@@ -4,7 +4,7 @@ export NULL, SQLiteDB, SQLiteStmt, ResultSet,
4
4
execute, query, tables, drop, create, append
5
5
6
6
type SQLiteException <: Exception
7
- msg:: String
7
+ msg:: AbstractString
8
8
end
9
9
10
10
include (" consts.jl" )
23
23
== (a:: ResultSet ,b:: ResultSet ) = a. colnames == b. colnames && a. values == b. values
24
24
include (" show.jl" )
25
25
26
- type SQLiteDB{T<: String }
26
+ type SQLiteDB{T<: AbstractString }
27
27
file:: T
28
28
handle:: Ptr{Void}
29
29
changes:: Int
30
30
end
31
31
SQLiteDB (file,handle) = SQLiteDB (file,handle,0 )
32
32
33
33
include (" UDF.jl" )
34
- export registerfunc, sqlreturn, @scalarfunc , @sr_str
34
+ export @sr_str , @register , register
35
35
36
36
37
37
function changes (db:: SQLiteDB )
@@ -48,13 +48,13 @@ sqliteopen(file::UTF16String,handle) = sqlite3_open16(file,handle)
48
48
sqliteerror () = throw (SQLiteException (bytestring (sqlite3_errmsg ())))
49
49
sqliteerror (db) = throw (SQLiteException (bytestring (sqlite3_errmsg (db. handle))))
50
50
51
- function SQLiteDB (file:: String = " " ;UTF16:: Bool = false )
51
+ function SQLiteDB (file:: AbstractString = " " ;UTF16:: Bool = false )
52
52
handle = [C_NULL ]
53
53
utf = UTF16 ? utf16 : utf8
54
54
file = isempty (file) ? file : expanduser (file)
55
55
if @OK sqliteopen (utf (file),handle)
56
56
db = SQLiteDB (utf (file),handle[1 ])
57
- registerfunc (db, 2 , regexp )
57
+ register (db, regexp, nargs = 2 )
58
58
finalizer (db,close)
59
59
return db
60
60
else # error
@@ -83,7 +83,7 @@ sqliteprepare(db,sql,stmt,null) =
83
83
sqliteprepare (db:: SQLiteDB{UTF16String} ,sql,stmt,null) =
84
84
@CHECK db sqlite3_prepare16_v2 (db. handle,utf16 (sql),stmt,null)
85
85
86
- function SQLiteStmt {T} (db:: SQLiteDB{T} ,sql:: String )
86
+ function SQLiteStmt {T} (db:: SQLiteDB{T} ,sql:: AbstractString )
87
87
handle = [C_NULL ]
88
88
sqliteprepare (db,sql,handle,[C_NULL ])
89
89
stmt = SQLiteStmt (db,handle[1 ],convert (T,sql))
@@ -112,26 +112,26 @@ function Base.bind{V}(stmt::SQLiteStmt, values::Dict{Symbol, V})
112
112
@assert nparams == length (values) " you must provide values for all placeholders"
113
113
for i in 1 : nparams
114
114
name = bytestring (sqlite3_bind_parameter_name (stmt. handle, i))
115
- @assert ! isempty (name) " nameless parameters should be passed as a tuple "
115
+ @assert ! isempty (name) " nameless parameters should be passed as a Vector "
116
116
# name is returned with the ':', '@' or '$' at the start
117
117
name = name[2 : end ]
118
118
bind (stmt, i, values[symbol (name)])
119
119
end
120
120
end
121
121
# Binding parameters to SQL statements
122
- function Base. bind (stmt:: SQLiteStmt ,name:: String ,val)
122
+ function Base. bind (stmt:: SQLiteStmt ,name:: AbstractString ,val)
123
123
i = sqlite3_bind_parameter_index (stmt. handle,name)
124
124
if i == 0
125
125
throw (SQLiteException (" SQL parameter $name not found in $stmt " ))
126
126
end
127
127
return bind (stmt,i,val)
128
128
end
129
- Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: FloatingPoint ) = @CHECK stmt. db sqlite3_bind_double (stmt. handle,i,float64 (val))
130
- Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: Int32 ) = @CHECK stmt. db sqlite3_bind_int (stmt. handle,i,val)
131
- Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: Int64 ) = @CHECK stmt. db sqlite3_bind_int64 (stmt. handle,i,val)
132
- Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: NullType ) = @CHECK stmt. db sqlite3_bind_null (stmt. handle,i)
133
- Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: String ) = @CHECK stmt. db sqlite3_bind_text (stmt. handle,i,val)
134
- Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: UTF16String ) = @CHECK stmt. db sqlite3_bind_text16 (stmt. handle,i,val)
129
+ Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: FloatingPoint ) = @CHECK stmt. db sqlite3_bind_double (stmt. handle,i,float64 (val))
130
+ Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: Int32 ) = @CHECK stmt. db sqlite3_bind_int (stmt. handle,i,val)
131
+ Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: Int64 ) = @CHECK stmt. db sqlite3_bind_int64 (stmt. handle,i,val)
132
+ Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: NullType ) = @CHECK stmt. db sqlite3_bind_null (stmt. handle,i)
133
+ Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: AbstractString ) = @CHECK stmt. db sqlite3_bind_text (stmt. handle,i,val)
134
+ Base. bind (stmt:: SQLiteStmt ,i:: Int ,val:: UTF16String ) = @CHECK stmt. db sqlite3_bind_text16 (stmt. handle,i,val)
135
135
# Fallback is BLOB and defaults to serializing the julia value
136
136
function sqlserialize (x)
137
137
t = IOBuffer ()
@@ -153,23 +153,23 @@ function execute(stmt::SQLiteStmt)
153
153
end
154
154
return r
155
155
end
156
- function execute (db:: SQLiteDB ,sql:: String )
156
+ function execute (db:: SQLiteDB ,sql:: AbstractString )
157
157
stmt = SQLiteStmt (db,sql)
158
158
execute (stmt)
159
159
return changes (db)
160
160
end
161
161
162
162
sqldeserialize (r) = deserialize (IOBuffer (r))
163
163
164
- function query (db:: SQLiteDB ,sql:: String , values= [])
164
+ function query (db:: SQLiteDB ,sql:: AbstractString , values= [])
165
165
stmt = SQLiteStmt (db,sql)
166
166
bind (stmt, values)
167
167
status = execute (stmt)
168
168
ncols = sqlite3_column_count (stmt. handle)
169
169
if status == SQLITE_DONE || ncols == 0
170
170
return changes (db)
171
171
end
172
- colnames = Array (String ,ncols)
172
+ colnames = Array (AbstractString ,ncols)
173
173
results = Array (Any,ncols)
174
174
for i = 1 : ncols
175
175
colnames[i] = bytestring (sqlite3_column_name (stmt. handle,i- 1 ))
@@ -220,7 +220,7 @@ function transaction(db, mode="DEFERRED")
220
220
221
221
If mode is one of "", "DEFERRED", "IMMEDIATE" or "EXCLUSIVE" then a
222
222
transaction of that (or the default) type is started. Otherwise a savepoint
223
- is created whose name is mode converted to String .
223
+ is created whose name is mode converted to AbstractString .
224
224
=#
225
225
if uppercase (mode) in [" " , " DEFERRED" , " IMMEDIATE" , " EXCLUSIVE" ]
226
226
execute (db, " BEGIN $(mode) TRANSACTION;" )
@@ -257,15 +257,15 @@ commit(db, name) = execute(db, "RELEASE SAVEPOINT $(name);")
257
257
rollback (db) = execute (db, " ROLLBACK TRANSACTION;" )
258
258
rollback (db, name) = execute (db, " ROLLBACK TRANSACTION TO SAVEPOINT $(name) ;" )
259
259
260
- function drop (db:: SQLiteDB ,table:: String )
260
+ function drop (db:: SQLiteDB ,table:: AbstractString )
261
261
transaction (db) do
262
262
execute (db," drop table $table " )
263
263
end
264
264
execute (db," vacuum" )
265
265
return changes (db)
266
266
end
267
267
268
- function dropindex (db:: SQLiteDB ,index:: String )
268
+ function dropindex (db:: SQLiteDB ,index:: AbstractString )
269
269
transaction (db) do
270
270
execute (db," drop index $index " )
271
271
end
@@ -274,12 +274,12 @@ end
274
274
275
275
gettype {T<:Integer} (:: Type{T} ) = " INT"
276
276
gettype {T<:Real} (:: Type{T} ) = " REAL"
277
- gettype {T<:String } (:: Type{T} ) = " TEXT"
277
+ gettype {T<:AbstractString } (:: Type{T} ) = " TEXT"
278
278
gettype (:: Type ) = " BLOB"
279
279
gettype (:: Type{NullType} ) = " NULL"
280
280
281
- function create (db:: SQLiteDB ,name:: String ,table,
282
- colnames= String [],coltypes= DataType[];temp:: Bool = false )
281
+ function create (db:: SQLiteDB ,name:: AbstractString ,table,
282
+ colnames= AbstractString [],coltypes= DataType[];temp:: Bool = false )
283
283
N, M = size (table)
284
284
colnames = isempty (colnames) ? [" x$i " for i= 1 : M] : colnames
285
285
coltypes = isempty (coltypes) ? [typeof (table[1 ,i]) for i= 1 : M] : coltypes
@@ -305,7 +305,7 @@ function create(db::SQLiteDB,name::String,table,
305
305
return changes (db)
306
306
end
307
307
308
- function createindex (db:: SQLiteDB ,table:: String ,index:: String ,cols;unique:: Bool = true )
308
+ function createindex (db:: SQLiteDB ,table:: AbstractString ,index:: AbstractString ,cols;unique:: Bool = true )
309
309
u = unique ? " unique" : " "
310
310
transaction (db) do
311
311
execute (db," create $u index $index on $table ($cols )" )
@@ -314,7 +314,7 @@ function createindex(db::SQLiteDB,table::String,index::String,cols;unique::Bool=
314
314
return changes (db)
315
315
end
316
316
317
- function append (db:: SQLiteDB ,name:: String ,table)
317
+ function append (db:: SQLiteDB ,name:: AbstractString ,table)
318
318
N, M = size (table)
319
319
transaction (db) do
320
320
# insert statements
@@ -333,7 +333,7 @@ function append(db::SQLiteDB,name::String,table)
333
333
return return changes (db)
334
334
end
335
335
336
- function deleteduplicates (db,table:: String ,cols:: String )
336
+ function deleteduplicates (db,table:: AbstractString ,cols:: AbstractString )
337
337
transaction (db) do
338
338
execute (db," delete from $table where rowid not in (select max(rowid) from $table group by $cols );" )
339
339
end
0 commit comments