Very interesting...
When I use the mysql command line tool and issue the following command it WORKS! (and shows the correct result on query)
UPDATE Azure_all_types SET myvarchar = 'Bob''s' WHERE id = 2;
|
But when I change it to:
UPDATE Azure_all_types SET myvarchar = 'Bob\'s' WHERE id = 2;
|
it fails with the same error:
ERROR 1296 (HY000): Got error 122 'ExecuteUpdate: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax n
|
ear 's'. n=-1' from CONNECT
|
So clearly the MariaDB JDBC driver is escaping single quotes like \' before sending it to the server.... which is valid for MariaDB but not optimal when sending to a remote server via CONNECT.
Maybe the solution is to change our code base so that we don't use prepared statements, or maybe this is or can be fixed in a MariaDB JDBC driver update? Note this also explains some of the other strange behavior such as with double quotes where a \ is added.
For example updating a record (with a prepared statement) that has a " (double quote char) in it causes it to save as \"
From the mysql command line tool, the following works and gives the correct result when you select it:
UPDATE Azure_all_types SET myvarchar = 'Bob"s' WHERE id = 2;
|
but the prepared statement adds a backslash before the double quote:
UPDATE Azure_all_types SET myvarchar = 'Bob\"s' WHERE id = 2;
which stores it in the remote database as \" !!!
This all makes sense now. Also \n inserts on the remote system as a \ and n character - i.e. not newline.
I don't see the need to escape ANY character in a single quoted string EXCEPT the single quote char itself? Do you agree?
Also, I don't see how CONNECT can tell if \" really means backslash quote or is an escaped double quote.
So two possible fixes I can see:
1) we change our code to eliminate prepared statements and only escape ' char as '' and leave all other characters as is
2) the MariaDB JDBC driver is changed so that it only escapes ' to double single quote if ANSI_QUOTES is turned on (is this a safe change to make??)
You did not tell me what command you used. Normally CONNECT is not using prepared statements.
How did you make the use of prepared statement?