diff --git a/Project.toml b/Project.toml index 5472c03..1e2b2fe 100644 --- a/Project.toml +++ b/Project.toml @@ -19,7 +19,7 @@ DataValues = "0.4.11" IteratorInterfaceExtensions = "0.1.1, 1" MacroTools = "0.5" QueryOperators = "0.9" -SQLite = "0.8.1, 0.9" +SQLite = "1" TableShowUtils = "0.2.5" TableTraits = "0.4.1, 1" julia = "1" diff --git a/src/QuerySQLite.jl b/src/QuerySQLite.jl index d034cf4..8873c58 100644 --- a/src/QuerySQLite.jl +++ b/src/QuerySQLite.jl @@ -15,7 +15,7 @@ import QueryOperators import Random: randstring import SQLite import SQLite: getvalue -using SQLite: columns, DB, execute!, generate_namedtuple, juliatype, +using SQLite: columns, DB, execute, juliatype, SQLITE_DONE, SQLITE_NULL, SQLITE_ROW, sqlite3_column_count, sqlite3_column_name, sqlite3_column_type, sqlite3_step, sqlitevalue, Stmt, tables import Statistics: mean, sum diff --git a/src/iterate.jl b/src/iterate.jl index 5fac032..d0cacdf 100644 --- a/src/iterate.jl +++ b/src/iterate.jl @@ -1,3 +1,12 @@ +function generate_namedtuple(::Type{NamedTuple{names, types}}, q) where {names, types} + if @generated + vals = Tuple(:(getvalue(q, $i, $(fieldtype(types, i)))) for i = 1:fieldcount(types)) + return :(NamedTuple{names, types}(($(vals...),))) + else + return NamedTuple{names, types}(Tuple(getvalue(q, i, fieldtype(types, i)) for i = 1:fieldcount(types))) + end +end + # This section of the code hijacks SQLite internals to make queryverse-compatible iterators # TODO: submit as a PR to SQLite struct SQLiteCursor{Row} @@ -105,7 +114,7 @@ function getiterator(source_code::SourceCode) string(finalize(translate(source_code.code))) ) # bind!(statement, values) - status = execute!(statement) + status = execute(statement) handle = statement.handle schema = ntuple( let handle = handle diff --git a/test/runtests.jl b/test/runtests.jl index fca0704..6eb6579 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,7 +5,7 @@ using Dates: Date, DateTime, format, Time using Documenter: doctest using Query using QueryTables -using SQLite: DB, drop!, execute!, Stmt +using SQLite: DB, drop!, execute, Stmt using Statistics: mean using Test @@ -103,10 +103,13 @@ end @testset "Systematic tests" begin -filename = joinpath(@__DIR__, "test.sqlite") +filename = joinpath(@__DIR__, "tmp", "test.sqlite") +isfifo(filename) && rm(filename) +cp(joinpath(@__DIR__, "test.sqlite"), filename) + connection = DB(filename) -execute!(Stmt(connection, """DROP TABLE IF EXISTS test""")) -execute!(Stmt(connection, """ +execute(Stmt(connection, """DROP TABLE IF EXISTS test""")) +execute(Stmt(connection, """ CREATE TABLE test ( zero Int, one Int, @@ -123,7 +126,7 @@ execute!(Stmt(connection, """ datetime_text Text, format Text )""")) -execute!(Stmt(connection, """ +execute(Stmt(connection, """ INSERT INTO test VALUES(0, 1, -1, "ab", NULL, 65, "a", "b", " a ", "_a_", "a%", 1.11, "2019-12-08T11:09:00", "%Y-%m-%d %H:%M:%S") """)) small = Database(connection) diff --git a/test/tmp/.gitignore b/test/tmp/.gitignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/test/tmp/.gitignore @@ -0,0 +1 @@ +*