@@ -4,7 +4,7 @@ using DataFrames
4
4
5
5
export sqlitedb, readdlmsql, query, createtable, droptable
6
6
7
- import Base: show
7
+ import Base: show, close
8
8
9
9
include (" SQLite_consts.jl" )
10
10
include (" SQLite_api.jl" )
@@ -15,7 +15,7 @@ type SQLiteDB
15
15
resultset:: Any
16
16
end
17
17
function show (io:: IO ,db:: SQLiteDB )
18
- if db == null_SQLiteDB
18
+ if db. handle == C_NULL
19
19
print (io," Null sqlite connection" )
20
20
else
21
21
println (io," sqlite connection" )
@@ -49,6 +49,16 @@ function connect(file::String)
49
49
return (sqlitedb = SQLiteDB (file,handle[1 ],null_resultset))
50
50
end
51
51
end
52
+ function close (conn:: SQLiteDB )
53
+ # if is fine to close when conn.handle is NULL (as stated in sqlite3's document)
54
+ if @FAILED sqlite3_close (conn. handle)
55
+ error (" [sqlite]: Error closing $(conn. file) ; $(bytestring (sqlite3_errmsg (conn. handle))) " )
56
+ else
57
+ conn. file = " "
58
+ conn. handle = C_NULL
59
+ conn. resultset = null_resultset
60
+ end
61
+ end
52
62
function internal_query (conn:: SQLiteDB ,q:: String ,finalize:: Bool = true ,stepped:: Bool = true )
53
63
stmt = Array (Ptr{Void},1 )
54
64
if @FAILED sqlite3_prepare_v2 (conn. handle,utf8 (q),stmt,[C_NULL ])
0 commit comments