Bug #12753 Value of URL parameter is cut after '='
Submitted: 23 Aug 2005 11:15 Modified: 17 Oct 2005 19:43
Reporter: Igor Bukanov Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:3.1.10, 3.2.0 Alpha OS:Windows (Windows, Linux)
Assigned to: Mark Matthews CPU Architecture:Any

[23 Aug 2005 11:15] Igor Bukanov
Description:
The URL parameter parser for JConnector does not allow to include '=' in the value of URL parameter. Effectively the value is cut after '='. For example, when I tried to include sessionVariables in  the connection URL to set sql_mode to ANSI like in:

java.sql.Connection c = new com.mysql.jdbc.NonRegisteringDriver().
    connect("jdbc:mysql://localhost:3306/DB"
            +"?user=USER&password=PASSWORD"
            +"&sessionVariables=sql_mode='ANSI'", null);

I got:

java.sql.SQLException: 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 '' at line 1.

This is caused by the fact that URL parser effectively sets sessionVariables to just "sql_mode" instead of "sessionVariables=sql_mode='ANSI'". That leads later to execution of "SET SESSION sql_mode" instead of "SET SESSION sql_mode='ANSI'" and error generation.

How to repeat:
Compile and run the following Java program:

public class Test
{
    public static void main(String[] args)
        throws Exception
    {
        java.sql.Connection c = new com.mysql.jdbc.NonRegisteringDriver().
            connect("jdbc:mysql://localhost:3306/DB"
                +"?user=USER&password=PASSWORD"
                +"&sessionVariables=sql_mode='ANSI'", null);
    }
}

where DB, USER, PASSWORD should be replaced by the valid values.

Suggested fix:
I use javax.sql.DataSource interface to connect to the database and configure DB properties using Tomcat Context, which allows to pass session properties only through URL. 

Thus as I workaround  I was forced to put explicit 
statement.executeUpdate("SET SESSION sql_mode='ANSI';") 
after connection initialization in the servlet code.
[23 Aug 2005 11:18] Igor Bukanov
Fix: patch against 3.1.10 to include full property value

Attachment: parse_fix.diff (text/x-patch), 1.23 KiB.

[23 Aug 2005 20:02] Mark Matthews
Patch is available at http://lists.mysql.com/internals/28697

The fix for testing should be available in the nightly builds after 00:00 GMT, Aug. 24 at http://downloads.mysql.com/snapshots.php#connector-j