在没有大量阅读SQLite在线文档并且不了解相关配置之前,几分钟的时间可以让你快速了解SQLite.
1. 下载源代码,你总能从http://www.sqlite.org/download.html 这里下载到最新的SQLite发行版本对应的源码。
2. 创建数据库
你可以从http://www.sqlite.org/download.html这里下载到sqlite3.exe,也可以直接依据下文:
http://iihero.iyunv.com/blog/1175595,自己动手编译出该可执行文件。
进到cmd窗口,进到sqlite3所在目录,执行sqlite3 <demo.db全路径>,即可为你创建一个数据库文件。如果是sqlite3 demo.db,则会在当前目录为你创建该数据库。
D:\shared>sqlite3 d:\shared\demo\test.db
SQLite version 3.7.6
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table t(id int primary key, col2 varchar(32));
sqlite> insert into t values(1, 'iihero');
sqlite> insert into t values(2, '中国');
sqlite> select * from t;
1|iihero
2|中国
sqlite>
逻辑很简单,就带两个参数,每一个参数为db文件的路径,第2个参数为要执行的sql语句。
设该文件为demo.c.
编译,需要sqlite3.h, sqlite3.c以及这个demo.c
下边看看我的整个编译及测试过程:
E:\learn\db_research\sqlite\sqlite_auto_build>cd sqlite-amalgamation-3070800
E:\learn\db_research\sqlite\sqlite_auto_build\sqlite-amalgamation-3070800>cl -Gs -GX -D_WIN32 -nologo -Zi -DOS_WIN=1 -DSQLITE_DEBUG=1 -DWIN32=1 -DTHREADSAFE=1 -DSQLITE_OS_WIN=1 -DSQLITE_ENABLE_COLUMN_METADATA=1 -DSQLITE_SOUNDEX=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -I. demo.c sqlite3.c -o demo.exe
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
cl : Command line warning D9035 : option 'o' has been deprecated and will be removed in a future release
demo.c
sqlite3.c
Generating Code...
E:\learn\db_research\sqlite\sqlite_auto_build\sqlite-amalgamation-3070800>dir demo.exe
驱动器 E 中的卷没有标签。
卷的序列号是 04EC-044E
E:\learn\db_research\sqlite\sqlite_auto_build\sqlite-amalgamation-3070800 的目录
2011-09-27 21:32 1,221,120 demo.exe
1 个文件 1,221,120 字节
0 个目录 8,856,236,032 可用字节
E:\learn\db_research\sqlite\sqlite_auto_build\sqlite-amalgamation-3070800>demo.exe d:\shared\demo\test.db "create table t123(id int primary key, col2 varchar(32)); insert into t123 values(1, 'iihero')"
E:\learn\db_research\sqlite\sqlite_auto_build\sqlite-amalgamation-3070800>d:\shared\sqlite3.exe d:\shared\demo\test.db
SQLite version 3.7.6
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from t123;
1|iihero
sqlite>