Skip to content

Commit b108e5d

Browse files
committed
Use finalizer() on SQLStmts again but us gc() before closing dbs.
1 parent 218fc7e commit b108e5d

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/SQLite.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ end
6060

6161
function Base.close{T}(db::SQLiteDB{T})
6262
db.handle == C_NULL && return
63+
# ensure SQLiteStmts are finalised
64+
gc()
6365
@CHECK db sqlite3_close(db.handle)
6466
db.handle = C_NULL
6567
return
@@ -80,6 +82,7 @@ function SQLiteStmt{T}(db::SQLiteDB{T},sql::String)
8082
handle = [C_NULL]
8183
sqliteprepare(db,sql,handle,[C_NULL])
8284
stmt = SQLiteStmt(db,handle[1],convert(T,sql))
85+
finalizer(stmt, close)
8386
return stmt
8487
end
8588

@@ -128,7 +131,6 @@ end
128131
function execute(db::SQLiteDB,sql::String)
129132
stmt = SQLiteStmt(db,sql)
130133
execute(stmt)
131-
close(stmt)
132134
return changes(db)
133135
end
134136

@@ -139,7 +141,6 @@ function query(db::SQLiteDB,sql::String)
139141
status = execute(stmt)
140142
ncols = sqlite3_column_count(stmt.handle)
141143
if status == SQLITE_DONE || ncols == 0
142-
close(stmt)
143144
return changes(db)
144145
end
145146
colnames = Array(String,ncols)
@@ -171,7 +172,6 @@ function query(db::SQLiteDB,sql::String)
171172
end
172173
status = sqlite3_step(stmt.handle)
173174
end
174-
close(stmt)
175175
if status == SQLITE_DONE
176176
return ResultSet(colnames, results)
177177
else
@@ -274,7 +274,6 @@ function create(db::SQLiteDB,name::String,table,
274274
end
275275
execute(stmt)
276276
end
277-
close(stmt)
278277
end
279278
execute(db,"analyze $name")
280279
return changes(db)
@@ -303,7 +302,6 @@ function append(db::SQLiteDB,name::String,table)
303302
end
304303
execute(stmt)
305304
end
306-
close(stmt)
307305
end
308306
execute(db,"analyze $name")
309307
return return changes(db)

0 commit comments

Comments
 (0)