Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-29687

ODBC tables do not quote identifier names correctly

Details

    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)
      
      

      Attachments

        Issue Links

          Activity

            anel Anel Husakovic added a comment - - edited

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

            anel Anel Husakovic added a comment - - edited markus makela How do you do that on psql side https://dbfiddle.uk/fPwrcY_7 ?
            markus makela markus makela added a comment - - edited

            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.

            markus makela markus makela added a comment - - edited 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.

            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.

            anel Anel Husakovic added a comment - 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.

            TheLinuxJedi please review PR 2295

            anel Anel Husakovic added a comment - TheLinuxJedi please review PR 2295

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

            TheLinuxJedi Andrew Hutchings (Inactive) added a comment - Reopening this one as I get this mtr failure now in 10.3. It is a blocker to getting anything else fixed.

            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

            TheLinuxJedi Andrew Hutchings (Inactive) added a comment - 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
            anel Anel Husakovic added a comment - - edited

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

            anel Anel Husakovic added a comment - - edited PR 2325 is fixing ASAN bug caused by MDEV-29687 fix.

            People

              anel Anel Husakovic
              markus makela markus makela
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.