I imagine this is expected behavior but wanted to be sure.

In an sqlite commandline utility (CLI) script, if one enables

.echo on
  for debugging, and redirects output either by

.once filename
   or
.output filename

then the sql commands themselves are included in the output file.

I've taken to putting a defensive ".echo off" just before any .output or
.once
commands to guard against my own absent-mindedness.

Notes:

   1. I've included a simple cut-paste  script below followed by its output.
   2. I tested with
      - Win 7,  and SQLite version 3.20.0
      - Win 10 and SQLite versions 3.20.1 and  3.17.0
      - Ubuntu 15.10 and sqlite 3.8.11.1
   3. I used .mode csv below, but the mode does not appear to matter.
   4. I used ".output stdout" and an in-memory db for illustration, but
   sending the output to a true file or using persistent db doesn't appear to
   matter.
   5. Using a batch file and a file containing the sql (vs cut-paste
   commands) does not appear to matter.
   6. An explicit ".trace off" does not appear to matter.
   7. Interestingly, dot commands entered while .output is in effect are
    NOT echoed to the output file as actual sql commands are.


Thanks for a great product,
    Donald Griggs
    Columbia SC USA

===============Paste following to console
sqlite3 :memory:

CREATE TABLE fruits( name TEXT, cnt INTEGER);
INSERT INTO fruits VALUES ('apple', 1), ('pear',2 ), ('mango', 4),
('grape', 3);

SELECT * FROM fruits;

.mode csv

.echo on
.once stdout
SELECT * FROM fruits;

.echo off
.once stdout
SELECT * FROM fruits;
.quit
==================================

Result (Win 7, with notation added)
==================================
SQLite version 3.20.0 2017-08-01 13:24:15
Enter ".help" for usage hints.
sqlite>
sqlite> CREATE TABLE fruits( name TEXT, cnt INTEGER);
sqlite> INSERT INTO fruits VALUES ('apple', 1), ('pear',2 ), ('mango', 4),
('grape', 3);
sqlite>
sqlite> SELECT * FROM fruits;
apple|1
pear|2
mango|4
grape|3
sqlite>
sqlite> .mode csv
sqlite>
sqlite> .echo on
sqlite> .once stdout
.once stdout
sqlite> SELECT * FROM fruits;
SELECT * FROM fruits;    <<<<**************The select is included in the
output file************
apple,1
pear,2
mango,4
grape,3
sqlite>

sqlite> .echo off
.echo off
sqlite> .once stdout
sqlite> SELECT * FROM fruits;
apple,1
pear,2
mango,4
grape,3
sqlite> .quit
==================================
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to