SQLite User Forum

commandline -echo option does not echo dot commands - is this a bug?
Login

commandline -echo option does not echo dot commands - is this a bug?

(1) By anonymous on 2025-03-11 22:00:59 [source]

I have asked this on StackOverflow but thought I should mirror it here, if it is indeed a bug then hopefully SQLite maintainers will see it.

StackOverflow: https://stackoverflow.com/questions/79502089/sqlite3-echo-does-not-echo-dot-commands-supplied-on-the-command-line

I will copy the question contents here:

When I run sqlite3 interactively with the -echo option, every command I type gets echoed before its output, as expected:

$ sqlite3 -echo database.db
SQLite version 3.45.1 2024-01-30 16:01:20
Enter ".help" for usage hints.
sqlite> SELECT * FROM stuff;
SELECT * FROM stuff;
apples|67
tissues|10
sqlite> .tables
.tables
stuff
sqlite> .exit

However, when the commands are specified in the commandline arguments, SQL queries get echoed but dot commands do not:

$ sqlite3 -echo database.db "SELECT * FROM stuff;" ".tables"
SELECT * FROM stuff;
apples|67
tissues|10
stuff

Notice that .tables did not get echoed.

  1. Why is this?
  2. Is there a way to make dot commands supplied in the command line get echoed as well?

In my opinion this is a bug (different behaviour between commandline and stdin), and seems to be because commandline commands are not run by the same code that runs stdin commands:

  // line 13,480 or so of shell.c

  if( !readStdin ){
    /* Run all arguments that do not begin with '-' as if they were separate
    ** command-line inputs, except for the argToSkip argument which contains
    ** the database filename.
    */
    for(i=0; i<nCmd; i++){
      if( azCmd[i][0]=='.' ){
        // !!!!! missing call to echo_group_input here !!!!!
        rc = do_meta_command(azCmd[i], &data);
        if( rc ){
          if( rc==2 ) rc = 0;
          goto shell_main_exit;
        }
      }else{
        // ...

(2.1) By NeatNit on 2025-03-12 14:55:51 edited from 2.0 in reply to 1 [link] [source]

I've registered to the forum now :)

Clickable link to StackOverflow: https://stackoverflow.com/q/79502089/6778374 (kinda silly that this forum's Markdown parser doesn't automatically make links clickable!)

I also meant shell.c.in instead of shell.c

Other than that, I really just wanted to bump this thread because I think it has been missed due to publication delay as it awaited moderator approval.

(3) By Richard Hipp (drh) on 2025-03-12 15:20:41 in reply to 2.1 [link] [source]

This is really important to you, it seems. Here is your patch: https://sqlite.org/src/info/6ec0c03b954cf705

Just for the record, this is not a bug. It is unspecified and untested behavior. I personally don't much care one why or another how --echo interacts with command-line arguments, so I'm happy to make this change. But it is apparently a change in long-standing behavior. Therefore, I reserve the right to change it back if I get pushback from other users saying this change broke their scripts.

(4) By NeatNit on 2025-03-12 15:38:55 in reply to 3 [link] [source]

This is really important to you, it seems.

That's a bit of an exaggeration. It did bother me enough to report though, and my second post and its edit are mostly coming from me being confused by this forum software and fiddling with it. Sorry if it came across as a bit spammy.

The main reason I think this is important is the .import command, which I want to see in my logs. It's at least as important as INSERT, so if I specify -echo I expect it to be echoed.

Here is your patch

Thanks!

Therefore, I reserve the right to change it back if I get pushback from other users saying this change broke their scripts.

Sure, that makes sense. I'll be disappointed but I'll survive.

Just for the record, this is not a bug.

I could argue with this, and I want to, but that wouldn't be productive. Thanks for your time :)