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
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
4 changes: 2 additions & 2 deletions src/sqlite.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function _dbconnect(connector::Type{SQLite.DB}; file_path)
function _dbconnect(connector::Type{SQLite.DB}, file_path::String)

return connector(file_path.second)
return connector(file_path)

end
Empty file added test/data/database.db
Empty file.
7 changes: 7 additions & 0 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
Expand Up @@ -2,3 +2,10 @@ using Test, Example

@test hello("Julia") == "Hello, Julia"
@test domath(2.0) ≈ 7.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you remove this?


@testset "_dbconnect function for SQLite" begin

conn= _dbconnect(SQLite.DB, "DBConnector.jl/test/data/database.db")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small think but could you rename "database.db" to "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


end