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

Expose more JDBC/R2DBC statement methods for dialect authors #5098

Merged
merged 9 commits into from
Apr 4, 2024

Conversation

hfhbd
Copy link
Collaborator

@hfhbd hfhbd commented Mar 27, 2024

Oracle JDBC requires the correct java.sql.Types when using statement.setNull in setObject, so sqldelight should expose an overload too.
At the moment I am forced to implement my own jdbc driver.

@@ -182,11 +182,7 @@ class JdbcPreparedStatement(
private val preparedStatement: PreparedStatement,
) : SqlPreparedStatement {
override fun bindBytes(index: Int, bytes: ByteArray?) {
if (bytes == null) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not needed, the JDBC driver calls setNull for non primitive types itself.

@@ -155,7 +156,7 @@ fun CoroutineScope.R2dbcDriver(
}

// R2DBC uses boxed Java classes instead primitives: https://r2dbc.io/spec/1.0.0.RELEASE/spec/html/#datatypes
class R2dbcPreparedStatement(private val statement: Statement) : SqlPreparedStatement {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exposed to allow casting to a driver specific Statement to access driver methods.

"use bindObject with generics instead",
ReplaceWith("bindObject<T>", ""),
)
fun bindObject(index: Int, any: Any?, ignoredSqlType: Int) {
Copy link
Collaborator Author

@hfhbd hfhbd Mar 27, 2024

Choose a reason for hiding this comment

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

This ignoredSqlType parameter is needed because the dialect does not know if it is generating sync or async code. Ideally, we would have two dialects focussing on sync/async or we push the Gradle flag down to the dialect. I am okay with both.

@@ -261,20 +253,28 @@ class JdbcPreparedStatement(
}
}

fun bindObjectOther(index: Int, obj: Any?) {
fun bindObject(index: Int, obj: Any?, type: Int) {
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 makes this a binary-incompatible change, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we can also keep it but it's only used by the Postgres driver.
And according to Alec only the runtime needs to be api compatible.

Copy link
Member

Choose a reason for hiding this comment

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

I think that was pre-2.0.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Binary compatibility matters less for a driver like R2DBC which is still more "experimental", but the JDBC driver is widely used (and the SQLite one is an implementation of it) so we should definitely maintain compatibility for it.

We should enable the API dumper plugin!

Copy link
Contributor

@griffio griffio Apr 2, 2024

Choose a reason for hiding this comment

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

💁 I can refactor uses of bindObjectOther in the Postgres dialect to use this new api once it has been merged, then remove bindObjectOther before any new release.
bindObjectOther has only recently been added in the snapshot builds - so can be changed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can refactor uses of bindObjectOther

This is already part of this PR, but thanks.

It's only recently been added in the snapshot builds - so can be changed.

In this case I agree, we can change it.

We should enable the API dumper plugin!

Yes, will do it in another PR.

@griffio griffio mentioned this pull request Apr 2, 2024
@hfhbd hfhbd merged commit 8b4f448 into master Apr 4, 2024
12 checks passed
@hfhbd hfhbd deleted the hfhbd/exposeJDBC branch April 4, 2024 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants