diff --git a/Project.toml b/Project.toml index e73cf82..a4d780c 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,8 @@ version = "1.0.0" [deps] DBInterface = "a10d1c49-ce27-4219-8d33-6db1a4562965" +DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +Example = "7876af07-990d-54b4-ab0e-23690620f79a" JDBC = "6042db11-3c3d-5e84-8dba-9cbf74c9ba48" LibPQ = "194296ae-ab2e-5f79-8cd4-7183a0a5a0d1" MySQL = "39abe10b-433b-5dbd-92d4-e302a9df00cd" diff --git a/docs/make.jl b/docs/make.jl index fd29b00..11e840f 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,5 +1,5 @@ -using Documenter, Example +#using Documenter, Example -makedocs(modules = [Example], sitename = "Example.jl") +#makedocs(modules = [Example], sitename = "Example.jl") -deploydocs(repo = "github.com/quinnj/Example.jl.git", push_preview = true) +#deploydocs(repo = "github.com/quinnj/Example.jl.git", push_preview = true) diff --git a/src/jdbc.jl b/src/jdbc.jl index 1627904..51b6eb8 100644 --- a/src/jdbc.jl +++ b/src/jdbc.jl @@ -8,23 +8,33 @@ function DBInterface.connect(::Type{JDBC.Connection}, args...; connection_string catch println("JVM already initialized") end - JDBC.Connection(connection_string) + JDBC.DriverManager.getConnection(connection_string) end """ -Dispatch for LibPQ interface to DBInterface `prepare` function -TODO: Not fully implemented yet +Dispatch for JDBC interface to DBInterface `prepare` function +BUG: Doesn't seem to work for all JDBC versions yet """ -# DBInterface.prepare(conn::JDBC.Connection, args...; kws...) = -# JDBC.prepareStatement(conn, args...; kws...) +function DBInterface.prepare(conn::JDBC.JavaObject{Symbol("java.sql.Connection")}, args...; kws...) + stmt = JDBC.createStatement(conn) + result = executeQuery(stmt, args...) + return result +end + +""" +Workaround for JDBC interface to DBInterface's `execute` function +""" +function DBInterface.execute(conn::JDBC.JavaObject{Symbol("java.sql.ResultSet")}, args...; kws...) + JDBC.Source(conn) +end """ -Workaround for LibPQ interface to DBInterface's `execute` function +Workaround for JDBC interface to DBInterface's `execute` function """ -function DBInterface.execute(conn::Union{JDBC.Connection, JDBC.JPreparedStatement}, args...; kws...) - csr = JDBC.cursor(conn) - JDBC.execute!(csr, args..., kws...) - JDBC.Source(csr) +function DBInterface.execute(conn::JDBC.JavaObject{Symbol("java.sql.Connection")}, args...; kws...) + stmt = JDBC.createStatement(conn) + result = executeQuery(stmt, args...) + JDBC.Source(result) end diff --git a/src/sqlite.jl b/src/sqlite.jl index a35d5ad..8295f37 100644 --- a/src/sqlite.jl +++ b/src/sqlite.jl @@ -1,5 +1,7 @@ -function _dbconnect(connector::Type{SQLite.DB}; file_path) +using SQLite - return connector(file_path.second) +function _dbconnect(connector::Type{SQLite.DB}, file_path::String) + + return connector(file_path) end diff --git a/test/data/sqlite.db b/test/data/sqlite.db new file mode 100644 index 0000000..7c5d231 Binary files /dev/null and b/test/data/sqlite.db differ diff --git a/test/runtests.jl b/test/runtests.jl index 35f99ea..71c52f9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,13 @@ -using Test, Example +using Test, DataFrames, SQLite +include("../src/sqlite.jl") -@test hello("Julia") == "Hello, Julia" -@test domath(2.0) ≈ 7.0 +@testset "_dbconnect function for SQLite" begin + + conn= _dbconnect(SQLite.DB, "../test/data/sqlite.db") + @test @isdefined conn + output = DBInterface.execute(conn, "SELECT age FROM PERSON WHERE name = 'John Doe'") |> DataFrame + out = output[1,1] + expected_output = 30; + @test out == expected_output + +end