Bug #70090 [Com]: SQLite table with - in the name causes error when query
| From: | a at b dot c dot de | Date: | Wed, 05 Aug 2015 07:58:38 +0000 |
| Subject: | Bug #70090 [Com]: SQLite table with - in the name causes error when query | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-194961@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70090&edit=1
ID: 70090
Comment by: a at b dot c dot de
Reported by: david dot vantyghem at free dot fr
Summary: SQLite table with - in the name causes error when
query
Status: Not a bug
Type: Bug
Package: SQLite related
Operating System: Linux Mint MATE 17.2
PHP Version: 5.5Git-2015-07-17 (Git)
Block user comment: N
Private report: N
New Comment:
The SQLite site is pretty weak on the subject of what is an identifier, but there is a FAQ entry
that mentions the double-quotes thing wrt special characters in passing:
"SQL uses double-quotes around identifiers (column or table names) that contains special
characters or which are keywords. So double-quotes are a way of escaping identifier names."
https://www.sqlite.org/faq.html#q24
The keywords page already linked mentions that single quotes should not be used for the purpose.
Previous Comments:
------------------------------------------------------------------------
[2015-07-17 07:21:20] mike@php.net
Yes, you need to quote the identifier because you use special characters in your identifier.
------------------------------------------------------------------------
[2015-07-17 07:07:04] david dot vantyghem at free dot fr
In this case, I don't think it's a problem of identifier or not. If I use a table without
-, it works with and without ' '.
If the name of the table contains -, it works only with ' '.
------------------------------------------------------------------------
[2015-07-17 07:03:07] yohgaki@php.net
https://www.sqlite.org/lang_keywords.html
I couldn't find good documents, but ANSI SQL needs "identifier-name" to make sure
identifier is treated as identifier.
------------------------------------------------------------------------
[2015-07-17 06:49:34] david dot vantyghem at free dot fr
Description:
------------
When a SQLite table contains - in its name, query sometimes show an error. The error disappears whit
adding ' ' at each side of the table name.
Test script:
---------------
With error :
$database_handle->query("SELECT * FROM software INNER JOIN software-compilations ON
software-compilations.compilation = ".$compilation_key." AND software.key =
software-compilations.software ORDER BY name");
Without error :
$database_handle->query("SELECT * FROM software INNER JOIN 'software-compilations'
ON 'software-compilations'.compilation = ".$compilation_key." AND software.key =
'software-compilations'.software ORDER BY name");
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70090&edit=1