Bug 278052 - Kexi allows creation of table with reserved words as field names
Summary: Kexi allows creation of table with reserved words as field names
Status: CLOSED FIXED
Alias: None
Product: KEXI
Classification: Applications
Component: Tables (show other bugs)
Version: 2.4 beta1 (Calligra 2.4 beta1)
Platform: Compiled Sources Linux
: LO wishlist
Target Milestone: ---
Assignee: Jarosław Staniek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-18 22:22 UTC by Dimitrios T Tanis
Modified: 2012-09-26 20:53 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 2.4 (Calligra 2.4)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitrios T Tanis 2011-07-18 22:22:48 UTC
Version:           2.4 beta1 (Calligra 2.4 beta1) (using KDE 4.6.0) 
OS:                Linux

This bug was found while trying to import an ODS with a column name titled "desc". It seems "desc" is a reserved word, however there is no check, thus allowing the creation of the table.
However trying to base a report on that table, displays an empty report.

Reproducible: Always

Steps to Reproduce:
1) Create a table with a field named "desc"
OR
2) Try to import one from CSV with a field named "desc"
OR 
3) Try to import an ODS  with a field named "desc"

Actual Results:  
In cases 1, 2 the table is created successfully and can be browsed
Trying to base a report on either of these tables, results an empty report.
In case 3 Kexi crashes.


Expected Results:  
User should be warned that "desc" cannot be used as a field name as it is a reserved keyword.

This bug should be fixed, as "desc" if fairly common in field names and using it could cause trouble.

Thanks to Adam for pinpointing it when importing.
Comment 1 Dimitrios T Tanis 2011-07-26 18:47:57 UTC
The same happens with a column named "temp". WHOOPS, I found another reserved word?

We should really to something about this, for starters why not publish somewhere a list of reserved words? We can worry fixing this later.
Comment 2 Jarosław Staniek 2011-07-26 19:53:22 UTC
I can see another solution that we more or less have in initial stage in Kexi(DB): enclosing names in " " before sending them to database backends, including SQLite.

SELECT * FROM "FROM"; could definitely work.

Remaining question is: what if user writes SELECT * FROM FROM; in the SQL view. She's power user so she should consult the documentation for the list of reserved words (and Kexi can warn about this quite well).

So for the latter case I agree that we can and should document reserved words for any backend in the documentation. Are you interested in helping with this? (I can guide you).
Well, we can even have reserved_words property of KexiDB/Predicate driver that returns the list...
Comment 3 Dimitrios T Tanis 2011-07-28 17:45:00 UTC
I strongly think we should abide by the standards. Having single or double quotes in field names could be even more confusing as quotes are used to pass text values to the Select statement.

So I lean towards the reserved words document (in the web, Documentation and Kexi)
I will be glad to do it (with proper guidance). We should talk the details at the IRC.
Comment 4 Jarosław Staniek 2012-03-07 23:12:59 UTC
Using quotes in identifiers is a common practice in databases. Without this ability we would exclude too many common words what would be unexpected to users working with KexiSQL. We could auto-replace  desc with _desc but replacing and requiring to replace with "desc" in KexiSQL (or [desc]?) would be a lot better - natural.

Kexi handles the case in tables, queries and forms.
A fix for reports is missing.
Comment 5 Jarosław Staniek 2012-03-08 00:25:42 UTC
Git commit 03b862620657fc43c95782a719da9156f313a8cc by Jaroslaw Staniek.
Committed on 08/03/2012 at 01:25.
Pushed by staniek into branch 'master'.

Reports: Fix crash in assigning data source that uses reserved words

Reports
*Fix crash in assigning data source that uses reserved words as field names
**Tables/queries with reserved words still do not work in reports though

M  +4    -0    kexi/doc/dev/CHANGELOG-Kexi-js
M  +3    -1    kexi/plugins/reports/kexidbreportdata.cpp

http://commits.kde.org/calligra/03b862620657fc43c95782a719da9156f313a8cc
Comment 6 Jarosław Staniek 2012-03-08 00:27:54 UTC
Git commit 5458aeea78ab67e370b41ea9d5b2f3179ea869f6 by Jaroslaw Staniek.
Committed on 08/03/2012 at 01:25.
Pushed by staniek into branch 'calligra/2.4'.

Reports: Fix crash in assigning data source that uses reserved words

Reports
*Fix crash in assigning data source that uses reserved words as field names
**Tables/queries with reserved words still do not work in reports though

Reviewed.

M  +4    -0    kexi/doc/dev/CHANGELOG-Kexi-js
M  +3    -1    kexi/plugins/reports/kexidbreportdata.cpp

http://commits.kde.org/calligra/5458aeea78ab67e370b41ea9d5b2f3179ea869f6
Comment 7 Jarosław Staniek 2012-03-08 00:30:06 UTC
Changing to a wish