@@ -5,29 +5,29 @@ Given a MYSQL type get the corresponding julia type.
55"""
66function mysql_get_julia_type (mysqltype)
77 if (mysqltype == MYSQL_TYPE_BIT)
8- return Union{Missings . Missing, Cuchar}
8+ return Cuchar
99
1010 elseif (mysqltype == MYSQL_TYPE_TINY ||
1111 mysqltype == MYSQL_TYPE_ENUM)
12- return Union{Missings . Missing, Cchar}
12+ return Cchar
1313
1414 elseif (mysqltype == MYSQL_TYPE_SHORT)
15- return Union{Missings . Missing, Cshort}
15+ return Cshort
1616
1717 elseif (mysqltype == MYSQL_TYPE_LONG ||
1818 mysqltype == MYSQL_TYPE_INT24)
19- return Union{Missings . Missing, Cint}
19+ return Cint
2020
2121 elseif (mysqltype == MYSQL_TYPE_LONGLONG)
22- return Union{Missings . Missing, Int64}
22+ return Int64
2323
2424 elseif (mysqltype == MYSQL_TYPE_FLOAT)
25- return Union{Missings . Missing, Cfloat}
25+ return Cfloat
2626
2727 elseif (mysqltype == MYSQL_TYPE_DECIMAL ||
2828 mysqltype == MYSQL_TYPE_NEWDECIMAL ||
2929 mysqltype == MYSQL_TYPE_DOUBLE)
30- return Union{Missings . Missing, Cdouble}
30+ return Cdouble
3131
3232 elseif (mysqltype == MYSQL_TYPE_NULL ||
3333 mysqltype == MYSQL_TYPE_SET ||
@@ -36,30 +36,30 @@ function mysql_get_julia_type(mysqltype)
3636 mysqltype == MYSQL_TYPE_LONG_BLOB ||
3737 mysqltype == MYSQL_TYPE_BLOB ||
3838 mysqltype == MYSQL_TYPE_GEOMETRY)
39- return Union{Missings . Missing, String}
39+ return String
4040
4141 elseif (mysqltype == MYSQL_TYPE_YEAR)
42- return Union{Missings . Missing, Clong}
42+ return Clong
4343
4444 elseif (mysqltype == MYSQL_TYPE_TIMESTAMP)
45- return Union{Missings . Missing, DateTime}
45+ return DateTime
4646
4747 elseif (mysqltype == MYSQL_TYPE_DATE)
48- return Union{Missings . Missing, Date}
48+ return Date
4949
5050 elseif (mysqltype == MYSQL_TYPE_TIME)
51- return Union{Missings . Missing, DateTime}
51+ return DateTime
5252
5353 elseif (mysqltype == MYSQL_TYPE_DATETIME)
54- return Union{Missings . Missing, DateTime}
54+ return DateTime
5555
5656 elseif (mysqltype == MYSQL_TYPE_VARCHAR ||
5757 mysqltype == MYSQL_TYPE_VAR_STRING ||
5858 mysqltype == MYSQL_TYPE_STRING)
59- return Union{Missings . Missing, String}
59+ return String
6060
6161 else
62- return Union{Missings . Missing, String}
62+ return String
6363
6464 end
6565end
@@ -71,7 +71,7 @@ function mysql_get_ctype end
7171mysql_get_ctype (:: Type{<:Dates.TimeType} ) = MYSQL_TIME
7272mysql_get_ctype (x) = x
7373
74- mysql_get_ctype {T} (jltype:: Type{Union{Missings. Missing, T}} ) = mysql_get_ctype (T)
74+ mysql_get_ctype (jltype:: Type{Union{Missing, T}} ) where {T} = mysql_get_ctype (T)
7575
7676mysql_get_ctype (mysqltype:: MYSQL_TYPE ) =
7777 mysql_get_ctype (mysql_get_julia_type (mysqltype))
@@ -81,7 +81,7 @@ Interpret a string as a julia datatype.
8181"""
8282function mysql_interpret_field end
8383
84- mysql_interpret_field {T} (strval:: String , :: Type{Union{Missings. Missing, T}} ) = mysql_interpret_field (strval, T)
84+ mysql_interpret_field (strval:: String , :: Type{Union{Missing, T}} ) where {T} = mysql_interpret_field (strval, T)
8585
8686mysql_interpret_field (strval:: String , :: Type{Cuchar} ) = UInt8 (strval[1 ])
8787
@@ -91,11 +91,8 @@ mysql_interpret_field(strval::String, ::Type{T}) where {T<:Number} =
9191mysql_interpret_field (strval:: String , :: Type{<:AbstractString} ) =
9292 strval
9393
94- mysql_interpret_field (strval:: String , :: Type{Date} ) =
95- Dates. Date (datestr, MYSQL_DATE_FORMAT)
96-
97- functionmysql_interpret_field (strval:: String , :: Type{DateTime} ) =
98- Dates. DateTime (contains (strval, " " ) ? strval : " 1970-01-01 " * strval, MYSQL_DATETIME_FORMAT)
94+ mysql_interpret_field (strval:: String , :: Type{Date} ) = mysql_date (strval)
95+ mysql_interpret_field (strval:: String , :: Type{DateTime} ) = mysql_datetime (strval)
9996
10097"""
10198Load a bytestring from `result` pointer given the field index `idx`.
160157"""
161158Convert a mysql field type array to a julia type array.
162159"""
163- function mysql_get_jtype_array (mysqlfield_types)
164- nfields = length (mysqlfield_types)
165- jtypes = Array {Type} (nfields)
166- for i = 1 : nfields
167- jtypes[i] = mysql_get_julia_type (mysqlfield_types[i])
168- end
169- return jtypes
170- end
160+ mysql_get_jtype_array (mysqlfield_types) = map (x-> mysql_get_julia_type (x), mysqlfield_types)
171161
172162"""
173163Returns true if `field` is nullable (i.e, it is not declared as `NOT NULL`)
@@ -178,40 +168,21 @@ mysql_is_nullable(field) = field.flags & NOT_NULL_FLAG == 0
178168Get an array of boolean values indicating whether the column is
179169 declared as `NULL`(true) or `NOT NULL`(false).
180170"""
181- mysql_get_nullable (result) = mysql_get_nullable (mysql_metadata (result))
182-
183- function mysql_get_nullable (meta:: Array{MYSQL_FIELD} )
184- isnullable = Array {Bool} (length (meta))
185- for i = 1 : length (meta)
186- isnullable[i] = mysql_is_nullable (meta[i])
187- end
188- return isnullable
189- end
171+ mysql_get_nullable (result) = map (x-> mysql_is_nullable (x), mysql_metadata (result))
190172
191173"""
192174Get the result as an array with each row as a vector.
193175"""
194176function mysql_get_result_as_array (result)
195177 nrows = mysql_num_rows (result)
196178 meta = mysql_metadata (result)
197- retarr = Array {Array{Any}} (nrows)
198- for i = 1 : nrows
199- retarr[i] = Array {Any} (meta. nfields)
200- mysql_get_row_as_vector! (mysql_fetch_row (result), retarr[i],
201- meta. jtypes, meta. is_nullables)
202- end
203- return retarr
179+ return [mysql_get_row_as_vector (mysql_fetch_row (result), meta. jtypes, meta. is_nullables) for i = 1 : nrows]
204180end
205181
206182function mysql_get_result_as_tuples (result:: MySQLResult )
207183 nrows = mysql_num_rows (result)
208184 meta = mysql_metadata (result)
209- retarr = Array {Tuple} (nrows)
210- for i = 1 : nrows
211- retarr[i] = mysql_get_row_as_tuple (mysql_fetch_row (result), meta. jtypes,
212- meta. is_nullables)
213- end
214- return retarr
185+ return [mysql_get_row_as_tuple (mysql_fetch_row (result), meta. jtypes, meta. is_nullables) for i = 1 : nrows]
215186end
216187
217188"""
@@ -275,18 +246,18 @@ function stmt_populate_row!(df, row_index, bindarr)
275246 for i = 1 : length (bindarr)
276247 if bindarr[i]. is_null_value != 0
277248 df[row_index, i] = missing
278- continue
279- end
280- df[row_index, i] = mysql_binary_interpret_field (bindarr[i]. buffer,
249+ else
250+ df[row_index, i] = mysql_binary_interpret_field (bindarr[i]. buffer,
281251 convert (MYSQL_TYPE, bindarr[i]. buffer_type))
252+ end
282253 end
283254end
284255
285256"""
286257Get a bind array for binding to results.
287258"""
288259function mysql_bind_array (meta:: MySQLMetadata )
289- bindarr = Array {MYSQL_BIND} (meta. nfields)
260+ bindarr = Vector {MYSQL_BIND} (uninitialized, meta. nfields)
290261 for i in 1 : meta. nfields
291262 bufflen = zero (Culong)
292263 bindbuff = C_NULL
@@ -360,7 +331,7 @@ function mysql_get_row_as_tuple(bindarr::Vector{MYSQL_BIND}, jtypes, isnullable)
360331 vec = Array {Any} (length (bindarr))
361332 for i = 1 : length (bindarr)
362333 if bindarr[i]. is_null_value != 0
363- vec[i] = Missings . missing
334+ vec[i] = missing
364335 else
365336 val = mysql_binary_interpret_field (bindarr[i]. buffer,
366337 convert (MYSQL_TYPE, bindarr[i]. buffer_type))
0 commit comments