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 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

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
@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 sqlite.org/cli.html
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?
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.

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.