Automate creating a SQLite database from a batch file

On a Windows platform, I have the following:
schema.sql (contains sql scripts)
sqlite3.exe (command shell for sqlite → download from sqlite.org)
build.bat: batch file with the line: sqlite3.exe -init schema.sql default.db3

When I run build.bat, the database is created as expected, however the sqlite shell does not end automatically. So, how can I run a batch file and automatically end sqlite command line shell?

eg. output

C: \ Work \ X \ Database> sqlite3.exe -init schema.sql default.db3
- Loading resources from schema.sql
SQLite Version 3.7.4
Enter ".help" for instructions
Enter SQL queries terminated by a ";"
sqlite>

+4
source share
6 answers

Try calling it like this:

echo .quit | sqlite3.exe 

Or put .quit at the end of your file.

+2
source

It seems (since you did not specify its contents) that there is no exit statement in the bat file. You can add it yourself:

 sqlite3.exe -init schema.sql default.db3 .exit 
+2
source

I had the same problem with sqlite3 3.11 (but not 3.8), and the solution that worked for me was:

 sqlite3.exe default.db3 < schema.sql 

And the Regis answer worked perfectly.

+1
source

I agree with Andrey. If this does not work, try adding "quit" on a separate line at the end of your schema.sql

Hope this helps.

0
source

Try instead:

 type schema.sql | sqlite3 default.db3 
0
source

Golf Andrew will answer, you can also run:

 echo | sqlite3 

EOF is going to close sqlite3

0
source

All Articles