@@ -75,12 +75,12 @@ function mysql_next_result(hndl::MySQLHandle)
7575end
7676
7777for func = (:mysql_field_count , :mysql_error , :mysql_insert_id )
78- eval ( quote
78+ @ eval begin
7979 function ($ func)(hndl:: MySQLHandle , args... )
8080 hndl. mysqlptr == C_NULL && throw (MySQLInterfaceError ($ (string (func)) * " called with NULL connection." ))
8181 return ($ func)(hndl. mysqlptr, args... )
8282 end
83- end )
83+ end
8484end
8585
8686"""
@@ -93,14 +93,14 @@ mysql_insert_id
9393
9494# wrappers to take MySQLHandle as input as well as check for NULL pointer.
9595for func = (:mysql_query , :mysql_options )
96- eval ( quote
96+ @ eval begin
9797 function ($ func)(hndl:: MySQLHandle , args... )
9898 hndl. mysqlptr == C_NULL && throw (MySQLInterfaceError ($ (string (func)) * " called with NULL connection." ))
9999 val = ($ func)(hndl. mysqlptr, args... )
100100 val != 0 && throw (MySQLInternalError (hndl))
101101 return val
102102 end
103- end )
103+ end
104104end
105105
106106"""
@@ -166,7 +166,7 @@ function mysql_execute(hndl, command; opformat=MYSQL_DATA_FRAME)
166166 else
167167 throw (MySQLInterfaceError (" Query expected to produce results but did not." ))
168168 end
169-
169+
170170 status = mysql_next_result (hndl. mysqlptr)
171171 if status > 0
172172 throw (MySQLInternalError (hndl))
@@ -212,12 +212,12 @@ end
212212
213213for func = (:mysql_stmt_num_rows , :mysql_stmt_affected_rows ,
214214 :mysql_stmt_result_to_dataframe , :mysql_stmt_error )
215- eval ( quote
215+ @ eval begin
216216 function ($ func)(hndl:: MySQLHandle , args... )
217217 hndl. stmtptr == C_NULL && throw (MySQLInterfaceError ($ (string (func)) * " called with NULL statement handle." ))
218218 return ($ func)(hndl. stmtptr, args... )
219219 end
220- end )
220+ end
221221end
222222
223223"""
@@ -254,23 +254,23 @@ function mysql_stmt_bind_result(hndl::MySQLHandle, bindarr::Vector{MYSQL_BIND})
254254end
255255
256256for func = (:mysql_stmt_store_result , :mysql_stmt_bind_param )
257- eval ( quote
257+ @ eval begin
258258 function ($ func)(hndl, args... )
259259 hndl. stmtptr == C_NULL && throw (MySQLInterfaceError ($ (string (func)) * " called with NULL statement handle." ))
260260 val = ($ func)(hndl. stmtptr, args... )
261261 val != 0 && throw (MySQLStatementError (hndl))
262262 return val
263263 end
264- end )
264+ end
265265end
266266
267267for func = (:mysql_num_rows , :mysql_fetch_row )
268- eval ( quote
268+ @ eval begin
269269 function ($ func)(hndl, args... )
270270 hndl. resptr == C_NULL && throw (MySQLInterfaceError ($ (string (func)) * " called with NULL result set." ))
271271 return ($ func)(hndl. resptr, args... )
272272 end
273- end )
273+ end
274274end
275275
276276"""
@@ -279,8 +279,14 @@ Get a `MYSQL_BIND` instance given the mysql type `typ` and a `value`.
279279mysql_bind_init (typ:: MYSQL_TYPE , value) =
280280 mysql_bind_init (mysql_get_julia_type (typ), typ, value)
281281
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)
284290
285291mysql_bind_init (:: Type{String} , typ, value) = MYSQL_BIND (value, typ)
286292mysql_bind_init (jtype, typ, value) = MYSQL_BIND ([convert (jtype, value)], typ)
@@ -295,13 +301,13 @@ Returns an array of `MYSQL_BIND`.
295301function mysql_bind_array (typs, params)
296302 length (typs) != length (params) && throw (MySQLInterfaceError (" Length of `typs` and `params` must be same." ))
297303 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
301307 push! (bindarr, mysql_bind_init (MYSQL_TYPE_NULL, " NULL" ))
302308 else
303309 push! (bindarr, mysql_bind_init (typ, val)) # Otherwise
304- end
310+ end
305311 end
306312 return bindarr
307313end
@@ -332,14 +338,22 @@ end
332338Escapes a string using `mysql_real_escape_string()`, returns the escaped string.
333339"""
334340function 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)))
337343 if output_len == typemax (Cuint)
338344 throw (MySQLInternalError (hndl))
339345 end
340346 return String (output[1 : output_len])
341347end
342348
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+
343357export mysql_options, mysql_connect, mysql_disconnect, mysql_execute,
344358 mysql_insert_id, mysql_store_result, mysql_metadata, mysql_query,
345359 mysql_stmt_prepare, mysql_escape
0 commit comments