@@ -19,10 +19,10 @@ function Source(db::DB, sql::AbstractString, values=[]; rows::Int=0, stricttypes
19
19
bind! (stmt, values)
20
20
status = SQLite. execute! (stmt)
21
21
cols = SQLite. sqlite3_column_count (stmt. handle)
22
- header = Array (Compat . UTF8String ,cols)
22
+ header = Array (String ,cols)
23
23
types = Array (DataType,cols)
24
24
for i = 1 : cols
25
- header[i] = Compat . bytestring (SQLite. sqlite3_column_name (stmt. handle,i))
25
+ header[i] = unsafe_string (SQLite. sqlite3_column_name (stmt. handle,i))
26
26
# do better column type inference; query what the column was created for?
27
27
types[i] = stricttypes ? SQLite. juliatype (stmt. handle,i) : Any
28
28
end
@@ -41,23 +41,23 @@ function juliatype(handle,col)
41
41
return juliatype (x)
42
42
end
43
43
end
44
- juliatype (x) = x == SQLITE_INTEGER ? Int : x == SQLITE_FLOAT ? Float64 : x == SQLITE_TEXT ? Compat . UTF8String : Any
44
+ juliatype (x) = x == SQLITE_INTEGER ? Int : x == SQLITE_FLOAT ? Float64 : x == SQLITE_TEXT ? String : Any
45
45
46
46
sqlitevalue {T<:Union{Signed,Unsigned}} (:: Type{T} ,handle,col) = convert (T, sqlite3_column_int64 (handle,col))
47
47
const FLOAT_TYPES = Union{Float16,Float32,Float64} # exclude BigFloat
48
48
sqlitevalue {T<:FLOAT_TYPES} (:: Type{T} ,handle,col) = convert (T, sqlite3_column_double (handle,col))
49
- # TODO : test returning a PointerString instead of calling `bytestring`
50
- sqlitevalue {T<:AbstractString} (:: Type{T} ,handle,col) = convert (T,Compat . bytestring (sqlite3_column_text (handle,col)))
49
+ # TODO : test returning a WeakRefString instead of calling `bytestring`
50
+ sqlitevalue {T<:AbstractString} (:: Type{T} ,handle,col) = convert (T,unsafe_string (sqlite3_column_text (handle,col)))
51
51
function sqlitevalue {T} (:: Type{T} ,handle,col)
52
- blob = convert (Ptr{UInt8},SQLite . sqlite3_column_blob (handle,col))
53
- b = SQLite . sqlite3_column_bytes (handle,col)
52
+ blob = convert (Ptr{UInt8},sqlite3_column_blob (handle,col))
53
+ b = sqlite3_column_bytes (handle,col)
54
54
buf = zeros (UInt8,b) # global const?
55
55
unsafe_copy! (pointer (buf), blob, b)
56
- r = SQLite . sqldeserialize (buf):: T
56
+ r = sqldeserialize (buf):: T
57
57
return r
58
58
end
59
59
60
- # `T` might be Int, Float64, String, PointerString , any Julia type, Any, NullType
60
+ # `T` might be Int, Float64, String, WeakRefString , any Julia type, Any, NullType
61
61
# `t` (the actual type of the value we're returning), might be SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB, SQLITE_NULL
62
62
" `SQLite.getfield` returns the next `Nullable{T}` value from the `SQLite.Source`"
63
63
function getfield {T} (source:: SQLite.Source , :: Type{T} , row, col)
@@ -73,40 +73,39 @@ function getfield{T}(source::SQLite.Source, ::Type{T}, row, col)
73
73
return val
74
74
end
75
75
76
- function getfield! {T} (source:: SQLite.Source , dest:: NullableVector{T} , :: Type{T} , row, col)
76
+ function getfield! {T} (source:: SQLite.Source , dest:: NullableVector{T} , row, col)
77
77
@inbounds dest[row] = SQLite. getfield (source, T, row, col)
78
78
return
79
79
end
80
- function pushfield! {T} (source:: SQLite.Source , dest:: NullableVector{T} , :: Type{T} , row, col)
80
+ function pushfield! {T} (source:: SQLite.Source , dest:: NullableVector{T} , row, col)
81
81
push! (dest, SQLite. getfield (source, T, row, col))
82
82
return
83
83
end
84
- " streams data from the SQLite.Source to a Data.Table "
85
- function Data. stream! (source:: SQLite.Source ,sink:: Data.Table )
84
+ " streams data from the SQLite.Source to a DataFrame "
85
+ function Data. stream! (source:: SQLite.Source ,sink:: DataFrame )
86
86
rows, cols = size (source)
87
87
types = Data. types (source)
88
88
if rows == 0
89
89
row = 0
90
90
while ! Data. isdone (source)
91
91
for col = 1 : cols
92
92
@inbounds T = types[col]
93
- SQLite. pushfield! (source, Data . unsafe_column ( sink, col,T), T , row, col)
93
+ SQLite. pushfield! (source, sink. columns[ col] , row, col)
94
94
end
95
95
row += 1
96
96
end
97
97
source. schema. rows = row
98
98
else
99
99
for row = 1 : rows, col = 1 : cols
100
100
@inbounds T = types[col]
101
- SQLite. getfield! (source, Data . unsafe_column ( sink, col,T), T , row, col)
101
+ SQLite. getfield! (source, sink. columns[ col] , row, col)
102
102
end
103
103
end
104
- sink. schema = source. schema
105
104
return sink
106
105
end
107
- " creates a new Data.Table according to `source` schema and streams `Source` data into it"
108
- function Data. stream! (source:: SQLite.Source ,:: Type{Data.Table } )
109
- sink = Data . Table (source. schema)
106
+ " creates a new DataFrame according to `source` schema and streams `Source` data into it"
107
+ function Data. stream! (source:: SQLite.Source ,:: Type{DataFrame } )
108
+ sink = DataFrame (source. schema)
110
109
return Data. stream! (source,sink)
111
110
end
112
111
" streams data from an SQLite.Source to a CSV.Sink file; `header=false` will not write the column names to the file"
@@ -127,10 +126,10 @@ function Data.stream!(source::SQLite.Source,sink::CSV.Sink;header::Bool=true)
127
126
close (sink)
128
127
return sink
129
128
end
130
- " convenience method for executing an SQL statement and streaming the results back in a Data.Table "
129
+ " convenience method for executing an SQL statement and streaming the results back in a DataFrame "
131
130
function query (db:: DB ,sql:: AbstractString , values= [];rows:: Int = 0 ,stricttypes:: Bool = true )
132
131
so = Source (db,sql,values;rows= rows,stricttypes= stricttypes)
133
- return Data. stream! (so,Data . Table )
132
+ return Data. stream! (so,DataFrame )
134
133
end
135
134
136
135
" returns a list of tables in `db`"
0 commit comments