[CONJ-93] Connection fails when there is a '-' in the jdbc url Created: 2014-04-16  Updated: 2014-09-17  Resolved: 2014-05-22

Status: Closed
Project: MariaDB Connector/J
Component/s: None
Affects Version/s: 1.1.7
Fix Version/s: 1.1.8

Type: Bug Priority: Critical
Reporter: Régis Caspar Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: None
Environment:

not applicable


Attachments: File patch.diff    
Issue Links:
Relates
relates to CONJ-71 Database isn't auto-selected when con... Closed

 Description   

After an upgrade 1.1.5 > 1.1.7, I can no longer connect to a database with a '-' in it's name.

This may be a regression from CONJ-65

Stacktrace:

Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-something' at line 1
at org.mariadb.jdbc.internal.SQLExceptionMapper.get(SQLExceptionMapper.java:138)
at org.mariadb.jdbc.internal.SQLExceptionMapper.throwException(SQLExceptionMapper.java:106)
at org.mariadb.jdbc.Driver.connect(Driver.java:114)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
... 16 more
Caused by: org.mariadb.jdbc.internal.common.QueryException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-something' at line 1
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.getResult(MySQLProtocol.java:942)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.executeQuery(MySQLProtocol.java:991)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.executeQuery(MySQLProtocol.java:886)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:504)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:673)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.<init>(MySQLProtocol.java:266)
at org.mariadb.jdbc.Driver.connect(Driver.java:110)



 Comments   
Comment by Vladislav Vaintroub [ 2014-04-17 ]

It is not related to CONJ-65. It is related to CONJ-71.

The fix for CONJ-71 always uses "USE database" during connection (I'm not sure it is a good idea, it is an extra query, that is almost always avoidable). database name is passed unquoted.

Comment by Vladislav Vaintroub [ 2014-04-17 ]

I attach a patch for this issue.

It removes original fix for CONJ-71, so now there is no more extraneous "use " for every connection . Instead, ensure that CONNECT_WITH_DB is set for the SSL initialization packet.

This patch also ensures that database name is identifier-quoted if createDB parameter is given in the connection URL, for "create database if not exists"/"use" statements.

Also add/improve relevant test cases.

Comment by Régis Caspar [ 2014-04-17 ]

@Vladislav, thanks for the patch.

(fixed "relates to" link)

Comment by Georg Richter [ 2014-05-22 ]

fixed in rev. 508.
Special thanks to Wlad for his patch!

Generated at Thu Feb 08 03:13:07 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.