https://bugs.kde.org/show_bug.cgi?id=420599

            Bug ID: 420599
           Summary: KDbNativeStatementBuilder escapes identifiers in a way
                    that KDbParser parses as string literals
           Product: KDb
           Version: 3.2.0
          Platform: Compiled Sources
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: General
          Assignee: stan...@kde.org
          Reporter: jf...@infoblitz.com
  Target Milestone: ---

Created attachment 127876
  --> https://bugs.kde.org/attachment.cgi?id=127876&action=edit
Database with a table using SQL keywords as column names and a query showing
incorrect results

SUMMARY

This is a problem for KEXI when building a query based on a table that has
columns named after SQL reserved keywords (e.g., “group”).


STEPS TO REPRODUCE (IN KEXI 3.2.1)
1. Create a table with a column named “group”; it does not matter its type or
whether its primary key or not.
2. Insert any data that column, but avoid “group” as value.
3. Create a new query with only the “group” column from that table.
4. Switch to SQL view and check that the SQL is indeed correct, with group
double quoted.
5. Switch to data view
6. Switch back to SQL view

OBSERVED RESULT
In data view, all rows have the literal string “group” as value of a column
named “expr1”.

In the second switch to SQL, the query has changed from

  SELECT "group" FROM source

To

  SELECT 'group' AS expr1 FROM source

In the attached database file the SQL query does not changed because it was
saved before switching view, but in data mode it still shows all rows with the
same incorrect literal string.


EXPECTED RESULT
In data view, the column should be named “group” and all its values should be
the same as in the source table.

In SQL, the query should still have the “group” column double quoted and
without any alias.


SOFTWARE/OS VERSIONS
Linux/KDE Plasma: openSUSE 15.1
KDE Plasma Version: N/A
KDE Frameworks Version: 5.69.0
Qt Version: 5.12.2

ADDITIONAL INFORMATION
This seems to be a side effect of bug #364950 (SQL: Handle escape sequences in
string literals), in where the parser was changed to parse double-quoted
strings as literals in order to recognize escape sequences in them.

As a quick test, i modified KDbSqlScanner.l from

   e_str1  (\\\'|\'\'|[^'])
   e_str2  (\\\"|\"\"|[^"])
   string  (\'{e_str1}*\'|\"{e_str2}*\")

to

   e_str1  (\\\'|\'\'|[^'])
   e_str2  (\\\"|\"\"|[^"])
   string  (\'{e_str1}*\')
   quoted_identifier (\"{e_str2}*\")

plus a new quoted_identifier block, and then KEXI produced the expected result.

I am not sure if this is a but of KDb per se; maybe KEXI is just using the
wrong components to generate the SQL. Any thoughts on this?

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to