2

What i was wondering is, how to copy the next sqlite3 code into a single powershell script:

    SQLite version 3.22.0 2018-01-22 18:45:57
Enter ".help" for usage hints.
sqlite> .once -x
sqlite> SELECT * FROM analysis;

I tried the following thing regarding the changing to powershell:

echo "SELECT * FROM analysis" echo ".once -x;" | sqlite3 C:\ProgramData\PROISER\ISASPSUS\datastore\dsfile.db

But as you can know, there is no way that two echo statements can be together in a same place. And the end result that throws Powershell is:

sqlite3 : Error: near line 2: near "echo": syntax error
En línea: 1 Carácter: 51
+ ... once -x;" | sqlite3 C:\ProgramData\PROISER\ISASPSUS\datastore\dsfile. ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Error: near lin...": syntax error:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Now.

1 Answers1

1

Store your SQL in a file, and pass the filename to SQLite. Essentially:

sqlite3 DB.db ".read FILENAME"

See Running a Sqlite3 Script from Command Line

MisterSmith
  • 2,884
  • 1
  • 10
  • 13
  • MisterSmith i also want to run some sqlite3 cli commands in the batch file, like ".headers on", and the possibility to export it to an excel file, where i am having the actual trouble since i am observing that not all the commands from sqlite3 does the cmd recognise in this way – Santiago Corso Aug 29 '18 at 19:44
  • @SantiagoCorso - you should be able to insert any SQLite CLI specific commands in this file (`.headers on` etc). Theres some restrictions - see section #3 & #4 on https://www.sqlite.org/cli.html – MisterSmith Aug 29 '18 at 21:45
  • Thanks a lot. Now, i want to create with .once command a way to create ending reports in csv format, but with automatic name changing. ¿That is possible? – Santiago Corso Aug 30 '18 at 11:49
  • I have another issue. My resulting code is `sqlite3 -cmd ".headers on" -cmd ".once C:\Users\santiago.corso\Desktop\hola.csv" -cmd "SELECT * FROM analysis;" C:\ProgramData\PROISER\ISASPSUS\datastore\dsfile.db > C:\Users\santiago.corso\Desktop\hola.csv ` and what happens is that not a single piece of information is exported to the newly file. – Santiago Corso Aug 30 '18 at 11:56