[yunqa.de] Re: SQLite - String quote character

  • From: Delphi Inspiration <delphi@xxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Thu, 23 Apr 2015 23:40:58 +0200

The DISQLite3 documentation lists the four ways of quoting keywords in SQLite3 as follows:

<quote>

* 'keyword' - A keyword in single quotes is a string literal.

* "keyword" - A keyword in double-quotes is an identifier.

* [keyword] - A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility.

* `keyword` - A keyword enclosed in grave accents (ASCII code 96) is an identifier. This is not standard SQL. This quoting mechanism is used by MySQL and is included in SQLite for compatibility.

For resilience when confronted with historical SQL statements, SQLite will sometimes bend the quoting rules above:

* If a keyword in single quotes (ex: 'key' or 'glob') is used in a context where an identifier is allowed but where a string literal is not allowed, then the token is understood to be an identifier instead of a string literal.

* If a keyword in double quotes (ex: "key" or "glob") is used in a context where it cannot be resolved to an identifier but where a string literal is allowed, then the token is understood to be a string literal instead of an identifier.

</quote>

I hope this answers your question.

Ralf

On 23.04.2015 17:07, Tobias Rapp wrote:

I noticed that the SQL as understood by SQLite seems to support both
single quote (') and double quote (") character for string literals:

SELECT 'hello' a, "world" b

In the documentation it seems only the SQL standard single quote is
mentioned. Using the double quote makes it more easy when embedding
string literals into Delphi strings. My question now is if using double
quotes is only considered some legacy/deprecated/compatibility thing in
SQLite or if it is actually considered a feature?
_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
//www.freelists.org/list/yunqa



Other related posts: