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

Change in Behavior - Bind Variable Detection w/o Space Before Minus #2510

Closed
alkamo opened this issue Oct 10, 2023 · 6 comments
Closed

Change in Behavior - Bind Variable Detection w/o Space Before Minus #2510

alkamo opened this issue Oct 10, 2023 · 6 comments
Assignees

Comments

@alkamo
Copy link

alkamo commented Oct 10, 2023

Observed in JDBI 3.41.3
Not observed in JDBI 3.38.2
Java 17

A query written as select * from some_table where value = :bindVariable-7 results in org.jdbi.v3.core.statement.UnableToCreateStatementException: Missing named parameter 'bindVariable-7' in binding. It seems likely that changing the SQL to include a space between the bind variable name and the minus would correct this behavior, but it doesn't seem like that should be necessary.

@alkamo
Copy link
Author

alkamo commented Oct 11, 2023

Looking into this a little further, this appears to have been caused by #2481. #2499 was intended to correct it, but I'm still seeing this specific issue with 3.41.3.

@alkamo
Copy link
Author

alkamo commented Oct 11, 2023

Opinion

I don't really thing that dashes should be allowed in bind variable names. Periods I get, but dashes add a lot of ambiguity because they are an operator. Should :bind-variable-7 be interpreted as a 1) a variable named "bind-variable-7"; 2) a variable named "bind-variable" minus seven; or 3) a variable named "bind" minus the field named "variable" minus seven?

In my opinion, option 3 is the safest interpretation in SQL.

@alkamo alkamo changed the title Change in Behavior - Bind Variable Detection w/o Space Before Operator Change in Behavior - Bind Variable Detection w/o Space Before Minus Oct 11, 2023
@hgschmie hgschmie self-assigned this Oct 11, 2023
@stevenschlansker
Copy link
Member

I agree that allowing - in variable names adds lots of parsing ambiguity. It even happens without numbers at all: is a-b a var named a-b or is it a - b

hgschmie added a commit to hgschmie/jdbi that referenced this issue Oct 24, 2023
This hopefully addresses all the issues raised in jdbi#2481, jdbi#2499 and finally jdbi#2510.

The case of the trailing '-' is not solvable without a trailing
delimiter. There is not enough information to decide whether
`:foo-bar` is "identifier 'foo-bar'" or "identifier 'foo' minus bar".

This PR drops the '-' again as a valid character in a parameter or
binding (sorry if you added it; but then again this was only added in
3.41.1). The dot (`.`) is still supported as a valid character in a
binding or parameter name. It always was for the parameters but not
for a binding (this caused the original jdbi#2481 issue).
@hgschmie
Copy link
Contributor

This should be fixed with #2520 (and subsequently with the next release)

hgschmie added a commit to hgschmie/jdbi that referenced this issue Nov 19, 2023
This hopefully addresses all the issues raised in jdbi#2481, jdbi#2499 and finally jdbi#2510.

The case of the trailing '-' is not solvable without a trailing
delimiter. There is not enough information to decide whether
`:foo-bar` is "identifier 'foo-bar'" or "identifier 'foo' minus bar".

This PR drops the '-' again as a valid character in a parameter or
binding (sorry if you added it; but then again this was only added in
3.41.1). The dot (`.`) is still supported as a valid character in a
binding or parameter name. It always was for the parameters but not
for a binding (this caused the original jdbi#2481 issue).
@hgschmie
Copy link
Contributor

This should be fixed with 3.42.0.

@hgschmie
Copy link
Contributor

closing as fixed (and finally laid to rest in the upcoming 3.43.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants