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

The driver doens't honor default properties #1958

Open
mmimica opened this issue Nov 8, 2022 · 4 comments
Open

The driver doens't honor default properties #1958

mmimica opened this issue Nov 8, 2022 · 4 comments
Labels
Backlog The topic in question has been recognized and added to development backlog Enhancement An enhancement to the driver. Lower priority than bugs.
Projects

Comments

@mmimica
Copy link
Contributor

mmimica commented Nov 8, 2022

Driver version

11.2.1 but probably goes way back.

Problem description

java.util.Properties has notion of "default" properties, as a way to inherit properties. This mechanism is used by testcontainers framework. The driver looks only for top-level properties.

var defaults = new Properties();
defaults.setProperty("enablePrepareOnFirstPreparedStatementCall", "true");

Properties props = new Properties(defaults);
props.setProperty("encrypt", "false");
props.setProperty("user", "sa");
props.setProperty("password", "yourStrong(_)Password");

try (var conn = new SQLServerDriver().connect("jdbc:sqlserver://localhost", props)) {
    System.out.println(((SQLServerConnection) conn).getEnablePrepareOnFirstPreparedStatementCall());
}

Expected behavior

The above should print true, as the passed props.getProperty("enablePrepareOnFirstPreparedStatementCall") evaluates to "true".

Actual behavior

It prints false, ignoring the property passed to the driver.

@Jeffery-Wasty
Copy link
Member

Hi @mmimica,

Thank you for identifying an issue and creating a PR. Because of the extensive testing required, this issue and its PR will be backlogged for at least the next little while. We'll take a look at it again as soon as we can.

@Jeffery-Wasty Jeffery-Wasty added this to Under Investigation in MSSQL JDBC via automation Nov 9, 2022
@Jeffery-Wasty Jeffery-Wasty added the Backlog The topic in question has been recognized and added to development backlog label Nov 9, 2022
@Jeffery-Wasty Jeffery-Wasty moved this from Under Investigation to Backlog in MSSQL JDBC Nov 9, 2022
@Jeffery-Wasty Jeffery-Wasty added the Enhancement An enhancement to the driver. Lower priority than bugs. label Nov 9, 2022
@lilgreenbird
Copy link
Member

hi @mmimica

just to clarify, the 1st part of your example does work we do use that in our junit tests eg here.

The 2nd part of your repro is not currently supported and would require quite a bit of testing effort to ensure it works with all existing properties. We have to triage and prioritize all issues and enhancement requests for the driver so given that there are other supported ways to set properties for the driver this enhancement will likely not be treated as very high priority. So in the mean time, please use other supported ways to set the properties for the driver.

@mmimica
Copy link
Contributor Author

mmimica commented Nov 15, 2022

In the real world out there, a developer seldomly has a chance to interact with a JDBC driver directly. Usually the driver gets its Properties instance from a connection pool library, which may get it from an app server or some framework which injects settings from the environment... Any library in this chain may use a copy-constructor to instantiate Properties (usually to create a preventive copy, to avoid using clone()) and in that case some properties will not be applied.

Properties infamously inherits from Hashtable, but has its own methods that are supposed to be used when getting/setting properties.

I understand the change may impact existing working environments. I already have a workaround for my case. I mainly created this ticket for visibility. It's up to you what you are going to do with with the PR.

@lilgreenbird lilgreenbird changed the title The driver doens't hornor default properties The driver doens't honor default properties Nov 18, 2022
@michaelrobertharmon
Copy link

In revision 12.2.0 of SQLServerDriver.java the method named fixupProperties does not account for props.defaults. This results in loss of client requested parameters that were relegated to the defaults member as @mmimica mentioned in a previous comment.

I am working around the issue by including the JDBC connection properties in the connection URL (as opposed to a separate Properties parameter of the connect method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backlog The topic in question has been recognized and added to development backlog Enhancement An enhancement to the driver. Lower priority than bugs.
Projects
MSSQL JDBC
  
Backlog
Development

Successfully merging a pull request may close this issue.

4 participants