60
60
61
61
function Base. close {T} (db:: SQLiteDB{T} )
62
62
db. handle == C_NULL && return
63
- # Close all prepared statements with db
64
- stmt = C_NULL
65
- while true
66
- stmt = sqlite3_next_stmt (db. handle,stmt)
67
- stmt == C_NULL && break
68
- @CHECK db sqlite3_finalize (stmt)
69
- end
70
63
@CHECK db sqlite3_close (db. handle)
71
64
db. handle = C_NULL
72
65
return
@@ -87,7 +80,6 @@ function SQLiteStmt{T}(db::SQLiteDB{T},sql::String)
87
80
handle = [C_NULL ]
88
81
sqliteprepare (db,sql,handle,[C_NULL ])
89
82
stmt = SQLiteStmt (db,handle[1 ],convert (T,sql))
90
- finalizer (stmt, close)
91
83
return stmt
92
84
end
93
85
136
128
function execute (db:: SQLiteDB ,sql:: String )
137
129
stmt = SQLiteStmt (db,sql)
138
130
execute (stmt)
131
+ close (stmt)
139
132
return changes (db)
140
133
end
141
134
@@ -146,6 +139,7 @@ function query(db::SQLiteDB,sql::String)
146
139
status = execute (stmt)
147
140
ncols = sqlite3_column_count (stmt. handle)
148
141
if status == SQLITE_DONE || ncols == 0
142
+ close (stmt)
149
143
return changes (db)
150
144
end
151
145
colnames = Array (String,ncols)
@@ -177,6 +171,7 @@ function query(db::SQLiteDB,sql::String)
177
171
end
178
172
status = sqlite3_step (stmt. handle)
179
173
end
174
+ close (stmt)
180
175
if status == SQLITE_DONE
181
176
return ResultSet (colnames, results)
182
177
else
@@ -279,6 +274,7 @@ function create(db::SQLiteDB,name::String,table,
279
274
end
280
275
execute (stmt)
281
276
end
277
+ close (stmt)
282
278
end
283
279
execute (db," analyze $name " )
284
280
return changes (db)
@@ -307,6 +303,7 @@ function append(db::SQLiteDB,name::String,table)
307
303
end
308
304
execute (stmt)
309
305
end
306
+ close (stmt)
310
307
end
311
308
execute (db," analyze $name " )
312
309
return return changes (db)
0 commit comments