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

  • From: Tobias Rapp <t.rapp@xxxxxxxxxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Fri, 24 Apr 2015 08:43:44 +0200

Thanks Ralf for the detailed answer. I previously only found the text in
https://www.sqlite.org/lang_expr.html#litvalue :

<quote>
A string constant is formed by enclosing the string in single quotes ('). A single quote within the string can be encoded by putting two single quotes in a row - as in Pascal. C-style escapes using the backslash character are not supported because they are not standard SQL.
</quote>

Now I understand the difference between string and keyword quoting.

Best regards,
Tobias


On 23.04.2015 23:40, Delphi Inspiration wrote:

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: