nal databases listed for databases attached using the ATTACH statement.
The first output column is the name the database is attached with, and the second column is the filename of the external file.
".dump"命令将把database的内容转化为一个ASCII编码的文本文件。
This file can be converted back into a database by piping it back into sqlite3.
把一个数据库进行archival备份可以用如下的命令:
$ echo '.dump' | sqlite3 ex1 | gzip -c >ex1.dump.gz
这样将生产一个名叫ex1.dump.gz的文件,它包含了重新构建数据库的所有信息
重新构建数据库。只需要如下的语句: www.2cto.com
$ zcat ex1.dump.gz | sqlite3 ex2
因为文本格式是纯SQL的 ,所以你可以通过.dump命令把你的数据库导入到另外的更常用的数据库引擎.
比如:
$ createdb ex2
$ sqlite3 ex1 .dump | psql ex2
The ".explain" dot command can be used to set the output mode to "column" and
to set the column widths to values that are reasonable for looking at the output of an EXPLAIN command.
The EXPLAIN command is an SQLite-specific SQL extension that is useful for debugging.
If any regular SQL is prefaced by EXPLAIN, then the SQL command is parsed and analyzed but is not executed.
Instead, the sequence of virtual machine instructions that would have been used to execute the SQL command are returned like a query result.
For example:
sqlite> .explain
sqlite> explain delete from tbl1 where two<20;
addr opcode p1 p2 p3
---- ------------ ----- ----- -------------------------------------
0 ListOpen 0 0
1 Open 0 1 tbl1
2 Next 0 9
3 Field 0 1
4 Integer 20 0
5 Ge 0 2
6 Key 0 0
7 ListWrite 0 0
8 Goto 0 2
9 Noop 0 0
10 ListRewind 0 0
11 ListRead 0 14
12 Delete 0 0
13 Goto 0 11
14 ListClose 0 0
The ".timeout" command sets the amount of time that the sqlite3 program will wait for locks to clear on files it is trying to access before returning an error. The default value of the timeout is zero so that an error is returned immediately if any needed database table or index is locked.
".exit和“.quite"命令用于退出sqlite3程序.他们好像没有什么区别
如何以Shell脚本的方式使用sqlite3命令
一种方式是:用"echo"或"cat"命令输出一些sqlite3命令到一个文件,然后执行程序sqlite3,并把该文件作为sqlite3的输入流。这种方式不错,很多程序都可以这样。
另一种方式是:以SQL语句作为sqlite3的第二个参数,在执行SQL操作。为了方便,sqlite3允许在第一个参数数据库名后,再跟一个参数,来指定要执行的SQL语句。如果sqlite3带2个参数进行启动的话,第二个参数将做为SQL传递给SQLite library来处理, 返回结果将以list模式在标准输出中进行显示,然后sqlite3程序也退出了。
比如,示例17:
# sqlite3 /data/data/com.android.providers.settings/databases/settings.db "select * from system;select * from system"
以SQL语句作为sqlite3的第二个参数,这种方式主要是为了sqlite3和其他程序(比如"awk")联合使用.
比如,示例18:
$ sqlite3 ex1 'select * from tbl1' |
> awk '{printf "
| %s | %s\n",$1,$2 }'
|
| hello | 10
|
| goodbye | 20
$
SQL语句的结束符
一般sqlite3的SQL语句的结束符是分号";". 然而你在shell中运行sqlite3时你还可以使用"GO" (大写) 或"/"来作为一条SQL语句结束的标志. 他们分别在SQL Server和Oracle中被使用. 但是他在sqlite3_exec()不能使用shell会先把他们转化为分号";",然后再传递到该函数.
在源码中编译sqlite3
The sqlite3 program is built automatically when you compile the 当你编译SQLite library的时候,sqlite程序就自动被编译了. Just get a copy of the source tree, run "configure" and then "make".
|