Skip to content

Commit bd27c0c

Browse files
authored
Updates for 1.0 (#153)
* Updates for 1.0 * Fix REQUIRE' * Switch CI to 0.7 until upstream deps are fixed * Switch to use BinaryProvider * Fix library reference name
1 parent 8c3bd05 commit bd27c0c

File tree

12 files changed

+333
-311
lines changed

12 files changed

+333
-311
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*.jl.*.cov
33
*.jl.mem
44
/deps/builds
5+
/deps/build.log
56
/deps/usr
67
CMakeLists.txt.user
78
/deps/deps.jl

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ os:
77
- osx
88

99
julia:
10-
- 0.6
10+
- 0.7
1111
- nightly
1212

1313
notifications:
1414
email: false
1515

1616
after_success:
17-
- julia -e 'cd(Pkg.dir("SQLite")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
18-
- julia -e 'Pkg.add("Documenter")'
19-
- julia -e 'cd(Pkg.dir("SQLite")); include(joinpath("docs", "make.jl"))'
17+
- julia -e 'using Pkg; cd(Pkg.dir("SQLite")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
18+
- julia -e 'using Pkg; Pkg.add("Documenter")'
19+
- julia -e 'using Pkg; cd(Pkg.dir("SQLite")); include(joinpath("docs", "make.jl"))'

REQUIRE

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
julia 0.6
2-
BinDeps
3-
@osx Homebrew
4-
@windows WinRPM
1+
julia 0.7
52
DataStreams 0.3.0
63
DataFrames 0.11.0
74
WeakRefStrings 0.4.0
85
LegacyStrings
6+
Missings
7+
BinaryProvider

appveyor.yml

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
5-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
6-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
3+
- julia_version: 0.7
4+
- julia_version: nightly
5+
6+
platform:
7+
- x86 # 32-bit
8+
- x64 # 64-bit
9+
10+
# # Uncomment the following lines to allow failures on nightly julia
11+
# # (tests will run but not make your overall status red)
12+
# matrix:
13+
# allow_failures:
14+
# - julia_version: nightly
715

816
branches:
917
only:
@@ -17,25 +25,18 @@ notifications:
1725
on_build_status_changed: false
1826

1927
install:
20-
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
21-
# if there's a newer build queued for the same PR, cancel this one
22-
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
23-
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
24-
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
25-
throw "There are newer queued builds for this pull request, failing early." }
26-
# Download most recent Julia Windows binary
27-
- ps: (new-object net.webclient).DownloadFile(
28-
$env:JULIA_URL,
29-
"C:\projects\julia-binary.exe")
30-
# Run installer silently, output to C:\projects\julia
31-
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
28+
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))
3229

3330
build_script:
34-
# Need to convert from shallow to complete for Pkg.clone to work
35-
- IF EXIST .git\shallow (git fetch --unshallow)
36-
- C:\projects\julia\bin\julia -e "versioninfo();
37-
Pkg.clone(pwd(), \"SQLite\"); Pkg.build(\"SQLite\")"
38-
- where *sqlite3*
31+
- echo "%JL_BUILD_SCRIPT%"
32+
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"
3933

4034
test_script:
41-
- C:\projects\julia\bin\julia -e "Pkg.test(\"SQLite\")"
35+
- echo "%JL_TEST_SCRIPT%"
36+
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
37+
38+
# # Uncomment to support code coverage upload. Should only be enabled for packages
39+
# # which would have coverage gaps without running on Windows
40+
# on_success:
41+
# - echo "%JL_CODECOV_SCRIPT%"
42+
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"

deps/build.jl

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,46 @@
1-
using BinDeps
2-
using Compat
1+
using BinaryProvider # requires BinaryProvider 0.3.0 or later
32

4-
@BinDeps.setup
3+
# Parse some basic command-line arguments
4+
const verbose = "--verbose" in ARGS
5+
const prefix = Prefix(get([a for a in ARGS if a != "--verbose"], 1, joinpath(@__DIR__, "usr")))
6+
products = [
7+
LibraryProduct(prefix, ["libsqlite3"], :libsqlite),
8+
]
59

6-
sqlite3_lib = library_dependency("sqlite3_lib", aliases = ["sqlite3","sqlite3-64","libsqlite3","libsqlite3-0"])
10+
# Download binaries from hosted location
11+
bin_prefix = "https://github.com/JuliaDatabases/SQLiteBuilder/releases/download/v0.9.0"
712

8-
if is_windows()
9-
using WinRPM
10-
provides(WinRPM.RPM, "libsqlite3-0",sqlite3_lib, os = :Windows)
11-
elseif is_apple()
12-
using Homebrew
13-
provides(Homebrew.HB, "sqlite", sqlite3_lib, os = :Darwin)
14-
elseif is_linux()
15-
provides(Yum, Dict("sqlite3-devel" => sqlite3_lib))
16-
provides(AptGet, Dict("sqlite3" => sqlite3_lib))
13+
# Listing of files generated by BinaryBuilder:
14+
download_info = Dict(
15+
Linux(:aarch64, :glibc) => ("$bin_prefix/SQLiteBuilder.v0.1.0.aarch64-linux-gnu.tar.gz", "a72759ea789697475bc268631cd45723967403dcbd630e7090310acf3fe4e213"),
16+
Linux(:aarch64, :musl) => ("$bin_prefix/SQLiteBuilder.v0.1.0.aarch64-linux-musl.tar.gz", "865ad1af7907d6fad61a217cc347e88c31a1e14fde1e8b1842be30f40caadb2f"),
17+
Linux(:armv7l, :glibc, :eabihf) => ("$bin_prefix/SQLiteBuilder.v0.1.0.arm-linux-gnueabihf.tar.gz", "213587798e00e3d55600bfd8e9224ec7d25051df36443007c22d2616744d82a6"),
18+
Linux(:armv7l, :musl, :eabihf) => ("$bin_prefix/SQLiteBuilder.v0.1.0.arm-linux-musleabihf.tar.gz", "28aec3c8eba103d9680dcd9a869189a7a49b16fb26df0cf696025050cfa94b7c"),
19+
Linux(:i686, :glibc) => ("$bin_prefix/SQLiteBuilder.v0.1.0.i686-linux-gnu.tar.gz", "7b65157e359c44b2a57f12d69badb33dfe49af91a1550a2a4ce73fa39437384c"),
20+
Linux(:i686, :musl) => ("$bin_prefix/SQLiteBuilder.v0.1.0.i686-linux-musl.tar.gz", "6bd07d37a3471faae3eccbdda15331e2fef3617dc6517cdd5957ff0f232bfc66"),
21+
Windows(:i686) => ("$bin_prefix/SQLiteBuilder.v0.1.0.i686-w64-mingw32.tar.gz", "152e7c7933c3b1fcda56177a13d37e130d6dc33dea8b4af18f462ef8bc415ba4"),
22+
Linux(:powerpc64le, :glibc) => ("$bin_prefix/SQLiteBuilder.v0.1.0.powerpc64le-linux-gnu.tar.gz", "994abe7690163a94b58f589808380ac14e594d2a088d519ff1faf56365f20d10"),
23+
MacOS(:x86_64) => ("$bin_prefix/SQLiteBuilder.v0.1.0.x86_64-apple-darwin14.tar.gz", "acc1d370715be7f4a765e517ae8b4a9fd0ee9ffb08ffa6c81118aa5dc0db3eca"),
24+
Linux(:x86_64, :glibc) => ("$bin_prefix/SQLiteBuilder.v0.1.0.x86_64-linux-gnu.tar.gz", "45ba487144ff8e11271130ae9abbb3af5722739608dee6ef44be0d0c1205fa9a"),
25+
Linux(:x86_64, :musl) => ("$bin_prefix/SQLiteBuilder.v0.1.0.x86_64-linux-musl.tar.gz", "998b995bc9a2d66a99de2e85a210af865e4993af51a295ce4dd88c26136a4951"),
26+
FreeBSD(:x86_64) => ("$bin_prefix/SQLiteBuilder.v0.1.0.x86_64-unknown-freebsd11.1.tar.gz", "060d7a0512d16eed4b97787eaa70cb596695c300a3859a57b72b37c4e2be54e0"),
27+
Windows(:x86_64) => ("$bin_prefix/SQLiteBuilder.v0.1.0.x86_64-w64-mingw32.tar.gz", "dd323668391ede718e39994819cd475568aadc12563968dfd14900e338b78841"),
28+
)
29+
30+
# Install unsatisfied or updated dependencies:
31+
unsatisfied = any(!satisfied(p; verbose=verbose) for p in products)
32+
if haskey(download_info, platform_key())
33+
url, tarball_hash = download_info[platform_key()]
34+
if unsatisfied || !isinstalled(url, tarball_hash; prefix=prefix)
35+
# Download and install binaries
36+
install(url, tarball_hash; prefix=prefix, force=true, verbose=verbose)
37+
end
38+
elseif unsatisfied
39+
# If we don't have a BinaryProvider-compatible .tar.gz to download, complain.
40+
# Alternatively, you could attempt to install from a separate provider,
41+
# build from source or something even more ambitious here.
42+
error("Your platform $(triplet(platform_key())) is not supported by this package!")
1743
end
1844

19-
@BinDeps.install Dict(:sqlite3_lib => :sqlite3_lib)
45+
# Write out a deps.jl file that will contain mappings for our products
46+
write_deps_file(joinpath(@__DIR__, "deps.jl"), products)

src/SQLite.jl

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
__precompile__(true)
21
module SQLite
32

4-
using Missings, DataStreams, WeakRefStrings, LegacyStrings, DataFrames
3+
using Random, Missings, DataStreams, WeakRefStrings, LegacyStrings, DataFrames
54
import LegacyStrings: UTF16String
65

7-
if VERSION < v"0.7.0-DEV.2562"
8-
import Base: finalizer
9-
finalizer(f::Function, o) = finalizer(o, f)
10-
end
6+
import Serialization
117

128
export Data, DataFrame
139

@@ -35,11 +31,11 @@ Constructors:
3531
"""
3632
mutable struct DB
3733
file::String
38-
handle::Ptr{Void}
34+
handle::Ptr{Cvoid}
3935
changes::Int
4036

4137
function DB(f::AbstractString)
42-
handle = Ref{Ptr{Void}}()
38+
handle = Ref{Ptr{Cvoid}}()
4339
f = isempty(f) ? f : expanduser(f)
4440
if @OK sqliteopen(f, handle)
4541
db = new(f, handle[], 0)
@@ -66,11 +62,11 @@ Base.show(io::IO, db::SQLite.DB) = print(io, string("SQLite.DB(", db.file == ":m
6662
"""
6763
mutable struct Stmt
6864
db::DB
69-
handle::Ptr{Void}
65+
handle::Ptr{Cvoid}
7066

7167
function Stmt(db::DB,sql::AbstractString)
72-
handle = Ref{Ptr{Void}}()
73-
sqliteprepare(db, sql, handle, Ref{Ptr{Void}}())
68+
handle = Ref{Ptr{Cvoid}}()
69+
sqliteprepare(db, sql, handle, Ref{Ptr{Cvoid}}())
7470
stmt = new(db, handle[])
7571
finalizer(_close, stmt)
7672
return stmt
@@ -93,7 +89,7 @@ export @sr_str, @register, register
9389
9490
clears any bound values to a prepared SQL statement.
9591
"""
96-
function Base.clear!(stmt::Stmt)
92+
function clear!(stmt::Stmt)
9793
sqlite3_clear_bindings(stmt.handle)
9894
return
9995
end
@@ -164,7 +160,7 @@ bind!(stmt::Stmt, i::Int, val::Vector{UInt8}) = (sqlite3_bind_blob(stmt.handle,
164160
# Fallback is BLOB and defaults to serializing the julia value
165161

166162
# internal wrapper mutable struct to, in-effect, mark something which has been serialized
167-
struct Serialization
163+
struct Serialized
168164
object
169165
end
170166

@@ -174,8 +170,8 @@ function sqlserialize(x)
174170
# deserialize will sometimes return a random object when called on an array
175171
# which has not been previously serialized, we can use this mutable struct to check
176172
# that the array has been serialized
177-
s = Serialization(x)
178-
serialize(GLOBAL_BUF, s)
173+
s = Serialized(x)
174+
Serialization.serialize(GLOBAL_BUF, s)
179175
return take!(GLOBAL_BUF)
180176
end
181177
# fallback method to bind arbitrary julia `val` to the parameter at index `i` (object is serialized)
@@ -186,18 +182,14 @@ struct SerializeError <: Exception
186182
end
187183

188184
# magic bytes that indicate that a value is in fact a serialized julia value, instead of just a byte vector
189-
# const SERIALIZATION = UInt8[0x11,0x01,0x02,0x0d,0x53,0x65,0x72,0x69,0x61,0x6c,0x69,0x7a,0x61,0x74,0x69,0x6f,0x6e,0x23]
190-
if VERSION < v"0.7.0-DEV.1833"
191-
const SERIALIZATION = UInt8[0x34,0x10,0x01,0x0d,0x53,0x65,0x72,0x69,0x61,0x6c,0x69,0x7a,0x61,0x74,0x69,0x6f,0x6e,0x1f]
192-
else
193-
const SERIALIZATION = UInt8[0x37,0x4a,0x4c,0x07,0x04,0x00,0x00,0x00,0x34,0x10,0x01,0x0d,0x53,0x65,0x72,0x69,0x61,0x6c]
194-
end
185+
const SERIALIZATION = UInt8[0x37,0x4a,0x4c,0x07,0x04,0x00,0x00,0x00,0x34,0x10,0x01,0x0a,0x53,0x65,0x72,0x69,0x61,0x6c]
186+
195187
function sqldeserialize(r)
196188
ret = ccall(:memcmp, Int32, (Ptr{UInt8}, Ptr{UInt8}, UInt),
197189
SERIALIZATION, r, min(18, length(r)))
198190
if ret == 0
199191
try
200-
v = deserialize(IOBuffer(r))
192+
v = Serialization.deserialize(IOBuffer(r))
201193
return v.object
202194
catch e
203195
throw(SerializeError("Error deserializing non-primitive value out of database; this is probably due to using SQLite.jl with a different Julia version than was used to originally serialize the database values. The same Julia version that was used to serialize should be used to extract the database values into a different format (csv file, feather file, etc.) and then loaded back into the sqlite database with the current Julia version."))
@@ -211,9 +203,9 @@ end
211203
#int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
212204

213205
"""
214-
`SQLite.execute!(stmt::SQLite.Stmt)` => `Void`
206+
`SQLite.execute!(stmt::SQLite.Stmt)` => `Cvoid`
215207
216-
`SQLite.execute!(db::DB, sql::String)` => `Void`
208+
`SQLite.execute!(db::DB, sql::String)` => `Cvoid`
217209
218210
219211
Execute a prepared SQLite statement, not checking for or returning any results.
@@ -243,7 +235,7 @@ A vector of identifiers will be separated by commas.
243235
"""
244236
function esc_id end
245237

246-
esc_id(x::AbstractString) = "\"" * replace(x,"\"","\"\"") * "\""
238+
esc_id(x::AbstractString) = "\"" * replace(x, "\""=>"\"\"") * "\""
247239
esc_id(X::AbstractVector{S}) where {S <: AbstractString} = join(map(esc_id, X), ',')
248240

249241

@@ -274,7 +266,7 @@ function transaction(db, mode="DEFERRED")
274266
end
275267
function transaction(f::Function, db)
276268
# generate a random name for the savepoint
277-
name = string("SQLITE", randstring(10))
269+
name = string("SQLITE", Random.randstring(10))
278270
execute!(db, "PRAGMA synchronous = OFF;")
279271
transaction(db, name)
280272
try

src/Sink.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ Data.weakrefstrings(::Type{Sink}) = true
4444
function Sink(sch::Data.Schema, T, append::Bool, db::DB, name::AbstractString; reference::Vector{UInt8}=UInt8[], kwargs...)
4545
sink = Sink(db, name, sch; append=append, kwargs...)
4646
execute!(sink.db, "PRAGMA synchronous = OFF;")
47-
sink.transaction = string("SQLITE",randstring(10))
47+
sink.transaction = string("SQLITE", Random.randstring(10))
4848
transaction(sink.db, sink.transaction)
4949
return sink
5050
end
5151
function Sink(sink, sch::Data.Schema, T, append::Bool; reference::Vector{UInt8}=UInt8[])
5252
execute!(sink.db, "PRAGMA synchronous = OFF;")
53-
sink.transaction = string("SQLITE", randstring(10))
53+
sink.transaction = string("SQLITE", Random.randstring(10))
5454
transaction(sink.db, sink.transaction)
5555
!append && execute!(sink.db, "delete from $(esc_id(sink.tablename))")
5656
return sink

src/Source.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ function Source(db::DB, sql::AbstractString, values=[]; rows::Union{Int, Missing
1414
bind!(stmt, values)
1515
status = SQLite.execute!(stmt)
1616
cols = SQLite.sqlite3_column_count(stmt.handle)
17-
header = Vector{String}(cols)
18-
types = Vector{Type}(cols)
17+
header = Vector{String}(undef, cols)
18+
types = Vector{Type}(undef, cols)
1919
for i = 1:cols
2020
header[i] = unsafe_string(SQLite.sqlite3_column_name(stmt.handle, i))
2121
if nullable
@@ -60,7 +60,7 @@ function sqlitevalue(::Type{T}, handle, col) where {T}
6060
blob = convert(Ptr{UInt8}, sqlite3_column_blob(handle, col))
6161
b = sqlite3_column_bytes(handle, col)
6262
buf = zeros(UInt8, b) # global const?
63-
unsafe_copy!(pointer(buf), blob, b)
63+
unsafe_copyto!(pointer(buf), blob, b)
6464
r = sqldeserialize(buf)::T
6565
return r
6666
end
@@ -85,7 +85,7 @@ function Data.streamfrom(source::SQLite.Source, ::Type{Data.Field}, ::Type{Union
8585
val = missing
8686
else
8787
TT = SQLite.juliatype(t) # native SQLite Int, Float, and Text types
88-
val = SQLite.sqlitevalue(ifelse(TT === Any && !isbits(T), T, TT), handle, col)
88+
val = SQLite.sqlitevalue(ifelse(TT === Any && !isbitstype(T), T, TT), handle, col)
8989
end
9090
col == source.schema.cols && (source.status = sqlite3_step(handle))
9191
return val::Union{T, Missing}
@@ -97,7 +97,7 @@ function Data.streamfrom(source::SQLite.Source, ::Type{Data.Field}, ::Type{T}, r
9797
throw(Data.NullException("encountered missing value in non-missing typed column: row = $row, col = $col"))
9898
else
9999
TT = SQLite.juliatype(t) # native SQLite Int, Float, and Text types
100-
val::T = sqlitevalue(ifelse(TT === Any && !isbits(T), T, TT), handle, col)
100+
val::T = sqlitevalue(ifelse(TT === Any && !isbitstype(T), T, TT), handle, col)
101101
end
102102
col == source.schema.cols && (source.status = sqlite3_step(handle))
103103
return val

0 commit comments

Comments
 (0)