i want to create a new db of sqlite using A SHELL SCR开发者_开发百科IPT on an ubuntu10.10 OS....Any ideas??
I tried 'create.sh' file with following code...
#!/bin/bash
sqlite ex3.db
create table t1(f1 integer primary key,f2 text)
than run a ./create.sh from termminal but it leads me to sqlite> prompt...I dont see created DB ex3 anywhere..
Please help ...
One more way to accomplish this can be using SQL_ENTRY_TAG_N
#!/bin/bash
sqlite3 mydatabase <<SQL_ENTRY_TAG_1
SELECT * FROM sqlite_master;
SQL_ENTRY_TAG_1
see snippet for details
#!/bin/bash
sqlite3 ex3.db "create table t1(f1 integer primary key,f2 text)"
should work I think, unfortunately, not able to check right now.
You want to feed your SQL DDL commands to SQLite through the standard input:
#!/bin/bash
echo 'create table t1(f1 integer primary key,f2 text);' | sqlite ex3.db
Can you use the param -line on sqlite3, for example:
$sqlite3 -line teste.db 'create table table_name (field_name integer)'
$sqlite3 -line teste.db 'insert into table_name (123)'
$sqlite3 -line teste.db 'select * from table_name'
Example of CREATE
and INSERT
of create.sh
:
#!/bin/bash
DB_NAME=ex3.sqlite
DB_TABLE=t1
sqlite3 $DB_NAME << EOF
DROP TABLE IF EXISTS $DB_TABLE;
CREATE TABLE $DB_TABLE (
"f1" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"f2" TEXT NOT NULL DEFAULT "f2-text"
);
INSERT INTO $DB_TABLE (f1, f2) VALUES (1, "text 1");
INSERT INTO $DB_TABLE (f1, f2) VALUES (2, "text 2");
EOF
精彩评论