@@ -75,12 +75,12 @@ function mysql_next_result(hndl::MySQLHandle)
75
75
end
76
76
77
77
for func = (:mysql_field_count , :mysql_error , :mysql_insert_id )
78
- eval ( quote
78
+ @ eval begin
79
79
function ($ func)(hndl:: MySQLHandle , args... )
80
80
hndl. mysqlptr == C_NULL && throw (MySQLInterfaceError ($ (string (func)) * " called with NULL connection." ))
81
81
return ($ func)(hndl. mysqlptr, args... )
82
82
end
83
- end )
83
+ end
84
84
end
85
85
86
86
"""
@@ -93,14 +93,14 @@ mysql_insert_id
93
93
94
94
# wrappers to take MySQLHandle as input as well as check for NULL pointer.
95
95
for func = (:mysql_query , :mysql_options )
96
- eval ( quote
96
+ @ eval begin
97
97
function ($ func)(hndl:: MySQLHandle , args... )
98
98
hndl. mysqlptr == C_NULL && throw (MySQLInterfaceError ($ (string (func)) * " called with NULL connection." ))
99
99
val = ($ func)(hndl. mysqlptr, args... )
100
100
val != 0 && throw (MySQLInternalError (hndl))
101
101
return val
102
102
end
103
- end )
103
+ end
104
104
end
105
105
106
106
"""
@@ -166,7 +166,7 @@ function mysql_execute(hndl, command; opformat=MYSQL_DATA_FRAME)
166
166
else
167
167
throw (MySQLInterfaceError (" Query expected to produce results but did not." ))
168
168
end
169
-
169
+
170
170
status = mysql_next_result (hndl. mysqlptr)
171
171
if status > 0
172
172
throw (MySQLInternalError (hndl))
@@ -212,12 +212,12 @@ end
212
212
213
213
for func = (:mysql_stmt_num_rows , :mysql_stmt_affected_rows ,
214
214
:mysql_stmt_result_to_dataframe , :mysql_stmt_error )
215
- eval ( quote
215
+ @ eval begin
216
216
function ($ func)(hndl:: MySQLHandle , args... )
217
217
hndl. stmtptr == C_NULL && throw (MySQLInterfaceError ($ (string (func)) * " called with NULL statement handle." ))
218
218
return ($ func)(hndl. stmtptr, args... )
219
219
end
220
- end )
220
+ end
221
221
end
222
222
223
223
"""
@@ -254,23 +254,23 @@ function mysql_stmt_bind_result(hndl::MySQLHandle, bindarr::Vector{MYSQL_BIND})
254
254
end
255
255
256
256
for func = (:mysql_stmt_store_result , :mysql_stmt_bind_param )
257
- eval ( quote
257
+ @ eval begin
258
258
function ($ func)(hndl, args... )
259
259
hndl. stmtptr == C_NULL && throw (MySQLInterfaceError ($ (string (func)) * " called with NULL statement handle." ))
260
260
val = ($ func)(hndl. stmtptr, args... )
261
261
val != 0 && throw (MySQLStatementError (hndl))
262
262
return val
263
263
end
264
- end )
264
+ end
265
265
end
266
266
267
267
for func = (:mysql_num_rows , :mysql_fetch_row )
268
- eval ( quote
268
+ @ eval begin
269
269
function ($ func)(hndl, args... )
270
270
hndl. resptr == C_NULL && throw (MySQLInterfaceError ($ (string (func)) * " called with NULL result set." ))
271
271
return ($ func)(hndl. resptr, args... )
272
272
end
273
- end )
273
+ end
274
274
end
275
275
276
276
"""
@@ -279,8 +279,14 @@ Get a `MYSQL_BIND` instance given the mysql type `typ` and a `value`.
279
279
mysql_bind_init (typ:: MYSQL_TYPE , value) =
280
280
mysql_bind_init (mysql_get_julia_type (typ), typ, value)
281
281
282
- mysql_bind_init (jtype:: Union{Type{Date}, Type{DateTime}} , typ, value) =
283
- MYSQL_BIND ([convert (MYSQL_TIME, convert (jtype, value))], typ)
282
+ mysql_bind_init (jtype:: Type{Date} , typ, value:: Date ) =
283
+ MYSQL_BIND ([convert (MYSQL_TIME, value)], typ)
284
+ mysql_bind_init (jtype:: Type{Date} , typ, value:: String ) =
285
+ MYSQL_BIND ([convert (MYSQL_TIME, mysql_date (value))], typ)
286
+ mysql_bind_init (jtype:: Type{DateTime} , typ, value:: DateTime ) =
287
+ MYSQL_BIND ([convert (MYSQL_TIME, value)], typ)
288
+ mysql_bind_init (jtype:: Type{DateTime} , typ, value:: String ) =
289
+ MYSQL_BIND ([convert (MYSQL_TIME, mysql_datetime (value))], typ)
284
290
285
291
mysql_bind_init (:: Type{String} , typ, value) = MYSQL_BIND (value, typ)
286
292
mysql_bind_init (jtype, typ, value) = MYSQL_BIND ([convert (jtype, value)], typ)
@@ -295,13 +301,13 @@ Returns an array of `MYSQL_BIND`.
295
301
function mysql_bind_array (typs, params)
296
302
length (typs) != length (params) && throw (MySQLInterfaceError (" Length of `typs` and `params` must be same." ))
297
303
bindarr = MYSQL_BIND[]
298
- for (typ, val) in zip (typs, params)
299
- # Is the value one of three different versions of Null ?
300
- if ( isdefined ( :DataArrays ) && ( typeof ( val)== DataArrays . NAtype)) || ( isdefined ( :NullableArrays ) && ( typeof ( val) <: Nullable ) && (val . isnull)) || (val == nothing )
304
+ for (typ, val) in zip (typs, params)
305
+ # Is the value missing or equal to `nothing` ?
306
+ if ismissing ( val) || val === nothing
301
307
push! (bindarr, mysql_bind_init (MYSQL_TYPE_NULL, " NULL" ))
302
308
else
303
309
push! (bindarr, mysql_bind_init (typ, val)) # Otherwise
304
- end
310
+ end
305
311
end
306
312
return bindarr
307
313
end
@@ -332,14 +338,22 @@ end
332
338
Escapes a string using `mysql_real_escape_string()`, returns the escaped string.
333
339
"""
334
340
function mysql_escape (hndl:: MySQLHandle , str:: String )
335
- output = Vector {UInt8} (length (str)* 2 + 1 )
336
- output_len = mysql_real_escape_string (hndl. mysqlptr, output, str, UInt64 (length (str)))
341
+ output = Vector {UInt8} (uninitialized, length (str) * 2 + 1 )
342
+ output_len = mysql_real_escape_string (hndl. mysqlptr, output, str, Culong (length (str)))
337
343
if output_len == typemax (Cuint)
338
344
throw (MySQLInternalError (hndl))
339
345
end
340
346
return String (output[1 : output_len])
341
347
end
342
348
349
+ """
350
+ mysql_subtype(typ::DataType) -> DataType
351
+
352
+ Convenience function for working with missing values. If `typ` is of the form `Union{Missing, T}` it returns `T`, otherwise it returns `typ`. Not exported.
353
+ """
354
+ mysql_subtype {T} (typ:: Type{Union{Missing, T}} )= T
355
+ mysql_subtype (typ:: DataType )= typ
356
+
343
357
export mysql_options, mysql_connect, mysql_disconnect, mysql_execute,
344
358
mysql_insert_id, mysql_store_result, mysql_metadata, mysql_query,
345
359
mysql_stmt_prepare, mysql_escape
0 commit comments