Bug #119718 executeQuery SELECT fails if the tablename contains substring INTO

Submitted: 19 Jan 9:11 Modified: 3 Feb 11:57
Reporter: Mark James Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:9.5.0 OS:Any
Assigned to: CPU Architecture:Any

[19 Jan 9:11] Mark James
Description:
This is a bug in QueryInfo.java in mysql-connector-j: executeQuery on a java.sql.Statement will fail with the below exception because the isResultSetProducingQuery check has a bug and returns false for “SELECT * FROM PrintOptions” 

java.sql.SQLException: Statement.executeQuery() cannot issue statements that do not produce result sets.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:121)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:81)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:55)
at com.mysql.cj.jdbc.StatementImpl.executeQuery(StatementImpl.java:1238)

The bug is in QueryInfo:containsIntoClause which is just using com.mysql.cj.util.StringUtils.indexOfIgnoreCase to check for “INTO” in the select statement and returning true for any table name that has INTO as a substring.
  
containsIntoClause:892, QueryInfo (com.mysql.cj)
getQueryReturnType:855, QueryInfo (com.mysql.cj)
isResultSetProducingQuery:357, StatementImpl (com.mysql.cj.jdbc)
executeQuery:1237, StatementImpl (com.mysql.cj.jdbc)

How to repeat:
@Test
public void selectIntoBugTest() {
	ResultSet rs = null;
	try {
		Connection con = DriverManager.getConnection("jdbc:mysql://localhost/unittest?user=unittest&password=PASSWORD");
		Statement s = con.createStatement();
		s.execute("DROP TABLE IF EXISTS PrintOptions");
		s.execute("CREATE TABLE PrintOptions (id INT)");
		rs = s.executeQuery("SELECT * FROM PrintOptions");
	}catch(Exception x) {
		x.printStackTrace(System.err);
	}
	assertNotNull(rs);
}

Suggested fix:
Change the indexOfIgnoreCase to use a regex that will include a check for white-space/bracket/@ (and possibly others) around the INTO
[3 Feb 11:57] Filipe Silva
Thank you for your interest in MySQL Connector/J and for taking the time to report this issue. 

This is a duplicate of Bug#119245, which has been addressed and fixed in MySQL Connector/J 9.6.0. 

Thank you again for your feedback.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.059 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.