0

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?
4
  • I know of this workaround: echo ".tables" | sqlite3 -echo database.db but while this is acceptable, it doesn't answer my first question (why is this?) and it's a bit ugly. Commented Mar 11 at 20:52
  • 1
    This appears to be a limitation/bug of sqlite3's shell. When parsing the dot commands on a line input, it echos if requested, however, when parsing command line args, it doesn't. I'd suggest contacting the maintainers of SQLite with a feature/bug request. Commented Mar 11 at 21:34
  • Thanks. You are right, I have found the same thing as I am digging into this, but the repository you linked to is super old and completely out of date. The relevant file in the official repository is here: sqlite.org/src/file?name=src/shell.c.in&ci=trunk but this website does not support linking to specific lines or even syntax highlighting. If you copy it to your favorite editor, the relevant code seems to be around line 13,480. I think you're right, this is a bug. Commented Mar 11 at 21:49
  • 1
    I've posted this on the SQLite forum (anonymously) here: sqlite.org/forum/forumpost/fa827763c9 - hopefully will be picked up by the relevant maintainers Commented Mar 11 at 22:04

1 Answer 1

0

After posting in the SQLite forum, I've got my answers:

"Why is this?" - apparently no real reason, it's "unspecified and untested behavior". It should be fixed in the next release of SQLite, but is not considered a bug and may be reverted later on.

As for a workaround - short of using an updated version of SQLite (as yet unreleased unless building from source), instead of specifying the command as an argument, use echo and pipe it to sqlite:

$ echo '.tables' | sqlite3 -echo database.db 
.tables
stuff

To specify multiple commands, use printf '%s\n' instead of echo:

$ printf '%s\n' '.tables' 'SELECT * FROM stuff;' | sqlite3 -echo database.db 
.tables
stuff
SELECT * FROM stuff;
apples|67
tissues|10
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.