|
1 | 1 | module MySQL
|
2 | 2 |
|
3 |
| -using DataStreams, Missings, Dates |
4 |
| - |
5 |
| -export Data |
| 3 | +using Dates, Tables |
6 | 4 |
|
7 | 5 | abstract type MySQLError end
|
8 | 6 | # For errors that happen in MySQL.jl
|
|
67 | 65 | Escapes a string using `mysql_real_escape_string()`, returns the escaped string.
|
68 | 66 | """
|
69 | 67 | function escape(conn::MySQL.Connection, str::String)
|
70 |
| - output = Vector{UInt8}(undef, length(str) * 2 + 1) |
71 |
| - output_len = API.mysql_real_escape_string(conn.ptr, output, str, Culong(length(str))) |
| 68 | + output = Vector{UInt8}(undef, sizeof(str) * 2 + 1) |
| 69 | + output_len = API.mysql_real_escape_string(conn.ptr, output, str, Culong(sizeof(str))) |
72 | 70 | if output_len == typemax(Cuint)
|
73 | 71 | throw(MySQLInternalError(conn))
|
74 | 72 | end
|
@@ -105,20 +103,41 @@ See list of DataStreams implementations [here](https://github.com/JuliaData/Data
|
105 | 103 | """
|
106 | 104 | function query end
|
107 | 105 |
|
108 |
| -function query(conn::Connection, sql::String, sink::Type=Data.Table, args...; append::Bool=false, kwargs...) |
109 |
| - source = Query(conn, sql; kwargs...) |
110 |
| - sink = Data.stream!(source, sink, args...; append=append) |
111 |
| - return Data.close!(sink) |
| 106 | +function query(conn::Connection, sql::String, sink::Union{Type, Nothing}=nothing, args...; append::Bool=false, kwargs...) |
| 107 | + if sink === nothing |
| 108 | + Base.depwarn("`MySQL.query(conn, sql)` will return a MySQL.Query in the future; to materialize the result, use `MySQL.query(conn, sql) |> columntable` or `MySQL.query(conn, sql) |> DataFrame` instead", nothing) |
| 109 | + sink = columntable |
| 110 | + else |
| 111 | + Base.depwarn("`MySQL.query(conn, sql, $sink)` is deprecated; use `MySQL.query(conn, sql) |> $sink(args...)` instead", nothing) |
| 112 | + end |
| 113 | + if append |
| 114 | + Base.depwarn("`append=true` is deprecated; use sink-specific append features instead. For example, `columntable(existing, MySQL.query(conn, sql))` or `append!(existing_df, MySQL.query(conn, sql))`") |
| 115 | + end |
| 116 | + return Query(conn, sql; kwargs...) |> sink |
112 | 117 | end
|
113 | 118 |
|
114 | 119 | function query(conn::Connection, sql::String, sink::T; append::Bool=false, kwargs...) where {T}
|
115 |
| - source = Query(conn, sql; kwargs...) |
116 |
| - sink = Data.stream!(source, sink; append=append) |
117 |
| - return Data.close!(sink) |
| 120 | + Base.depwarn("`MySQL.query(conn, sql, ::$T)` is deprecated; `MySQL.Query` now supports the Tables.jl interface, so any valid Tables.jl sink can receive a resultset", nothing) |
| 121 | + if append |
| 122 | + Base.depwarn("`append=true` is deprecated; use sink-specific append features instead. For example, `columntable(existing, MySQL.query(conn, sql))` or `append!(existing_df, MySQL.query(conn, sql))`") |
| 123 | + end |
| 124 | + return Query(conn, sql; kwargs...) |> T |
118 | 125 | end
|
119 | 126 |
|
120 |
| -query(source::Query, sink=Data.Table, args...; append::Bool=false, transforms::Dict=Dict{Int,Function}()) = (sink = Data.stream!(source, sink, args...; append=append, transforms=transforms); return Data.close!(sink)) |
121 |
| -query(source::Query, sink::T; append::Bool=false, transforms::Dict=Dict{Int,Function}()) where {T} = (sink = Data.stream!(source, sink; append=append, transforms=transforms); return Data.close!(sink)) |
| 127 | +function query(source::Query, sink=columntable, args...; append::Bool=false) |
| 128 | + Base.depwarn("`MySQL.query(q::MySQL.Query)` is deprecated and will be removed in the future; `MySQL.Query` itself will iterate rows as NamedTuples and supports the Tables.jl interface", nothing) |
| 129 | + if append |
| 130 | + Base.depwarn("`append=true` is deprecated; use sink-specific append features instead. For example, `columntable(existing, MySQL.query(conn, sql))` or `append!(existing_df, MySQL.query(conn, sql))`") |
| 131 | + end |
| 132 | + return source |> sink |
| 133 | +end |
| 134 | +function query(source::Query, sink::T; append::Bool=false) where {T} |
| 135 | + Base.depwarn("`MySQL.query(q::MySQL.Query)` is deprecated and will be removed in the future; `MySQL.Query` itself will iterate rows as NamedTuples and supports the Tables.jl interface", nothing) |
| 136 | + if append |
| 137 | + Base.depwarn("`append=true` is deprecated; use sink-specific append features instead. For example, `columntable(existing, MySQL.query(conn, sql))` or `append!(existing_df, MySQL.query(conn, sql))`") |
| 138 | + end |
| 139 | + return source |> T |
| 140 | +end |
122 | 141 |
|
123 | 142 | include("prepared.jl")
|
124 | 143 |
|
|
0 commit comments