Skip to content

Add support for prepared statements in JDBC #3116

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

Merged
merged 14 commits into from
Feb 13, 2025

Conversation

ohadzeliger
Copy link
Contributor

@ohadzeliger ohadzeliger commented Feb 6, 2025

This PR enables support for prepared statements on the JDBC server.
Specifically, support for PreparedStatement setObject() and setArray().
Also, JDBCRelationalConnection needed support for array creation.
A slew of type conversion utilities were added in support of these features.
In general, we have 3 models that we are dealing with:

  • Java (including primitives, [], null)
  • JDBC (including primitive, Array, Struct, NULL)
  • Protobuf

And because of the way the API is structured, we may need to perform conversions between all 3. Specifically, we support the following:

  • Java and SQL primitives are treated the same way
  • Java arrays are only supported in Connection.createArrayOf, where the type of array elements is also provided
  • SQL Array and Struct are assumed in all cases of nesting. That is, an array of elements would be assumed to have SQL Array if there is any nested array. The reasoning is that we would need the additional type information in these cases
    Some cleanup and restructuring of that code may be warranted, in addition to null, error and edge case testing.

The protobuf for the Array definition was changed in order to support the extra type information.
The change was made to be backwards compatible at the protobuf level but the old server (before this change) cannot handle arrays in parameters. In order to facilitate multi-version testing against the older servers we may be able to cherry-pick these commits to the server's branch.

@ohadzeliger ohadzeliger changed the title Initial implementation of prepared statement support in JDBC Add support for prepared statements in JDBC Feb 6, 2025
@ohadzeliger ohadzeliger marked this pull request as ready for review February 7, 2025 14:11
case Types.DOUBLE:
return column.getDouble();
default:
// TODO: NULL?
Copy link
Collaborator

Choose a reason for hiding this comment

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

"enum" is also missing from this, but enum support in general is awaiting: #3074

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is #3074 going to be merged in soon? If so, I can add support here after it was merged.

Copy link
Collaborator

Choose a reason for hiding this comment

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

#3074 merged, but I don't know that we need to add support here, now.

case Types.DOUBLE:
return column.getDouble();
default:
// TODO: NULL?
Copy link
Collaborator

Choose a reason for hiding this comment

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

#3074 merged, but I don't know that we need to add support here, now.

@@ -58,6 +58,7 @@ test_block:
-
# correlation are allowed in from-subquery.
- query: select x, sq.idr, sq.nr from a, (select * from r where r.idr = a.x) sq;
- supported_version: !current_version # changes in Proto definition for arrays
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sorry.

@ohadzeliger ohadzeliger merged commit 917ba7d into FoundationDB:main Feb 13, 2025
4 checks passed
@ohadzeliger ohadzeliger deleted the jdbc-prep-statement branch February 13, 2025 19:21
Copy link

Overall Project 80.17% 🍏

There is no coverage information present for the Files changed

ohadzeliger pushed a commit to ohadzeliger/fdb-record-layer that referenced this pull request Feb 13, 2025
…tement multi-version tests to run against the 4.0.459 release
Copy link

Overall Project 80.17% 🍏

There is no coverage information present for the Files changed

2 similar comments
Copy link

Overall Project 80.17% 🍏

There is no coverage information present for the Files changed

Copy link

Overall Project 80.17% 🍏

There is no coverage information present for the Files changed

Copy link

Overall Project 80.17% 🍏

There is no coverage information present for the Files changed

1 similar comment
Copy link

Overall Project 80.17% 🍏

There is no coverage information present for the Files changed

@ScottDugas ScottDugas added the enhancement New feature or request label Feb 14, 2025
ScottDugas pushed a commit that referenced this pull request Feb 14, 2025
Backport parts of PR #3116 in order to allow prepared statement
multi-version tests to run against the 4.0.459 release.
This only takes in the JDBC server pieces that are required to allow
prepared statement to run on JDBC, so that newer versions of the project
can test against this server to prove backwards compatibility.
The original PR had additional changes to the client side that are not
required for this purpose and so were left out of this PR.

Co-authored-by: Pranjal Gupta <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants