|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70090 SQLite table with - in the name causes error when query
Submitted: 2015-07-17 06:49 UTC Modified: 2015-07-17 07:21 UTC
From: david dot vantyghem at free dot fr Assigned:
Status: Not a bug Package: SQLite related
PHP Version: 5.5Git-2015-07-17 (Git) OS: Linux Mint MATE 17.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: david dot vantyghem at free dot fr
New email:
PHP Version: OS:


 [2015-07-17 06:49 UTC] david dot vantyghem at free dot fr
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 = 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");


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-17 07:03 UTC]
-Status: Open +Status: Not a bug
 [2015-07-17 07:03 UTC]

I couldn't find good documents, but ANSI SQL needs "identifier-name" to make sure identifier is treated as identifier.
 [2015-07-17 07:07 UTC] 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:21 UTC]
Yes, you need to quote the identifier because you use special characters in your identifier.
 [2015-08-05 07:58 UTC] a at b dot c dot de
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."

The keywords page already linked mentions that single quotes should not be used for the purpose.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 14 06:01:33 2024 UTC