-
-
Notifications
You must be signed in to change notification settings - Fork 138
r2dbc named parameters binding #331
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
Comments
Thank you for reporting an issue. See the wiki for documentation and gitter for questions. |
Hi, |
Hi oshai! 0 is the binding position. The fix is to force unrwap the Parameter object into the actual scalar (string/int/long etc) in the org.springframework.r2dbc.core.DefaultDatabaseClient, but of course that's not desirable. Support for this Parameter type would be great. Another question, how can i map the returned (OUT) values from a mysql stored procedure? Many thanks, |
If you can please add a code snippet if the workaround, that would be great. I will take a look how that can be supported. |
About the stored procedure. There are some tests here: https://github.com/jasync-sql/jasync-sql/blob/6de042b540b65ea76dbc9dd96e31657969ec322a/mysql-async/src/test/java/com/github/jasync/sql/db/mysql/StoredProceduresSpec.kt |
I'm not sure, but after a little bit of debugging, I think the changes to the spring r2dbc framework which aligns r2dbc for 0.9 commit causes the error. See here for code public void bindTo(BindTarget target) {
for (String namedParameter : this.parameterSource.getParameterNames()) {
Object value = this.parameterSource.getValue(namedParameter);
if (value == null) {
bindNull(target, namedParameter, this.parameterSource.getType(namedParameter));
}
else {
bind(target, namedParameter, value);
}
}
}
// changed after 0.9 update
public void bindTo(BindTarget target) {
for (String namedParameter : this.parameterSource.getParameterNames()) {
Parameter parameter = this.parameterSource.getValue(namedParameter);
if (parameter.getValue() == null) {
bindNull(target, namedParameter, parameter);
}
else {
bind(target, namedParameter, parameter);
}
}
} Before the 0.9 update, the parameters were mapped as original values(scalar) by the spring r2dbc framework. However, after the update, the values are wrapped in Parameters. Don't know if it's the right place, but could check if the values coming in from r2dbc as Parameters in JasyncStatement
|
Hi, iiuc this is an issue with prepared statements? Also I didn't figure out if you suggested a fix, but if so, a PR is welcome! |
Is this issues still relevant? Can you please check it with jasync 2.1.11? |
Yes, It's still there. An operation is not implemented: couldn't find mapping for class io.r2dbc.spi.Parameters$InParameter Tested with You can simply reproduce with Spring DatabaseClient where you use .bind method! |
I created a test here: #360 But didn't manage to reproduce. |
Hey, try to use a named parameter.
|
Thanks, I added a test that reproduces it with the suggestion. The exception stacktrace is different in that case:
I am checking what can be done for that. I am also trying to understand if this is something used directly or by other frameworks like spring data etc'. |
It looks like mysql don't have native support for named params: https://dev.mysql.com/doc/refman/8.0/en/sql-prepared-statements.html OTOH spring data do support that: https://docs.spring.io/spring-data/r2dbc/docs/current/reference/html/#r2dbc.repositories.queries So to bridge that it's possible to implement it similar to here: https://github.com/mirromutth/r2dbc-mysql/blob/main/src/main/java/dev/miku/r2dbc/mysql/Query.java (this is an older version where the param started with There are two downsides I see for doing it:
But I don't see other alternatives. Suggestions are welcome. |
For reference this is r2dbc data change: spring-projects/spring-data-r2dbc#47 @mp911de - any thoughts on this? is parsing on the driver (client) required for the |
Named parameters work with Spring boot 2.7 and jasync-r2dbc-mysql (basically with spring-r2dbc 5) |
I created a sample application to reproduce the main error |
Thanks for the reproduction! I understand the issue now. When setting logs to trace I see the following:
I will create a fix for it soon. |
That's awesome, looking forward to it. |
Also throw unsupported on named binding. See #331
Also throw unsupported on named binding. See #331
I created version 2.1.13 with the fix. Once it's available you're welcome to test it. I want to also create a test that reproduces it before closing the issue. |
In the test application that I created for you the indexed parameter was also not working, so with 2.1.13 , I would think using a named parameter should throw an exception and indexed parameter should work! I will test it once it's available |
I think that also the named parameter will work. I think spring is doing the name binding before sending the query to jasync (that's what I saw on logs). |
It worked with both named and indexed parameters, thank you so much! |
Adding test in #364. |
Fixed in 2.1.13. |
This library is using name binding. I've been using this library with jasync The library do provide a way to customize this but I'm wondering why are we not supporting this at all. Seems like a norm in other library |
Can you provide a test case for what you're seeing (with latest jasync version)? please open another issue with it. |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
Using the latest Spring Boot 3 RC2 and doing a simple query generates the following:
The calling code is like this:
The text was updated successfully, but these errors were encountered: