Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlite test #7

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 20 additions & 10 deletions src/jdbc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 4 additions & 2 deletions src/sqlite.jl
Original file line number Diff line number Diff line change
@@ -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
Binary file added test/data/sqlite.db
Binary file not shown.
15 changes: 12 additions & 3 deletions test/runtests.jl
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why this PR's test are failing right now is due to the fact that _dbconnect is trying to access the DB file but the DB file is not being sourced properly from the test environment. You will have to add in the db file to the test environment, like test/data/sqlite_test.db and then have the test environment find the file.

This is also why you got the error email is that I enabled the test suite to run and GitHub sent you an email to say that the test suite failed.

Let me know if you have any questions -- good start! :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is updated, thank you for your patience :D

Original file line number Diff line number Diff line change
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good test but could you also write a test that:

  1. Queries the database
  2. Reports a result
  3. Verifies that the result returns what is expected

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