@@ -5,11 +5,11 @@ Independently constructs an `SQLite.Source` in `db` with the SQL statement `sql`
5
5
Will bind `values` to any parameters in `sql`.
6
6
`rows` is used to indicate how many rows to return in the query result if known beforehand. `rows=0` (the default) will return all possible rows.
7
7
`stricttypes=false` will remove strict column typing in the result set, making each column effectively `Vector{Any}`. `nullable::Bool=true` indicates
8
- whether to allow null values when fetching results; if set to `false` and a null value is encountered, a `NullException` will be thrown.
8
+ whether to allow missing values when fetching results; if set to `false` and a missing value is encountered, a `NullException` will be thrown.
9
9
10
10
Note that no results are returned; `sql` is executed, and results are ready to be returned (i.e. streamed to an appropriate `Data.Sink` type)
11
11
"""
12
- function Source (db:: DB , sql:: AbstractString , values= []; rows:: Union{Int, Null} = null , stricttypes:: Bool = true , nullable:: Bool = true )
12
+ function Source (db:: DB , sql:: AbstractString , values= []; rows:: Union{Int, Missing} = missing , stricttypes:: Bool = true , nullable:: Bool = true )
13
13
stmt = SQLite. Stmt (db, sql)
14
14
bind! (stmt, values)
15
15
status = SQLite. execute! (stmt)
@@ -19,7 +19,7 @@ function Source(db::DB, sql::AbstractString, values=[]; rows::Union{Int, Null}=n
19
19
for i = 1 : cols
20
20
header[i] = unsafe_string (SQLite. sqlite3_column_name (stmt. handle, i))
21
21
if nullable
22
- types[i] = stricttypes ? Union{SQLite. juliatype (stmt. handle, i), Null } : Any
22
+ types[i] = stricttypes ? Union{SQLite. juliatype (stmt. handle, i), Missing } : Any
23
23
else
24
24
types[i] = stricttypes ? SQLite. juliatype (stmt. handle, i) : Any
25
25
end
75
75
Data. reset! (io:: SQLite.Source ) = (sqlite3_reset (io. stmt. handle); execute! (io. stmt))
76
76
Data. streamtype (:: Type{SQLite.Source} , :: Type{Data.Field} ) = true
77
77
78
- # `T` might be Int, Float64, String, WeakRefString, any Julia type, Any, Null
78
+ # `T` might be Int, Float64, String, WeakRefString, any Julia type, Any, Missing
79
79
# `t` (the actual type of the value we're returning), might be SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB, SQLITE_NULL
80
- # `SQLite.streamfrom` returns the next `Union{T, Null }` value from the `SQLite.Source`
81
- function Data. streamfrom (source:: SQLite.Source , :: Type{Data.Field} , :: Type{Union{T, Null }} , row, col) where {T}
80
+ # `SQLite.streamfrom` returns the next `Union{T, Missing }` value from the `SQLite.Source`
81
+ function Data. streamfrom (source:: SQLite.Source , :: Type{Data.Field} , :: Type{Union{T, Missing }} , row, col) where {T}
82
82
handle = source. stmt. handle
83
83
t = SQLite. sqlite3_column_type (handle, col)
84
84
if t == SQLite. SQLITE_NULL
85
- val = null
85
+ val = missing
86
86
else
87
87
TT = SQLite. juliatype (t) # native SQLite Int, Float, and Text types
88
88
val = SQLite. sqlitevalue (ifelse (TT === Any && ! isbits (T), T, TT), handle, col)
89
89
end
90
90
col == source. schema. cols && (source. status = sqlite3_step (handle))
91
- return val:: Union{T, Null }
91
+ return val:: Union{T, Missing }
92
92
end
93
93
function Data. streamfrom (source:: SQLite.Source , :: Type{Data.Field} , :: Type{T} , row, col) where {T}
94
94
handle = source. stmt. handle
95
95
t = SQLite. sqlite3_column_type (handle, col)
96
96
if t == SQLite. SQLITE_NULL
97
- throw (Data. NullException (" encountered null value in non-null typed column: row = $row , col = $col " ))
97
+ throw (Data. NullException (" encountered missing value in non-missing typed column: row = $row , col = $col " ))
98
98
else
99
99
TT = SQLite. juliatype (t) # native SQLite Int, Float, and Text types
100
100
val:: T = sqlitevalue (ifelse (TT === Any && ! isbits (T), T, TT), handle, col)
@@ -112,13 +112,13 @@ Will bind `values` to any parameters in `sql`.
112
112
`rows` is used to indicate how many rows to return in the query result if known beforehand. `rows=0` (the default) will return all possible rows.
113
113
`stricttypes=false` will remove strict column typing in the result set, making each column effectively `Vector{Any}`
114
114
"""
115
- function query (db:: DB , sql:: AbstractString , sink= DataFrame, args... ; append:: Bool = false , transforms:: Dict = Dict {Int,Function} (), values= [], rows:: Union{Int, Null} = null , stricttypes:: Bool = true , nullable:: Bool = true )
115
+ function query (db:: DB , sql:: AbstractString , sink= DataFrame, args... ; append:: Bool = false , transforms:: Dict = Dict {Int,Function} (), values= [], rows:: Union{Int, Missing} = missing , stricttypes:: Bool = true , nullable:: Bool = true )
116
116
source = Source (db, sql, values; rows= rows, stricttypes= stricttypes, nullable= nullable)
117
117
sink = Data. stream! (source, sink; append= append, transforms= transforms, args... )
118
118
return Data. close! (sink)
119
119
end
120
120
121
- function query (db:: DB , sql:: AbstractString , sink:: T ; append:: Bool = false , transforms:: Dict = Dict {Int,Function} (), values= [], rows:: Union{Int, Null} = null , stricttypes:: Bool = true , nullable:: Bool = true ) where {T}
121
+ function query (db:: DB , sql:: AbstractString , sink:: T ; append:: Bool = false , transforms:: Dict = Dict {Int,Function} (), values= [], rows:: Union{Int, Missing} = missing , stricttypes:: Bool = true , nullable:: Bool = true ) where {T}
122
122
source = Source (db, sql, values; rows= rows, stricttypes= stricttypes, nullable= nullable)
123
123
sink = Data. stream! (source, sink; append= append, transforms= transforms)
124
124
return Data. close! (sink)
0 commit comments