[sqlite] How initialize a database file from unix shell without landing in SQLite command prompt?

2015-03-14 Thread Mikael
I have a file DBDEFINITION.TXT that I want to use to initialize [execute
on] the database DB.SQLITE.

How do I do something like

$ sqlite3 -exec DBDEFINITION.TXT DB.SQLITE
$


?

All methods I tried end me up in the SQLite prompt, and that is what I
don't want. Like, doing sqlite3 -init DBDEFINITION.TXT DB.SQLITE and having
".quit" as last line in the definition file.

Thanks.


[sqlite] How initialize a database file from unix shell without landing in SQLite command prompt?

2015-03-14 Thread R.Smith


On 2015-03-14 10:51 AM, Mikael wrote:
> I have a file DBDEFINITION.TXT that I want to use to initialize [execute
> on] the database DB.SQLITE.
>
> How do I do something like
>
> $ sqlite3 -exec DBDEFINITION.TXT DB.SQLITE
> $

A piped file is always the answer - for anything really. If a piped file 
is not specified then the console becomes the standard input to the 
program and you end up in the console input cycle (which is what happens 
for you).

# sqlite3 mydb.db < somefile.sql

- will execute with mydb.db all the SQL statements (if no errors occur) 
inside somefile.sql - Note that this doesn't wrap the file in an 
implicit transaction, if the file fails halfway through and you did not 
start an explicit transaction, it won't be rolled back.

Good luck!
Ryan


[sqlite] How initialize a database file from unix shell without landing in SQLite command prompt?

2015-03-14 Thread Neville Dastur

Just pipe the text file to sqlite3
# sqlite3 DB.SQLITE :
>I have a file DBDEFINITION.TXT that I want to use to initialize [execute
>on] the database DB.SQLITE.
>How do I do something like
>$ sqlite3 -exec DBDEFINITION.TXT DB.SQLITE
>$
>?
>All methods I tried end me up in the SQLite prompt, and that is what I
>don't want. Like, doing sqlite3 -init DBDEFINITION.TXT DB.SQLITE and having
>".quit" as last line in the definition file.
>Thanks.
>___
>sqlite-users mailing list
>sqlite-users at mailinglists.sqlite.org
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users