[MDEV-29687] ODBC tables do not quote identifier names correctly Created: 2022-10-03  Updated: 2022-11-08  Resolved: 2022-11-08

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - Connect
Affects Version/s: 10.3
Fix Version/s: 10.3.37

Type: Bug Priority: Critical
Reporter: markus makela Assignee: Anel Husakovic
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-29397 Connect engine ODBC UPDATE triggers e... Closed

 Description   

In Postgres:

maxuser=# create table space_in_name("something with space" int);
CREATE TABLE
maxuser=# insert into space_in_name values(1),(2),(3);
INSERT 0 3

In MariaDB:

MariaDB [test]> CREATE TABLE pg_in_maria ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='Driver=PostgreSQL Unicode;UID=maxuser;PWD=maxpwd;SERVER=127.0.0.1;PORT=5432' tabname='public.space_in_name';
Query OK, 0 rows affected (0.038 sec)
 
MariaDB [test]> select * from pg_in_maria;
ERROR 1296 (HY000): Got error 174 'SQLExecDirect: ERROR: syntax error at or near "with";
Error while executing the query' from CONNECT

Looking at the network capture, we can see that the identifiers aren't quoted correctly.

T 127.0.0.1:40322 -> 127.0.0.1:5432 [AP] #14
  51 00 00 00 3a 53 45 4c    45 43 54 20 73 6f 6d 65    Q...:SELECT some
  74 68 69 6e 67 20 77 69    74 68 20 73 70 61 63 65    thing with space
  20 46 52 4f 4d 20 70 75    62 6c 69 63 2e 73 70 61     FROM public.spa
  63 65 5f 69 6e 5f 6e 61    6d 65 00                   ce_in_name.    

A workaround is to use SrcDef to define the SQL statement:

MariaDB [test]> CREATE TABLE pg_in_maria ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='Driver=PostgreSQL Unicode;UID=maxuser;PWD=maxpwd;SERVER=127.0.0.1;PORT=5432' SrcDef='SELECT * FROM public.space_in_name';
Query OK, 0 rows affected (0.035 sec)
 
MariaDB [test]> SELECT * FROM pg_in_maria;
+----------------------+
| something with space |
+----------------------+
|                    1 |
|                    2 |
|                    3 |
+----------------------+
3 rows in set (0.009 sec)



 Comments   
Comment by Anel Husakovic [ 2022-10-09 ]

markus makela
How do you do that on psql side https://dbfiddle.uk/fPwrcY_7 ?

Comment by markus makela [ 2022-10-09 ]

The same as MariaDB in ANSI mode: SELECT "my space column" FROM "schema1"."space_in_column_name"

https://dbfiddle.uk/yq5vmelP

I believe this is standard ANSI SQL: single quotes are for strings, double quotes are for identifiers. Backticks are a MySQL/MariaDB extension.

Comment by Anel Husakovic [ 2022-10-10 ]

Connect SE has a table option quoted for ODBC type (see table options) that you should give to create statement, problem here is that it fails even with that. THere is also qchar option but as tested I noted that psqlodbca.so will update it for default double quotes.
I have a working patch, need just more testing, will create PR soon.

Comment by Anel Husakovic [ 2022-10-20 ]

TheLinuxJedi please review PR 2295

Comment by Andrew Hutchings [ 2022-11-03 ]

Reopening this one as I get this mtr failure now in 10.3. It is a blocker to getting anything else fixed.

Comment by Andrew Hutchings [ 2022-11-07 ]

Test case failure was due to ASAN using scrambled memory to find an off-by-one bug and also an off-by-one malloc bug. These are fixed in https://github.com/MariaDB/server/pull/2325

Comment by Anel Husakovic [ 2022-11-08 ]

PR 2325 is fixing ASAN bug caused by MDEV-29687 fix.

Generated at Thu Feb 08 10:10:31 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.