@@ -16,6 +16,11 @@ immutable NullType end
16
16
const NULL = NullType ()
17
17
Base. show (io:: IO ,:: NullType ) = print (io," NULL" )
18
18
19
+ # internal wrapper type to, in-effect, mark something which has been serialized
20
+ type Serialization
21
+ object
22
+ end
23
+
19
24
type ResultSet
20
25
colnames
21
26
values:: Vector{Any}
@@ -132,13 +137,18 @@ Base.bind(stmt::SQLiteStmt,i::Int,val::Int64) = @CHECK stmt.db sqlite3_
132
137
Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: NullType ) = @CHECK stmt. db sqlite3_bind_null (stmt. handle,i)
133
138
Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: AbstractString ) = @CHECK stmt. db sqlite3_bind_text (stmt. handle,i,val)
134
139
Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: UTF16String ) = @CHECK stmt. db sqlite3_bind_text16 (stmt. handle,i,val)
140
+ Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: Vector{UInt8} ) = @CHECK stmt. db sqlite3_bind_blob (stmt. handle,i,val)
135
141
# Fallback is BLOB and defaults to serializing the julia value
136
142
function sqlserialize (x)
137
143
t = IOBuffer ()
138
- serialize (t,x)
144
+ # deserialize will sometimes return a random object when called on an array
145
+ # which has not been previously serialized, we can use this type to check
146
+ # that the array has been serialized
147
+ s = Serialization (x)
148
+ serialize (t,s)
139
149
return takebuf_array (t)
140
150
end
141
- Base. bind (stmt:: SQLiteStmt ,i:: Int ,val) = @CHECK stmt . db sqlite3_bind_blob (stmt. handle ,i,sqlserialize (val))
151
+ Base. bind (stmt:: SQLiteStmt ,i:: Int ,val) = bind (stmt,i,sqlserialize (val))
142
152
# TODO :
143
153
# int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
144
154
# int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
@@ -159,7 +169,23 @@ function execute(db::SQLiteDB,sql::AbstractString)
159
169
return changes (db)
160
170
end
161
171
162
- sqldeserialize (r) = deserialize (IOBuffer (r))
172
+ function sqldeserialize (r)
173
+ # try blocks introduce new scope
174
+ local v
175
+ # deserialize will sometimes, but not consistently (see comment in
176
+ # sqlserialize), throw an error when called on an object which hasn't been
177
+ # previously serialized
178
+ try
179
+ v = deserialize (IOBuffer (r))
180
+ catch
181
+ return r
182
+ end
183
+ if isa (v, Serialization)
184
+ return v. object
185
+ else
186
+ return r
187
+ end
188
+ end
163
189
164
190
function query (db:: SQLiteDB ,sql:: AbstractString , values= [])
165
191
stmt = SQLiteStmt (db,sql)
0 commit comments