[CONJ-705] QueryRunner的update方法执行/**/时会报错 Created: 2019-05-30 Updated: 2021-11-08 Resolved: 2020-06-22 |
|
| Status: | Closed |
| Project: | MariaDB Connector/J |
| Component/s: | metadata |
| Affects Version/s: | 2.4.0 |
| Fix Version/s: | 2.6.1, 3.0.3 |
| Type: | Bug | Priority: | Major |
| Reporter: | Xu Shilin | Assignee: | Diego Dupin |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
jdk1.8 |
||
| Description |
|
用mysql的connector/j 不会报错 |
| Comments |
| Comment by Diego Dupin [ 2019-06-03 ] | |||||||||||||||||||||||||||||||||||
|
Could you please elaborate on the issue ? | |||||||||||||||||||||||||||||||||||
| Comment by Diego Dupin [ 2019-09-13 ] | |||||||||||||||||||||||||||||||||||
|
Closing since no answer | |||||||||||||||||||||||||||||||||||
| Comment by Vassilis Virvilis [ 2020-05-14 ] | |||||||||||||||||||||||||||||||||||
|
Hi, I can verify that and answer questions or try builds if required. I can probably try patches also. The issue is also discussed in https://issues.apache.org/jira/browse/DBUTILS-117 How the problem manifests itself: Apache Commons DbUtils are crashing when they try to execute a prepared statement with no parameters. For me it was just a "LOAD DATA INFILE '/tmp/data.txt' INTO TABLE mytable"; The problem lies in (I have version 2.6.0 of the mariadb java connector) in org.mariadb.jdbc.MariaDbParameterMetaData around line 77. When the AbstractQueryRunner:334 (of DbUtils) calls fillStatement() it tries to check the numbers of parameters. DbUtils have some defensive code there. They check if getParameterMetaData() throws SQLFeatureNotSupportedException or returns null. MariaDB does not throw SQLFeatureNotSupportedException and does not return null. The jdbc implementations is considered okish and DbUtils tries to getParameterCount() which calls MariaDbParameterMetaData:77 Now the MariaDB connector calls checkAvailable() if parametersInformation == null then throws {{ throw new SQLException("Parameter metadata not available for these statement", "S1C00");}} What it has to be done (according to my opinion)getParameterCount() should return 0 and do not throw exception. I can try cook a patch if you agree with this behavior. I am sure however that there is more to this than my naive approach but MySQL implementation seems to protect it. Not quite sure though about that. Probably the jdbc standard will have an opinion of its own on this. Please consider altering this behaviour though. It hurts portability from MySQL. WorkaroundInstantiate the QueryRunner with a boolean set to true which sets the internal variable pmdKnownBroken in order to handle substandard jdbc drivers. | |||||||||||||||||||||||||||||||||||
| Comment by Diego Dupin [ 2020-05-14 ] | |||||||||||||||||||||||||||||||||||
|
For client (default) prepare statement, metadata are done by executing a "PREPARE" command and using the resulting metadata. Driver return a metadata object without any information, so that will throw an exception for all methods.
Driver has to return null in this specific case. | |||||||||||||||||||||||||||||||||||
| Comment by Vassilis Virvilis [ 2020-05-15 ] | |||||||||||||||||||||||||||||||||||
|
Hi thanks for answering and for the link. I think there is a misunderstanding though. You are speaking about ResultSetMetaData object while my issue is in the implementation of ParameterMetaData (MariaDbParameterMetaData). Here is the code from Apache Commons DbUtils AbstractQueryRunner.java It can be found here: https://github.com/apache/commons-dbutils/blob/master/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java#L278
https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/java/sql/ParameterMetaData.html#getParameterCount() does not indicate that it should throw an exception if there are no parameters. If there are no parameters the number of parameters returned should be 0 IMHO (implied not explicitely stated). In the same vain the query of the original reporter '/**/' is a valid SQL query with zero paramters. Why it should throw an exception when we ask the parameter count? This works in MySQL and apparently in other JDBC drivers so I genuinely believe it is an implementation bug in MariaDB JDBC connector Here is the patch I propose:
I am willing to formally submit a patch and create a test case if you agree with it. Thanks in advance | |||||||||||||||||||||||||||||||||||
| Comment by Diego Dupin [ 2020-05-15 ] | |||||||||||||||||||||||||||||||||||
|
allright, i've added commit https://github.com/mariadb-corporation/mariadb-connector-j/commit/12af84fa31c2fc47280877b18a083ebe1e7be0db that at least permits parameterCount() for parameterMetadata (that's the only known data when query cannot be prepared). You can test result using snapshot version:
could you confirm that solve this issue ? | |||||||||||||||||||||||||||||||||||
| Comment by Vassilis Virvilis [ 2020-05-15 ] | |||||||||||||||||||||||||||||||||||
|
Diego, I confirm that it works. I also saw that you added a test case too. That will prevent it from breaking in the feature. Super cool !!! Thanks a lot. I really appreciate it. |