Mixing SQL statements with SQLite .commandscan be a bit complicated:
$ sqlite3 test.db 'create table X(x integer); .dump'
Error: near ".": syntax error
The easiest and most versatile way to handle this is to provide all the SQLite3 command line standard input commands separated by newline characters as you typed them:
$ sqlite3 test.db <<EOF
> CREATE TABLE TEST(X INTEGER);
> .dump
> EOF
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE TEST(X INTEGER);
COMMIT;
Since documents are not available in all shells here, you can use an intermediate file to circumvent this limitation:
$ cat test.sql
CREATE TABLE TEST(X INTEGER);
.dump
$ sqlite3 test.db <test.sql
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE TEST(X INTEGER);
COMMIT;
source
share