Why "UTF-8" and not 'UTF-8' ?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Why "UTF-8" and not 'UTF-8' ?

Simon Slavin-3
The documentation for PRAGMA includes this command:

PRAGMA encoding = "UTF-8";

Why is it "UTF-8" and not 'UTF-8' ?  Why is it double quotes rather than a normally-delimited string ?  Should either of these work ?

PRAGMA encoding = UTF-8;PRAGMA encoding = 'UTF-8'
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Why "UTF-8" and not 'UTF-8' ?

J. King-3
On September 23, 2019 1:27:54 p.m. EDT, Simon Slavin <[hidden email]> wrote:

>The documentation for PRAGMA includes this command:
>
>PRAGMA encoding = "UTF-8";
>
>Why is it "UTF-8" and not 'UTF-8' ?  Why is it double quotes rather
>than a normally-delimited string ?  Should either of these work ?
>
>PRAGMA encoding = UTF-8;PRAGMA encoding = 'UTF-8'
>_______________________________________________
>sqlite-users mailing list
>[hidden email]
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

It's worth noting, too, that barring changed  compile-time settings, the default encoding is UTF-8 to begin with.
--
J. King
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Why "UTF-8" and not 'UTF-8' ?

Keith Medcalf
In reply to this post by Simon Slavin-3

It should be

pragma encoding = 'UTF-8';

UTF-8 is a character string, not an identifier.  And yes, due to a longstanding bug in SQLite3 you can use identifier quotes around strings -- if the identifier quotes do not resolve to an identifier they fallback to a string.  

You can now "turn this bug off" but the turning off does not seem to affect usage in most DDL, which will still carry on accepting double-quoted strings in most places.

>-----Original Message-----
>From: sqlite-users <[hidden email]> On
>Behalf Of Simon Slavin
>Sent: Monday, 23 September, 2019 11:28
>To: SQLite mailing list <[hidden email]>
>Subject: [sqlite] Why "UTF-8" and not 'UTF-8' ?
>
>The documentation for PRAGMA includes this command:
>
>PRAGMA encoding = "UTF-8";
>
>Why is it "UTF-8" and not 'UTF-8' ?  Why is it double quotes rather than
>a normally-delimited string ?  Should either of these work ?
>
>PRAGMA encoding = UTF-8;PRAGMA encoding = 'UTF-8'
>_______________________________________________
>sqlite-users mailing list
>[hidden email]
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Why "UTF-8" and not 'UTF-8' ?

Richard Hipp-3
On 9/23/19, Keith Medcalf <[hidden email]> wrote:
>
> due to a
> longstanding bug in SQLite3 you can use identifier quotes around strings

I don't think "bug" is quite the right word here, as the behavior was
deliberate.  The use of double-quotes for strings was put in in a
(perhaps misguided) attempt to be more compatible with MySQL 3.x,
which was the predominant SQL engine when SQLite was first being
designed.  Maybe "mis-feature" would be a better word.

In any event, you are correct that the behavior can now be disabled
and should be for new applications.  But we need to leave it turned on
by default for legacy.


--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Why "UTF-8" and not 'UTF-8' ?

Simon Slavin-3
On 23 Sep 2019, at 9:09pm, Richard Hipp <[hidden email]> wrote:

> In any event, you are correct that the behavior can now be disabled
> and should be for new applications.

Can I get an answer to my 'Subject' header ?

Is the parameter to the PRAGMA a string parameter ?  If so, can the documentation be changed to use apostrophes as delimiters ?  Using double quotes in the documentation seems really weird.

If, on the other hand, the PRAMGA is actually looking for double-quotes after the equals sign, is this for a reason ?
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Why "UTF-8" and not 'UTF-8' ?

Keith Medcalf
In reply to this post by Richard Hipp-3

On Monday, 23 September, 2019 14:09, Richard Hipp <[hidden email]>:

>In any event, you are correct that the behavior can now be disabled
>and should be for new applications.  But we need to leave it turned on
>by default for legacy.

Nevertheless, the point is that even if you purportedly turn the behaviour off, it is not turned off:

That is, if you compile with DQS set to 0, the statement

pragma encoding = "UTF-8"

is still accepted without error.

SQLite version 3.30.0 2019-09-23 19:37:40
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> pragma encoding="UTF-8";
sqlite> .dbconfig
       enable_fkey on
    enable_trigger on
       enable_view on
    fts3_tokenizer off
    load_extension on
  no_ckpt_on_close off
       enable_qpsg off
       trigger_eqp off
    reset_database off
         defensive off
   writable_schema off
legacy_alter_table off
           dqs_dml off
           dqs_ddl off

If fact the dqs_ddl setting seems not to do anything at all.  dqs_dml seems to work however.

sqlite> create table x (x default "DFLT");
sqlite> insert into x default values;
sqlite> select * from x;
DFLT
sqlite> insert into x values ("DFLT");
Error: no such column: DFLT
sqlite>

Now, if you created a legacy database with dqs_ddl turned on and opened it in a version of SQLite3 that has dqs_ddl turned off, should parsing a currently malformed schema produce an error?  However, the create with incorrect quotes should be an error if at the time it is made dqs_ddl is turned off.

sqlite> create view v as select "TEST";
sqlite> select * from v;
Error: no such column: TEST
sqlite>

Should this not toss an error when the ddl creating the view is parsed?  Hard to say because a view is merely a stored statement and I don't think it is parsed (as in prepared) at create view time, however it does definitely throw an error when executed (prepared), in accordance with the dqs_dml setting.

Does the dqs_ddl setting need to be passed to something else, like the parser generator?





_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Why "UTF-8" and not 'UTF-8' ?

Darren Duncan
In reply to this post by Simon Slavin-3
On 2019-09-23 1:22 p.m., Simon Slavin wrote:
> Can I get an answer to my 'Subject' header ?
>
> Is the parameter to the PRAGMA a string parameter ?  If so, can the documentation be changed to use apostrophes as delimiters ?  Using double quotes in the documentation seems really weird.
>
> If, on the other hand, the PRAMGA is actually looking for double-quotes after the equals sign, is this for a reason ?

I agree.  All documentation should show the more standard/correct single quotes
for strings when that works, and only show double quotes when those are
required.  This would help avoid a lot of confusion. -- Darren Duncan
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users