Skip to content

Commit 72430bb

Browse files
committed
Replace String with AbstractString.
1 parent cceae01 commit 72430bb

File tree

5 files changed

+50
-50
lines changed

5 files changed

+50
-50
lines changed

src/SQLite.jl

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export NULL, SQLiteDB, SQLiteStmt, ResultSet,
44
execute, query, tables, drop, create, append
55

66
type SQLiteException <: Exception
7-
msg::String
7+
msg::AbstractString
88
end
99

1010
include("consts.jl")
@@ -23,7 +23,7 @@ end
2323
==(a::ResultSet,b::ResultSet) = a.colnames == b.colnames && a.values == b.values
2424
include("show.jl")
2525

26-
type SQLiteDB{T<:String}
26+
type SQLiteDB{T<:AbstractString}
2727
file::T
2828
handle::Ptr{Void}
2929
changes::Int
@@ -48,7 +48,7 @@ sqliteopen(file::UTF16String,handle) = sqlite3_open16(file,handle)
4848
sqliteerror() = throw(SQLiteException(bytestring(sqlite3_errmsg())))
4949
sqliteerror(db) = throw(SQLiteException(bytestring(sqlite3_errmsg(db.handle))))
5050

51-
function SQLiteDB(file::String="";UTF16::Bool=false)
51+
function SQLiteDB(file::AbstractString="";UTF16::Bool=false)
5252
handle = [C_NULL]
5353
utf = UTF16 ? utf16 : utf8
5454
file = isempty(file) ? file : expanduser(file)
@@ -83,7 +83,7 @@ sqliteprepare(db,sql,stmt,null) =
8383
sqliteprepare(db::SQLiteDB{UTF16String},sql,stmt,null) =
8484
@CHECK db sqlite3_prepare16_v2(db.handle,utf16(sql),stmt,null)
8585

86-
function SQLiteStmt{T}(db::SQLiteDB{T},sql::String)
86+
function SQLiteStmt{T}(db::SQLiteDB{T},sql::AbstractString)
8787
handle = [C_NULL]
8888
sqliteprepare(db,sql,handle,[C_NULL])
8989
stmt = SQLiteStmt(db,handle[1],convert(T,sql))
@@ -119,19 +119,19 @@ function Base.bind{V}(stmt::SQLiteStmt, values::Dict{Symbol, V})
119119
end
120120
end
121121
# Binding parameters to SQL statements
122-
function Base.bind(stmt::SQLiteStmt,name::String,val)
122+
function Base.bind(stmt::SQLiteStmt,name::AbstractString,val)
123123
i = sqlite3_bind_parameter_index(stmt.handle,name)
124124
if i == 0
125125
throw(SQLiteException("SQL parameter $name not found in $stmt"))
126126
end
127127
return bind(stmt,i,val)
128128
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)
135135
# Fallback is BLOB and defaults to serializing the julia value
136136
function sqlserialize(x)
137137
t = IOBuffer()
@@ -153,23 +153,23 @@ function execute(stmt::SQLiteStmt)
153153
end
154154
return r
155155
end
156-
function execute(db::SQLiteDB,sql::String)
156+
function execute(db::SQLiteDB,sql::AbstractString)
157157
stmt = SQLiteStmt(db,sql)
158158
execute(stmt)
159159
return changes(db)
160160
end
161161

162162
sqldeserialize(r) = deserialize(IOBuffer(r))
163163

164-
function query(db::SQLiteDB,sql::String, values=[])
164+
function query(db::SQLiteDB,sql::AbstractString, values=[])
165165
stmt = SQLiteStmt(db,sql)
166166
bind(stmt, values)
167167
status = execute(stmt)
168168
ncols = sqlite3_column_count(stmt.handle)
169169
if status == SQLITE_DONE || ncols == 0
170170
return changes(db)
171171
end
172-
colnames = Array(String,ncols)
172+
colnames = Array(AbstractString,ncols)
173173
results = Array(Any,ncols)
174174
for i = 1:ncols
175175
colnames[i] = bytestring(sqlite3_column_name(stmt.handle,i-1))
@@ -220,7 +220,7 @@ function transaction(db, mode="DEFERRED")
220220
221221
If mode is one of "", "DEFERRED", "IMMEDIATE" or "EXCLUSIVE" then a
222222
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.
224224
=#
225225
if uppercase(mode) in ["", "DEFERRED", "IMMEDIATE", "EXCLUSIVE"]
226226
execute(db, "BEGIN $(mode) TRANSACTION;")
@@ -257,15 +257,15 @@ commit(db, name) = execute(db, "RELEASE SAVEPOINT $(name);")
257257
rollback(db) = execute(db, "ROLLBACK TRANSACTION;")
258258
rollback(db, name) = execute(db, "ROLLBACK TRANSACTION TO SAVEPOINT $(name);")
259259

260-
function drop(db::SQLiteDB,table::String)
260+
function drop(db::SQLiteDB,table::AbstractString)
261261
transaction(db) do
262262
execute(db,"drop table $table")
263263
end
264264
execute(db,"vacuum")
265265
return changes(db)
266266
end
267267

268-
function dropindex(db::SQLiteDB,index::String)
268+
function dropindex(db::SQLiteDB,index::AbstractString)
269269
transaction(db) do
270270
execute(db,"drop index $index")
271271
end
@@ -274,12 +274,12 @@ end
274274

275275
gettype{T<:Integer}(::Type{T}) = " INT"
276276
gettype{T<:Real}(::Type{T}) = " REAL"
277-
gettype{T<:String}(::Type{T}) = " TEXT"
277+
gettype{T<:AbstractString}(::Type{T}) = " TEXT"
278278
gettype(::Type) = " BLOB"
279279
gettype(::Type{NullType}) = " NULL"
280280

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)
283283
N, M = size(table)
284284
colnames = isempty(colnames) ? ["x$i" for i=1:M] : colnames
285285
coltypes = isempty(coltypes) ? [typeof(table[1,i]) for i=1:M] : coltypes
@@ -305,7 +305,7 @@ function create(db::SQLiteDB,name::String,table,
305305
return changes(db)
306306
end
307307

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)
309309
u = unique ? "unique" : ""
310310
transaction(db) do
311311
execute(db,"create $u index $index on $table ($cols)")
@@ -314,7 +314,7 @@ function createindex(db::SQLiteDB,table::String,index::String,cols;unique::Bool=
314314
return changes(db)
315315
end
316316

317-
function append(db::SQLiteDB,name::String,table)
317+
function append(db::SQLiteDB,name::AbstractString,table)
318318
N, M = size(table)
319319
transaction(db) do
320320
# insert statements
@@ -333,7 +333,7 @@ function append(db::SQLiteDB,name::String,table)
333333
return return changes(db)
334334
end
335335

336-
function deleteduplicates(db,table::String,cols::String)
336+
function deleteduplicates(db,table::AbstractString,cols::AbstractString)
337337
transaction(db) do
338338
execute(db,"delete from $table where rowid not in (select max(rowid) from $table group by $cols);")
339339
end

src/UDF.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function registerfunc(db::SQLiteDB, nargs::Integer, func::Function, isdeterm::Bo
44
# assume any negative number means a varargs function
55
nargs < -1 && (nargs = -1)
66

7-
name = isempty(name) ? string(func) : name::String
7+
name = isempty(name) ? string(func) : name::AbstractString
88
@assert sizeof(name) <= 255 "size of function name must be <= 255"
99

1010
cfunc = cfunction(func, Nothing, (Ptr{Void}, Cint, Ptr{Ptr{Void}}))
@@ -24,7 +24,7 @@ function registerfunc(db::SQLiteDB, nargs::Integer, step::Function, final::Funct
2424
# assume any negative number means a varargs function
2525
nargs < -1 && (nargs = -1)
2626

27-
name = isempty(name) ? string(step) : name::String
27+
name = isempty(name) ? string(step) : name::AbstractString
2828
cstep = cfunction(step, Nothing, (Ptr{Void}, Cint, Ptr{Ptr{Void}}))
2929
cfinal = cfunction(final, Nothing, (Ptr{Void}, Cint, Ptr{Ptr{Void}}))
3030

@@ -63,17 +63,17 @@ function sqlvalue(values, i)
6363
end
6464
end
6565

66-
sqlreturn(context, ::NullType) = sqlite3_result_null(context)
67-
sqlreturn(context, val::Int32) = sqlite3_result_int(context, val)
68-
sqlreturn(context, val::Int64) = sqlite3_result_int64(context, val)
69-
sqlreturn(context, val::Float64) = sqlite3_result_double(context, val)
70-
sqlreturn(context, val::String) = sqlite3_result_text(context, val)
71-
sqlreturn(context, val::UTF16String) = sqlite3_result_text16(context, val)
72-
sqlreturn(context, val) = sqlite3_result_blob(context, sqlserialize(val))
66+
sqlreturn(context, ::NullType) = sqlite3_result_null(context)
67+
sqlreturn(context, val::Int32) = sqlite3_result_int(context, val)
68+
sqlreturn(context, val::Int64) = sqlite3_result_int64(context, val)
69+
sqlreturn(context, val::Float64) = sqlite3_result_double(context, val)
70+
sqlreturn(context, val::UTF16String) = sqlite3_result_text16(context, val)
71+
sqlreturn(context, val::AbstractString) = sqlite3_result_text(context, val)
72+
sqlreturn(context, val) = sqlite3_result_blob(context, sqlserialize(val))
7373

7474
sqlreturn(context, val::Bool) = sqlreturn(context, int(val))
7575

76-
sqludferror(context, msg::String) = sqlite3_result_error(context, msg)
76+
sqludferror(context, msg::AbstractString) = sqlite3_result_error(context, msg)
7777
sqludferror(context, msg::UTF16String) = sqlite3_result_error16(context, msg)
7878

7979
function funcname(expr)
@@ -100,6 +100,6 @@ macro scalarfunc(args...)
100100
end
101101

102102
# annotate types because the MethodError makes more sense that way
103-
@scalarfunc regexp(r::String, s::String) = ismatch(Regex(r), s)
103+
@scalarfunc regexp(r::AbstractString, s::AbstractString) = ismatch(Regex(r), s)
104104
# macro for preserving the special characters in a string
105105
macro sr_str(s) s end

src/api.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function sqlite3_errmsg(db::Ptr{Void})
99
Ptr{Uint8}, (Ptr{Void},),
1010
db)
1111
end
12-
function sqlite3_open(file::String,handle::Array{Ptr{Void},1})
12+
function sqlite3_open(file::AbstractString,handle::Array{Ptr{Void},1})
1313
return ccall( (:sqlite3_open, sqlite3_lib),
1414
Cint, (Ptr{Uint8},Ptr{Void}),
1515
file,handle)
@@ -31,13 +31,13 @@ function sqlite3_next_stmt(db::Ptr{Void},stmt::Ptr{Void})
3131
Ptr{Void}, (Ptr{Void},Ptr{Void}),
3232
db, stmt)
3333
end
34-
function sqlite3_prepare_v2(handle::Ptr{Void},query::String,stmt::Array{Ptr{Void},1},unused::Array{Ptr{Void},1})
34+
function sqlite3_prepare_v2(handle::Ptr{Void},query::AbstractString,stmt::Array{Ptr{Void},1},unused::Array{Ptr{Void},1})
3535
@NULLCHECK handle
3636
return ccall( (:sqlite3_prepare_v2, sqlite3_lib),
3737
Cint, (Ptr{Void},Ptr{Uint8},Cint,Ptr{Void},Ptr{Void}),
3838
handle,query,sizeof(query),stmt,unused)
3939
end
40-
function sqlite3_prepare16_v2(handle::Ptr{Void},query::String,stmt::Array{Ptr{Void},1},unused::Array{Ptr{Void},1})
40+
function sqlite3_prepare16_v2(handle::Ptr{Void},query::AbstractString,stmt::Array{Ptr{Void},1},unused::Array{Ptr{Void},1})
4141
@NULLCHECK handle
4242
return ccall( (:sqlite3_prepare16_v2, sqlite3_lib),
4343
Cint, (Ptr{Void},Ptr{Uint16},Cint,Ptr{Void},Ptr{Void}),
@@ -65,7 +65,7 @@ function sqlite3_bind_parameter_name(stmt::Ptr{Void}, col::Int)
6565
stmt, col)
6666
end
6767
# SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
68-
function sqlite3_bind_parameter_index(stmt::Ptr{Void},value::String)
68+
function sqlite3_bind_parameter_index(stmt::Ptr{Void},value::AbstractString)
6969
@NULLCHECK stmt
7070
return ccall( (:sqlite3_bind_parameter_index, sqlite3_lib),
7171
Cint, (Ptr{Void},Ptr{Uint8}),
@@ -100,7 +100,7 @@ function sqlite3_bind_null(stmt::Ptr{Void},col::Int)
100100
stmt,col)
101101
end
102102
# SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
103-
function sqlite3_bind_text(stmt::Ptr{Void},col::Int,value::String)
103+
function sqlite3_bind_text(stmt::Ptr{Void},col::Int,value::AbstractString)
104104
@NULLCHECK stmt
105105
return ccall( (:sqlite3_bind_text, sqlite3_lib),
106106
Cint, (Ptr{Void},Cint,Ptr{Uint8},Cint,Ptr{Void}),
@@ -251,7 +251,7 @@ function sqlite3_result_double(context::Ptr{Void},value::Float64)
251251
context,value)
252252
end
253253
# SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int)
254-
function sqlite3_result_error(context::Ptr{Void},msg::String)
254+
function sqlite3_result_error(context::Ptr{Void},msg::AbstractString)
255255
return ccall( (:sqlite3_result_error, sqlite3_lib),
256256
Void, (Ptr{Void},Ptr{Uint8},Cint),
257257
context,value,sizeof(msg)+1)
@@ -281,7 +281,7 @@ function sqlite3_result_null(context::Ptr{Void})
281281
context)
282282
end
283283
# SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int n, void(*)(void*));
284-
function sqlite3_result_text(context::Ptr{Void},value::String)
284+
function sqlite3_result_text(context::Ptr{Void},value::AbstractString)
285285
return ccall( (:sqlite3_result_text, sqlite3_lib),
286286
Void, (Ptr{Void},Ptr{Uint8},Cint,Ptr{Void}),
287287
context,value,sizeof(value)+1,SQLITE_TRANSIENT)
@@ -305,7 +305,7 @@ end
305305
# SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int)
306306

307307

308-
function sqlite3_create_function_v2(db::Ptr{Void},name::String,nargs::Integer,
308+
function sqlite3_create_function_v2(db::Ptr{Void},name::AbstractString,nargs::Integer,
309309
enc::Integer,data::Ptr{Void},func::Ptr{Void},
310310
step::Ptr{Void},final::Ptr{Void},
311311
destructor::Ptr{Void})
@@ -403,7 +403,7 @@ function sqlite3_os_end()
403403
Cint, (),
404404
)
405405
end
406-
function sqlite3_free_table(result::Array{String,1})
406+
function sqlite3_free_table(result::Array{AbstractString,1})
407407
return ccall( (:sqlite3_free_table, sqlite_lib),
408408
Void, (Ptr{Ptr{Void}},),
409409
result)
@@ -454,18 +454,18 @@ end
454454
# SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
455455

456456
# Not directly used
457-
function sqlite3_open_v2(file::String,handle::Array{Ptr{Void},1},flags::Cint,vfs::String)
457+
function sqlite3_open_v2(file::AbstractString,handle::Array{Ptr{Void},1},flags::Cint,vfs::AbstractString)
458458
return ccall( (:sqlite3_open_v2, sqlite3_lib),
459459
Cint, (Ptr{Uint8},Ptr{Void},Cint,Ptr{Uint8}),
460460
file,handle,flags,vfs)
461461
end
462-
function sqlite3_prepare(handle::Ptr{Void},query::String,stmt::Array{Ptr{Void},1},unused::Array{Ptr{Void},1})
462+
function sqlite3_prepare(handle::Ptr{Void},query::AbstractString,stmt::Array{Ptr{Void},1},unused::Array{Ptr{Void},1})
463463
@NULLCHECK handle
464464
return ccall( (:sqlite3_prepare, sqlite3_lib),
465465
Cint, (Ptr{Void},Ptr{Uint8},Cint,Ptr{Void},Ptr{Void}),
466466
handle,query,sizeof(query),stmt,unused)
467467
end
468-
function sqlite3_prepare16(handle::Ptr{Void},query::String,stmt::Array{Ptr{Void},1},unused::Array{Ptr{Void},1})
468+
function sqlite3_prepare16(handle::Ptr{Void},query::AbstractString,stmt::Array{Ptr{Void},1},unused::Array{Ptr{Void},1})
469469
@NULLCHECK handle
470470
return ccall( (:sqlite3_prepare16, sqlite3_lib),
471471
Cint, (Ptr{Void},Ptr{Uint8},Cint,Ptr{Void},Ptr{Void}),

src/show.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ begin
3838
ourshowcompact(io, x)
3939
return position(io)
4040
end
41-
ourstrwidth(x::String) = strwidth(x) + 2 # -> Int
41+
ourstrwidth(x::AbstractString) = strwidth(x) + 2 # -> Int
4242
ourstrwidth(s::Symbol) = int(ccall(:u8_strwidth,
4343
Csize_t,
4444
(Ptr{Uint8}, ),
@@ -61,7 +61,7 @@ end
6161
#' ourshowcompact(STDOUT, "abc")
6262
#' ourshowcompact(STDOUT, 10000)
6363
ourshowcompact(io::IO, x::Any) = showcompact(io, x) # -> Nothing
64-
ourshowcompact(io::IO, x::String) = showcompact(io, x) # -> Nothing
64+
ourshowcompact(io::IO, x::AbstractString) = showcompact(io, x) # -> Nothing
6565
ourshowcompact(io::IO, x::Symbol) = print(io, x) # -> Nothing
6666

6767
#' @description
@@ -83,7 +83,7 @@ ourshowcompact(io::IO, x::Symbol) = print(io, x) # -> Nothing
8383
#' chunk of the AbstractDataFrame that would be rendered to IO. Can
8484
#' be empty if the AbstractDataFrame would be printed without any
8585
#' ellipses.
86-
#' @param rowlabel::String The label that will be used when rendered the
86+
#' @param rowlabel::AbstractString The label that will be used when rendered the
8787
#' numeric ID's of each row. Typically, this will be set to "Row".
8888
#'
8989
#' @returns widths::Vector{Int} The maximum string widths required to render

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ results = query(db,"SELECT * FROM Employee;")
2727
@test length(results.colnames) == 15
2828
@test size(results) == (8,15)
2929
@test typeof(results[1,1]) == Int64
30-
@test typeof(results[1,2]) <: String
30+
@test typeof(results[1,2]) <: AbstractString
3131
@test results[1,5] == NULL
3232

3333
query(db,"SELECT * FROM Album;")

0 commit comments

Comments
 (0)