You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am in the process of making an all-in-one package to support connecting to a variety of databases. It is unregistered, but the draft is here: https://github.com/JuliaDatabases/DBConnector.jl
In short, I am running into a problem with the reflect statement for PostgreSQL when using a JDBC driver and JDBC.jl. I have a working example of the package here for SQLite:
Create a test environment and add the following packages:
As you can see, the above works perfectly for SQLite. However, when doing something similar for PostgreSQL, it fails. Sadly, I don't have a PostgreSQL DB set-up for reproducibility that you could use, but here is the script:
My assigned schema is not being interpolated correctly into the SQL block despite my prepare statement in DBConnector accepting the interpolation syntax. I have isolated the error to my extension of the function DBInterface.prepare in DBConnector as I can confirm that using my dispatch for DBInterface.connect and DBInterface.execute does work with code querying a PostgreSQL DB like DBInterface.execute(conn, "SELECT * FROM person LIMIT 1;") |> DataFrame
"""Dispatch for JDBC interface to DBInterface `prepare` functionBUG: Doesn't seem to work for all JDBC versions yet"""function DBInterface.prepare(conn::JDBC.JavaObject{Symbol("java.sql.Connection")}, args...; kws...)
stmt = JDBC.createStatement(conn)
result =executeQuery(stmt, args...)
return result
end
Any thoughts as to what I may be doing wrong?
Thanks!
The text was updated successfully, but these errors were encountered:
When you connect to PostgreSQL using JDBC (or ODBC) rather than using the standard LibPQ driver, you need to customize the dialect object. This is because JDBC expects query parameters to be represented as ? while the standard PostgreSQL expects parameters to be in the form $1, $2, and so on. Internally, JDBC driver rewrites the query into the standard PostgreSQL form before submitting it to the server.
Then use this object in place of :postgresql with all FunSQL functions that take a dialect parameter.
By the way, you will likely have the same problem with JDBC driver for SQLite as soon as you run any query with a parameter. The reason why your SQLite code haven't triggered an error is because SQLite does not support schemas, and therefore the reflect query does not have any parameters.
clarkevans
changed the title
[BUG] Prepared Statement Not Being Properly Interpolated for PostgreSQL reflect
Prepared Statement Not Being Properly Interpolated for PostgreSQL reflectFeb 26, 2024
Hi @xitology and co!
I am in the process of making an all-in-one package to support connecting to a variety of databases. It is unregistered, but the draft is here: https://github.com/JuliaDatabases/DBConnector.jl
In short, I am running into a problem with the
reflect
statement for PostgreSQL when using a JDBC driver and JDBC.jl. I have a working example of the package here for SQLite:As you can see, the above works perfectly for SQLite. However, when doing something similar for PostgreSQL, it fails. Sadly, I don't have a PostgreSQL DB set-up for reproducibility that you could use, but here is the script:
And I get the following error:
Doing some more digging in the
reflect
source code, I discovered that for some reason here:FunSQL.jl/src/reflect.jl
Lines 17 to 28 in 2741b75
My assigned
schema
is not being interpolated correctly into the SQL block despite my prepare statement in DBConnector accepting the interpolation syntax. I have isolated the error to my extension of the functionDBInterface.prepare
in DBConnector as I can confirm that using my dispatch forDBInterface.connect
andDBInterface.execute
does work with code querying a PostgreSQL DB likeDBInterface.execute(conn, "SELECT * FROM person LIMIT 1;") |> DataFrame
Here is the source code for my JDBC
DBInterface.prepare
dispatch (link here too: https://github.com/JuliaDatabases/DBConnector.jl/blob/main/src/jdbc.jl):Any thoughts as to what I may be doing wrong?
Thanks!
The text was updated successfully, but these errors were encountered: