Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automating the creation of a SQLite database from a batch file

On a windows platform I have the following:

  • schema.sql (contains the sql scripts)
  • sqlite3.exe (command shell for sqlite -> downloaded from sqlite.org)
  • build.bat : A 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 doesn't automatically terminate. So how would I get the batch file to run and terminate the sqlite command shell automatically?

E.g. 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 statements terminated with a ";"  
  sqlite>  
like image 213
Eminem Avatar asked Apr 22 '11 15:04

Eminem


People also ask

How do I start SQLite from command prompt?

Open a command prompt (cmd.exe) and 'cd' to the folder location of the SQL_SAFI. sqlite database file. run the command 'sqlite3' This should open the SQLite shell and present a screen similar to that below.

Can multiple processes write to SQLite?

SQLite allows multiple processes to have the database file open at once, and for multiple processes to read the database at once. When any process wants to write, it must lock the entire database file for the duration of its update. But that normally only takes a few milliseconds.

Why SQLite is not used in production?

The biggest problem with using SQLite in production is disaster recovery. If your server dies, so does your data. That's… not good. Other database servers have replication so they can stream database changes to another server in case one goes down.

Can SQLite be deployed?

SQLite is the most widely deployed database in the world with more applications than we can count, including several high-profile projects. SQLite is a compact library. With all features enabled, the library size can be less than 750KiB, depending on the target platform and compiler optimization settings.


2 Answers

Try to call it like that:

echo .quit | sqlite3.exe 

Or put .quit in the end of your file.

like image 69
Andrey Avatar answered Sep 28 '22 11:09

Andrey


It seems (since you haven't shown its contents) that the bat file is missing the exit statement. You can add it yourself:

sqlite3.exe -init schema.sql default.db3 .exit
like image 45
Regis Avatar answered Sep 28 '22 11:09

Regis