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

feat: enable native JDBC connections #28

Merged
merged 3 commits into from
Feb 4, 2022
Merged

Conversation

olavloite
Copy link
Collaborator

Enables connections to PgAdapter from the native PostgreSQL JDBC driver. This requires a couple of minor tweaks to the startup protocol:

  1. Some older versions of the JDBC driver require the encoding values to be in upper case (i.e. UTF8 instead of utf8).
  2. The date style should also include the year-month-day order.
  3. The value for standard_conforming_strings should be on or off (not true or false).

Copy link
Collaborator

@Vizerai Vizerai left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Maybe we should add in more pg-jdbc testing, but it doesn't have to be done in this PR.

DriverManager.getConnection(
String.format("jdbc:postgresql://localhost:%d/", testEnv.getPort()))) {
try (ResultSet resultSet =
connection.createStatement().executeQuery("SELECT 'Hello World!'")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this work with all other queries as well using pg-jdbc? I assume the wireprotocol is the same for pg-jdbc?

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, the wireprotocol is the same for pg-jdbc, so yes it will in theory work with other queries. However:

  1. The pg-jdbc driver uses binary format for many query parameter types, so we need to support that for parameterized queries to work. That is included in feat: add support incoming binary values #27
  2. The pg-jdbc driver sends timestamp and date parameter values as untyped parameters. Support for that is also included in feat: add support incoming binary values #27 (only for timestamp at this moment, as we currently do not support date).
  3. The pg-jdbc driver prefers the extended query mode over simple query mode (which is normally used in psql). That will probably also need some tweaking.

@olavloite
Copy link
Collaborator Author

Overall LGTM. Maybe we should add in more pg-jdbc testing, but it doesn't have to be done in this PR.

Yeah, I'll bring in a lot more test cases in separate PRs. #23 already contains a lot of test cases, but I decided to split it into several smaller PRs so it would be easier to review. Many of the test cases in #23 will only succeed once #27 has been merged, as the tests use parameterized queries and the pg-jdbc driver sends parameter values in binary format as opposed to the default text format used by psql.

@olavloite olavloite enabled auto-merge (squash) February 4, 2022 08:13
@olavloite olavloite merged commit ceba433 into postgresql-dialect Feb 4, 2022
@olavloite olavloite deleted the jdbc-startup branch March 6, 2022 16:06
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.

2 participants