SQLite User Forum

Double Prompt with MinGW64 (MSVCRT) compilation
Login

Double Prompt with MinGW64 (MSVCRT) compilation

(1) By Richard (richboss) on 2024-11-05 18:30:27 [source]

Hello,

in the past I was always successful in compiling the SQLite shell with MinGW64 on a Windows 10 PC. I am using the following command:

gcc sqlite3.c shell.c -o sqlite3.exe -msse4 -maes

But with branch-3.47 the compiled shell shows a strange effect: After Return is pressed, the prompt text is always printed twice, like so:

SQLite version 3.47.0 2024-11-04 13:59:58
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>
sqlite> sqlite>
sqlite> sqlite>
sqlite> sqlite> .q

(Of course before compiling I had to apply the fix discussed in this forum post, otherwise the shell would have crashed after the second output line already.)

When I change the prompt text with the ".prompt" command, the changed prompt also is shown twice.

The strange doubling effect was introduced with commit f97f9944b8 from 2024-09-26 19:38:34. Earlier checkouts do not show this effect.

Most importantly this effect - or say, error - is dependent on the "flavour" of MinGW64. I used to have an MinGW64 installation with the traditional MSVCRT runtime library. This is where the error occurs. But I discovered that the error disappared completely after I switched to an installation with the newer UCRT runtime library (downloaded from https://winlibs.com/).

So for myself found a solution to the problem - kind of, anyway. But it would be better if it could be fixed in the code so that the flavour of the runtime library does not matter.

Regards, Richard

(2) By Rowan Worth (sqweek) on 2024-11-06 05:24:32 in reply to 1 [link] [source]

I would guess this is caused by a change in how line endings are interpreted, ie. the standard Windows/DOS ending \r\n is being interpreted as two line endings.

The change you highlighted is a big one, but the following details seem relevant. Before, we had this:

/* From here onward, fgets() is redirected to the console_io library. */
# define fgets(b,n,f) fGetsUtf8(b,n,f)

Looks like this invoked the WIN32API call ReadConsoleW to get data from stdin.

After the change, the code now uses sqlite3_fgets to read lines from stdin, which defers to either fgetws or fgets -- that may explain why the libc that you link against now affects the behaviour.

I also note that openChrSource() is using fopen(..., "rb") which tells libc to open the file in "binary" mode ie. with no newline translation. May or may not be relevant.

(3) By jose isaias cabrera (jicman) on 2024-11-08 14:47:14 in reply to 1 [link] [source]

I am also reporting that cross-compiled sqlite3.exe tools built with cygwin and MSYS environment have a double prompt:

MSYS build

 7:25:28.83>sqlite3
SQLite version 3.48.0 2024-11-08 08:01:56
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .ver
SQLite 3.48.0 2024-11-08 08:01:56 bb3c6dc126896528328bb9f51a28a1d46d4549e687c93c16f2d164230c6b1684
gcc-14.2.0 (64-bit)
sqlite> sqlite>
sqlite> sqlite>
sqlite> sqlite>

Cygwin build

 9:29:13.41>sqlite3
SQLite version 3.48.0 2024-11-08 08:01:56
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .ver
SQLite 3.48.0 2024-11-08 08:01:56 bb3c6dc126896528328bb9f51a28a1d46d4549e687c93c16f2d164230c6b1684
gcc-12.4.0 (64-bit)
sqlite> sqlite>
sqlite> sqlite>
sqlite> sqlite>

The native builds do not have the double prompt. Also, if I run the cross-compiled build under the native build environment, it still has double prompt. I thought that the double prompt behavior was just under the Windows DOS environment.

(4) By jose isaias cabrera (jicman) on 2024-11-14 14:14:19 in reply to 3 [link] [source]

I am also reporting that cross-compiled sqlite3.exe tools built with cygwin and MSYS environment have a double prompt:

I cross-compiled sqlite3.exe yesterday with both MSYS and CYGWIN and the double prompt no longer appears with both builds. So, this is no longer true as of

 9:11:57.83>sqlite3
SQLite version 3.48.0 2024-11-13 16:08:02
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .ver
SQLite 3.48.0 2024-11-13 16:08:02 0611e2b0cf3f33c28cc9ff6c5da7ebba2033bcbda5b1072a30021a3e1fb4e738
gcc-14.2.0 (64-bit)
sqlite>

which was the latest trunk check-in yesterday. Just wanted to finalize this thread from my side.

(5) By Rowan Worth (sqweek) on 2024-11-15 07:42:09 in reply to 4 [link] [source]

Possibly this change was the resolution: https://sqlite.org/src/info/abfe488ed67e2e35

(6) By jose isaias cabrera (jicman) on 2024-11-15 12:33:05 in reply to 5 [link] [source]

A very high probability. Yes.