SQLite User Forum

£ POUND SIGN (V3.41.2) - U+00A3
Login

£ POUND SIGN (V3.41.2) - U+00A3

(1.2) By Aask (AAsk1902) on 2023-04-11 16:10:56 edited from 1.1 [link] [source]

Windows 11: In Control Panel click Region and select the Administrative tab on the ensuing dialogue; for UK users, the setting Current Language for non-Unicode programs is English (United Kingdom). Click the Change System locale button to reveal that Beta: Use Unicode UTF-8 for worldwide unicode support is switched on (and so without user prompting during Windws Update).

With this setting switched on by default, Windows 11 uses code page 65001. With this code page in use, SQLite3 fails to recognise some (Unicode) characters and reports such errors as I reported here.

For convenience, my session looks as follows:

SQLite version 3.41.2 2023-03-22 11:56:21
Enter ".help" for usage hints.
sqlite> .system chcp
Active code page: 65001
sqlite> create table if not exists tblCurrency as select £10.72 as price;
;
Parse error: near ";": syntax error
  create table if not exists tblCurrency as select ;
                                     error here ---^
sqlite> create table if not exists tblCurrency as select '£10.72' as price;

'  ...> ;
'  ...> ;
'  ...> '
   ...> ;
sqlite> select * from tblCurrency;
'
-

;
;
sqlite> /* when inserting '£10.72' (note - in quotes) what is inserted (after several stray continuation prompts) is unrecognisable. */

If I change the code page to 850 (used by Windows 10 by default) and re-try the same SQL expression in a new CLI session, it works BUT ...

SQLite version 3.41.2 2023-03-22 11:56:21
Enter ".help" for usage hints.
sqlite> .system chcp 850
Active code page: 850
sqlite> create table if not exists tblCurrency as select '£10.72' as price;
sqlite> select * from tblCurrency;
price
------
´┐¢10.72
sqlite> /* note £ has not been written correctly */

  • Why is £ problematic for SQLite?
  • Will SQLite support code page 65001?

(2) By Larry Brasfield (larrybr) on 2023-04-11 17:21:26 in reply to 1.2 [link] [source]

Why is £ problematic for SQLite?

It is not. It is problematic for the program providing a "console" that sqlite3.exe and other console programs are given by the Windows operating system.

Will SQLite support code page 65001?

The sqlite3.exe CLI does not provide a replacement console for any OS.

If you create this text in an editor that can handle UTF-8: SELECT '£10.72'; , write it as a file named 'aask.sql', then run this in a sqlite3.exe session: .once aask.out .read aask.sql , then examine the file 'aask.out' in the same or similarly capable editor, you will find that sqlite3.exe handles your '£' character perfectly.

The reason you see problems when you try pasting or typing it into a console window or try getting it rendered as a glyph on a console window is that the stock Windows console and even its shiny replacement, "Windows Terminal", are stuck with a very outdated way of handling character sets.

There are a great many Windows applications which do not use the outdated Windows console API and will let you use the SQLite library to create, modify and query SQLite3 databases. These generally have no problem with character outside of the 7-bit ASCII set that Windows consoles can handle sensibly.

(3.2) By Aask (AAsk1902) on 2023-04-11 18:37:28 edited from 3.1 in reply to 2 [link] [source]

... you will find that sqlite3.exe handles your '£' character perfectly.

  1. I tried the code snippet; the CLI executes it and the output file contains why I expected (as you suggested).

  2. I tried SELECT '£10.72'; with System.Data.SQLite directly , that is, without writing the SQL statement to a file. I get the expected result.

I am not yet convinced that this is not a problem with the Windows version of SQLite3.EXE.

  • The CLI is UTF-8 compliant: Therefore, I would expect

SELECT '£10.72';

to respond immediately with

'£10.72'
--------
£10.72

Version 3.41.2 does NOT respond immediately and does NOT respond with the expected result.

  • If I write the SQL to a file named '£aask.sql' and then try

.read £aask.sql

I get the same behaviour as with select '£10.72';

(4) By Larry Brasfield (larrybr) on 2023-04-11 19:02:04 in reply to 3.1 [link] [source]

I tried SELECT '£10.72'; with System.Data.SQLite directly ... I get the expected result.

I have no idea what this means. The System.Data.SQLite .Net library does no I/O other than its creation and access of database files. So how did you get your query with that non-7-bit code point into the library API? And how did the result get from the library API to something you could deem "expected"? (I venture that the said input and output data did not pass through the Windows Console API.)

I am not yet convinced that this is not a problem with the Windows version of SQLite3.EXE. ... The CLI is UTF-8 compliant: Therefore, I would expect ...

The CLI deals with UTF-8 on input and output. This why, when those streams come from or are directed to files, the results are unsurprising when the streams are interpreted as UTF-8 character sequences. However, such interpretation is simply not possible when the character data passes through the Windows Console API, and more particularly when it must pass through the ancient "code page" scheme which was Microsoft's early attempt to cater to non-USA customers with software that treats characters as 8-bit values.

[Yet another console interaction gone awry.]

Nothing of that nature is convincing to me. This is because disappointing character handling is completely within my expectation when characters are shoved through a channel which insists "Characters shall have no more than 8 bits."

(8.1) By Aask (AAsk1902) on 2023-04-11 19:53:48 edited from 8.0 in reply to 4 [link] [source]

Nothing of that nature is convincing to me.

From the command prompt, running

sqlite3 d:/sqlite32/db/chinook.db "select '£10.72';" > e:/temp/res.txt

  • responds immediately
  • the expected string £10.72 is written to e:/temp/res.txt and

  • sqlite3.exe terminates gracefully.

Yet the same SQL fails in a CLI session.

(9) By Keith Medcalf (kmedcalf) on 2023-04-11 19:55:02 in reply to 8.0 [link] [source]

Interesting, is it not, that as soon as the Windows Console is involved complaints start rolling in. I wonder if perhaps it is causal?

(12.6) By Aask (AAsk1902) on 2023-04-11 21:39:32 edited from 12.5 in reply to 9 [source]

Interesting, is it not

I am not sure which way you are thinking.

Another way to explain the problem as I see it.

Part 1

From the Windows 11 Command Prompt, this works:

Microsoft Windows [Version 10.0.22621.1413]
(c) Microsoft Corporation. All rights reserved.

C:\>dir e:\temp\*.csx
 Volume in drive E is DATA
 Volume Serial Number is 84B8-2F69

 Directory of e:\temp

04/04/2022  02:47                62 aa.csx
16/02/2022  13:35               288 cs.csx
25/03/2023  12:56                46 cs1.csx
29/04/2022  10:04                64 hw.csx
               4 File(s)            460 bytes

Part 2

This works too (I believe .shell aka .system simply passes what follows .shell or .system to the operating system console (standard input) and reads back via standard output or standard error).

SQLite version 3.41.2 2023-03-22 11:56:21
Enter ".help" for usage hints.
sqlite> .shell dir e:\\temp\\*.csx
 Volume in drive E is DATA
 Volume Serial Number is 84B8-2F69

 Directory of e:\temp

04/04/2022  02:47                62 aa.csx
16/02/2022  13:35               288 cs.csx
25/03/2023  12:56                46 cs1.csx
29/04/2022  10:04                64 hw.csx
               4 File(s)            460 bytes

Both ways return the same results.

Part 3

Now I try using the Windows console for my SQL:

Microsoft Windows [Version 10.0.22621.1413]
(c) Microsoft Corporation. All rights reserved.

C:\>d:\sqlite32\sqlite3.exe ":memory:" "select '£10.72';"
£10.72

I have got the result that I expect.

Part 4

Next, I try the same thing in the CLI by invoking the command with .shell

SQLite version 3.41.2 2023-03-22 11:56:21
Enter ".help" for usage hints.
sqlite> .shell d:\\sqlite32\\sqlite3.exe ":memory:" "select '£10.72';"

Error: in prepare, unrecognized token: "'"
  select '
         ^--- error here
System command returns 1

The only difference between what I ran in the Command Prompt and in the CLI is that I have doubled up \ in the CLI.

I do NOT get the result in the CLI. Therefore I believe that the CLI is not handling £ correctly whereas the Windows console is.

As £ is 0x00A3 (higher than ASCII 127) it is a Unicode issue in the CLI.

UPDATE

For what it worth, the statement works here, in 3.42

The left-pane

-- ==================================================
-- Use ctrl-enter or shift-enter to execute sqlite3
-- shell commands and SQL.
-- If a subset of the text is currently selected,
-- only that part is executed.
-- ==================================================
.nullvalue NULL
.headers on
select '£10.72';

The right-pane

This experimental app is provided in the hope that it may prove interesting or useful but is not an officially supported deliverable of the sqlite project. It is subject to any number of changes or outright removal at any time.

SQLite version 3.42.0 2023-03-10 11:57:23
Welcome to the "fiddle" shell.

Enter ".help" for usage hints.
.nullvalue NULL
.headers on
'£10.72'
£10.72

I have to ask: (tongue-in-cheek) is this introducing backward compatibilty failure?

Interesting, is it not

(5) By AlexJ (CompuRoot) on 2023-04-11 19:11:56 in reply to 3.2 [link] [source]

The CLI is UTF-8 compliant:

CLI is complaint, but your console isn't.

run in your console chcp and see what your console is set to.

You can chcp 65001 to display UTF-8 in cmd/powershell console, but windows's console is very limited and Microsoft advising to use "Windows Terminal" that has full support for unicode characters

(6) By Aask (AAsk1902) on 2023-04-11 19:20:26 in reply to 5 [link] [source]

run in your console chcp and see what your console is set to.

It is set to 65001; see session below.

SQLite version 3.41.2 2023-03-22 11:56:21
Enter ".help" for usage hints.
sqlite> .system chcp
Active code page: 65001
sqlite> select '£10.72;';

'  ...> '
   ...> ;
'
-

When I try with a trailing £

sqlite> select '10.72£';

'  ...> '
   ...> ;
'10.72
------
10.72
sqlite>

My reading of this is that the CLI is treating £ as a continuation or terminating character.

(7) By Larry Brasfield (larrybr) on 2023-04-11 19:37:25 in reply to 6 [link] [source]

My reading of this is that the CLI is treating £ as a continuation or terminating character.

As someone familiar with what the CLI prompts mean, I read it as "Some character after the first single-quote and before the last single-quote tripped up the usual (and correct) parsing of the input byte stream into UTF-8 code points such that the last single-quote was not interpreted as a character." When the continuation prompt starts with certain characters, including single-quote, that means that a single-quoted string literal remains open at that point in the input. The fact that you get a continuation prompt means that a terminating character was not seen. In the case you demonstrate, the semicolon was also seen as being within a string literal, and is not a terminating character in that context.

(10) By AlexJ (CompuRoot) on 2023-04-11 20:21:29 in reply to 6 [link] [source]

My reading of this is that the CLI is treating £ as a continuation or terminating character.

Use appropriate terminal for UTF-8: https://learn.microsoft.com/en-us/windows/terminal/

(11.1) By Aask (AAsk1902) on 2023-04-11 21:10:48 edited from 11.0 in reply to 10 [link] [source]

Use appropriate terminal for UTF-8:

I do NOT believe it is the console I'm using that is the problem:

Microsoft Windows [Version 10.0.22621.1413]
(c) Microsoft Corporation. All rights reserved.

C:\Users\ajaya>d:\sqlite32\sqlite3.exe ":memory:" "select '£10.72';"
£10.72

Your sqlite3.exe would be in a different location; if you have Windows 11, change as appropriate and run the same command to re-create my experience i.e.

d:\sqlite32\sqlite3.exe ":memory:" "select '£10.72';"

(see 12.3 above)

(13) By Gunter Hick (gunter_hick) on 2023-04-12 05:54:51 in reply to 11.1 [link] [source]

Maybe you should be looking at the byte sequences aka hexdump instead of the renderings to determine how the pound currency symbol is encoded.

(14.3) By Aask (AAsk1902) on 2023-04-12 07:18:35 edited from 14.2 in reply to 13 [link] [source]

Maybe you should be looking at the byte sequences aka hexdump

Thanks for the reminder.

Alas, that fails in a similar fashion:

SQLite version 3.41.2 2023-03-22 11:56:21
Enter ".help" for usage hints.
sqlite> select hex('£');
;
'  ...> '
(x1...> ;
Parse error: near ";": syntax error
  select hex('; ' ;
                  ^--- error here

However on Try it Live

select hex('£');

returns

hex('£')
C2A3

Not sure whether that is wrong , that is, I don't know if hex should be returning the unicode value, in this case U+00A3; however, C2 nstead of 00 does not look correct to me. Yet, as I point out in the Update section, Try it Live does NOT fail as the CLI on Windows 11 does.

Decimal 49827 (0xC2A3) 슣 (Korean syuh) as opposed to 163 (0x00A3) for £ might well be the issue at play here.

(15) By Tim Streater (Clothears) on 2023-04-12 07:52:21 in reply to 14.3 [link] [source]

C2A3 is the correct UTF8 byte sequence for the UK pound symbol. You've already been told that the CLI uses UTF8. Perhaps you should ensure your Windows Terminal does too.

(16.3) By Aask (AAsk1902) on 2023-04-12 08:16:00 edited from 16.2 in reply to 15 [link] [source]

Having looked it up, I agree that £ has unicode point U+00A3 abd its UTF8 Hex is 2CA3.

Windows terminal handles £ correctly as I showed in Part 3 or in this reply.

To ease the reference, this is the code:

Microsoft Windows [Version 10.0.22621.1555]
(c) Microsoft Corporation. All rights reserved.

D:\>d:\sqlite32\sqlite3.exe ":memory:" "select '£10.72';"
£10.72

You've already been told that the CLI uses UTF8

At the Command Prompt, (and in several other applications, including the CLI also) I can also see £ when I hold down the ALT key and key in 0163 on the numeric keypad.

That does NOT explain to me why

  • SQLite3.EXE called at the Command Prompt (as shown above) works fine
  • SQLite3.EXE used as the CLI fails.

(17) By Keith Medcalf (kmedcalf) on 2023-04-12 15:18:41 in reply to 16.3 [link] [source]

In the case that succeeds the Windows Console is not involved. In the one that fails it is. I thought we had arrived at this conclusion ages ago.

(18.1) By Aask (AAsk1902) on 2023-04-12 19:59:44 edited from 18.0 in reply to 17 [link] [source]

UPDATE

I can overcome the immediate problem with version 3.41.2- see my session below for details:

SQLite version 3.41.2 2023-03-22 11:56:21
Enter ".help" for usage hints.
sqlite> select char(0xA3) || '10.72' as Price;
Price
------
£10.72
sqlite> create table tblCurrency as select char(0xA3) || '10.72' as Price;
sqlite> select * from tblCurrency;
Price
------
£10.72
sqlite>

Just to keep things joined up (may be).

.shell deficiency mentions this thread (I do not know C well enough to gauge the implications referred to).

A new option, possibly, for CLI: -utf8 appears to be related (I am unable to compile this version).

(19) By Larry Brasfield (larrybr) on 2023-04-12 20:18:33 in reply to 18.1 [link] [source]

.shell deficiency mentions this thread (I do not know C well enough to gauge the implications referred to).

It's quite a remote tangent, being related to this thread only by mention of the CLI.

A new option, possibly, for CLI: -utf8 appears to be related (I am unable to compile this version).

It's related very closely. This thread and others like it inspired the thought, "What if we were willing to essentially take over the console and dork it however much the OS allows, without regard for what older OS versions support?"

It builds, from a cmd.exe shell whose environment supports Microsoft Visual Studio's build tools, with this invocation: nmake -f Makefile.msc , provided that a TCL interpreter has been made available. (That is needed to build the amalgamation from the sources and do some other preprocessing.)