2010ÄêSQLiteѧϰ±Ê¼ÇÖ®¶þ
Ò».½¨Á¢Êý¾Ý¿â
sqlite3.exe test.db
¶þ.Ë«»÷sqlite-3_6_16Ŀ¼ÏµijÌÐòsqlite3.exe£¬¼´¿ÉÔËÐÐ
Èý.Í˳ö
.exit
»òÕß
.quit
ËÄ.SQLiteÖ§³ÖÈçÏÂ5ÖÖÊý¾ÝÀàÐÍ
1.NULL£º¿ÕÖµ¡£
2.INTEGER£º´ø·ûºÅµÄÕûÐÍ£¬¾ßÌåÈ¡¾öÓдæÈëÊý×ֵķ¶Î§´óС¡£
3.REAL£º¸¡µãÊý×Ö£¬´æ´¢Îª8-byte IEEE¸¡µãÊý¡£
4.TEXT£º×Ö·û´®Îı¾¡£
5.BLOB£º¶þ½øÖƶÔÏó¡£
Îå.ÁªÏµÈ˱í¸ñ½á¹¹ÈçÏÂ
create table contact(id integer primary key autoincrement,
lastname varchar(20),firstname varchar(20),
mobile varchar(30), telephone varchar(20),
email varchar(30), company varchar(50),
department varchar(16),address varchar(80),
id1 interger,id2 integer, updatetime datetime);
Áù.²é¿´Êý¾Ý¿âÓÐÄÄЩÊý¾Ý±í
ÃüÁîÊÇ£º.tables
Æß.ÈçºÎ²åÈëÒ»Ìõ¼Ç¼
insert into contact(lastname,firstname,mobile,telephone,updatetime) values('Áõ','³©','13910128132','010-81749136','2009-07-22');
°Ë.²é¿´Êý¾Ý±íµÄ½á¹¹
Õë¶ÔÕû¸öÊý¾Ý¿â
.schema
Õë¶Ô½ö½öÊÇcontactÁªÏµÈ˸ñí
.schema contact ×¢ÒâûÓзֺÅ
......
SQLite3ÊÇSQLiteÒ»¸öȫеİ汾,ËüËäÈ»ÊÇÔÚSQLite 2.8.13µÄ´úÂë»ù´¡Ö®ÉÏ¿ª·¢µÄ,µ«ÊÇʹÓÃÁ˺Í֮ǰµÄ°æ±¾²»¼æÈݵÄÊý¾Ý¿â¸ñʽºÍAPI. SQLite3ÊÇΪÁËÂú×ãÒÔϵÄÐèÇó¶ø¿ª·¢µÄ:
Ö§³ÖUTF-16±àÂë.
Óû§×Ô¶¨ÒåµÄÎı¾ÅÅÐò·½·¨.
¿ÉÒÔ¶ÔBLOBs×ֶν¨Á¢Ë÷Òý.
Òò´ËΪÁËÖ§³ÖÕâЩÌØÐÔÎҸıäÁËÊý¾Ý¿âµÄ¸ñʽ,½¨Á¢ÁËÒ»¸öÓë֮ǰ°æ±¾²»¼æÈݵÄ3.0°æ. ÖÁÓÚÆäËûµÄ¼æÈÝÐԵĸıä,ÀýÈçȫеÄAPIµÈµÈ,¶¼½«ÔÚÀíÂÛ½éÉÜÖ®ºóÏòÄã˵Ã÷,ÕâÑù¿ÉÒÔʹÄã×î¿ìµÄÒ»´ÎÐÔ°ÚÍѼæÈÝÐÔÎÊÌâ.
3.0°æµÄºÍ2.X°æµÄAPI·Ç³£ÏàËÆ,µ«ÊÇÓÐһЩÖØÒªµÄ¸Ä±äÐèҪעÒâ. ËùÓÐAPI½Ó¿Úº¯ÊýºÍÊý¾Ý½á¹¹µÄǰ׺¶¼ÓÉ"sqlite_
"¸ÄΪÁË"sqlite3_
". ÕâÊÇΪÁ˱ÜÃâͬʱʹÓÃSQLite 2.XºÍSQLite 3.0ÕâÁ½¸ö°æ±¾µÄʱºò·¢ÉúÁ´½Ó³åÍ».
ÓÉÓÚ¶ÔÓÚCÓïÑÔÓ¦¸ÃÓÃʲôÊý¾ÝÀàÐÍÀ´´æ·ÅUTF-16±àÂëµÄ×Ö·û´®²¢Ã»ÓÐÒ»ÖµĹ淶. Òò´ËSQLiteʹÓÃÁËÆÕͨµÄvoid* ÀàÐÍÀ´Ö¸ÏòUTF-16±àÂëµÄ×Ö·û´®. ¿Í»§¶ËʹÓùý³ÌÖпÉÒÔ°Ñvoid*Ó³Éä³ÉÊʺÏËûÃǵÄϵͳµÄÈκÎÊý¾ÝÀàÐÍ.
2.0 C/C++ ½Ó¿Ú
SQLite 3.0Ò»¹²ÓÐ83¸öAPIº¯Êý,´ËÍ⻹ÓÐһЩÊý¾Ý½á¹¹ºÍÔ¤¶¨Òå(#defines). (ÍêÕûµÄAPI½éÉÜÇë²Î¿´ÁíÒ»·ÝÎĵµ.)
²»¹ýÄãÃÇ¿ÉÒÔ·ÅÐÄ,ÕâЩ½Ó¿ÚʹÓÃÆðÀ´²»»áÏñËüµÄÊýÁ¿Ëù° ......
SQLite3ÊÇSQLiteÒ»¸öȫеİ汾,ËüËäÈ»ÊÇÔÚSQLite 2.8.13µÄ´úÂë»ù´¡Ö®ÉÏ¿ª·¢µÄ,µ«ÊÇʹÓÃÁ˺Í֮ǰµÄ°æ±¾²»¼æÈݵÄÊý¾Ý¿â¸ñʽºÍAPI. SQLite3ÊÇΪÁËÂú×ãÒÔϵÄÐèÇó¶ø¿ª·¢µÄ:
Ö§³ÖUTF-16±àÂë.
Óû§×Ô¶¨ÒåµÄÎı¾ÅÅÐò·½·¨.
¿ÉÒÔ¶ÔBLOBs×ֶν¨Á¢Ë÷Òý.
Òò´ËΪÁËÖ§³ÖÕâЩÌØÐÔÎҸıäÁËÊý¾Ý¿âµÄ¸ñʽ,½¨Á¢ÁËÒ»¸öÓë֮ǰ°æ±¾²»¼æÈݵÄ3.0°æ. ÖÁÓÚÆäËûµÄ¼æÈÝÐԵĸıä,ÀýÈçȫеÄAPIµÈµÈ,¶¼½«ÔÚÀíÂÛ½éÉÜÖ®ºóÏòÄã˵Ã÷,ÕâÑù¿ÉÒÔʹÄã×î¿ìµÄÒ»´ÎÐÔ°ÚÍѼæÈÝÐÔÎÊÌâ.
3.0°æµÄºÍ2.X°æµÄAPI·Ç³£ÏàËÆ,µ«ÊÇÓÐһЩÖØÒªµÄ¸Ä±äÐèҪעÒâ. ËùÓÐAPI½Ó¿Úº¯ÊýºÍÊý¾Ý½á¹¹µÄǰ׺¶¼ÓÉ"sqlite_
"¸ÄΪÁË"sqlite3_
". ÕâÊÇΪÁ˱ÜÃâͬʱʹÓÃSQLite 2.XºÍSQLite 3.0ÕâÁ½¸ö°æ±¾µÄʱºò·¢ÉúÁ´½Ó³åÍ».
ÓÉÓÚ¶ÔÓÚCÓïÑÔÓ¦¸ÃÓÃʲôÊý¾ÝÀàÐÍÀ´´æ·ÅUTF-16±àÂëµÄ×Ö·û´®²¢Ã»ÓÐÒ»ÖµĹ淶. Òò´ËSQLiteʹÓÃÁËÆÕͨµÄvoid* ÀàÐÍÀ´Ö¸ÏòUTF-16±àÂëµÄ×Ö·û´®. ¿Í»§¶ËʹÓùý³ÌÖпÉÒÔ°Ñvoid*Ó³Éä³ÉÊʺÏËûÃǵÄϵͳµÄÈκÎÊý¾ÝÀàÐÍ.
2.0 C/C++ ½Ó¿Ú
SQLite 3.0Ò»¹²ÓÐ83¸öAPIº¯Êý,´ËÍ⻹ÓÐһЩÊý¾Ý½á¹¹ºÍÔ¤¶¨Òå(#defines). (ÍêÕûµÄAPI½éÉÜÇë²Î¿´ÁíÒ»·ÝÎĵµ.)
²»¹ýÄãÃÇ¿ÉÒÔ·ÅÐÄ,ÕâЩ½Ó¿ÚʹÓÃÆðÀ´²»»áÏñËüµÄÊýÁ¿Ëù° ......
SQLite3ÊÇSQLiteÒ»¸öȫеİ汾,ËüËäÈ»ÊÇÔÚSQLite 2.8.13µÄ´úÂë»ù´¡Ö®ÉÏ¿ª·¢µÄ,µ«ÊÇʹÓÃÁ˺Í֮ǰµÄ°æ±¾²»¼æÈݵÄÊý¾Ý¿â¸ñʽºÍAPI. SQLite3ÊÇΪÁËÂú×ãÒÔϵÄÐèÇó¶ø¿ª·¢µÄ:
Ö§³ÖUTF-16±àÂë.
Óû§×Ô¶¨ÒåµÄÎı¾ÅÅÐò·½·¨.
¿ÉÒÔ¶ÔBLOBs×ֶν¨Á¢Ë÷Òý.
Òò´ËΪÁËÖ§³ÖÕâЩÌØÐÔÎҸıäÁËÊý¾Ý¿âµÄ¸ñʽ,½¨Á¢ÁËÒ»¸öÓë֮ǰ°æ±¾²»¼æÈݵÄ3.0°æ. ÖÁÓÚÆäËûµÄ¼æÈÝÐԵĸıä,ÀýÈçȫеÄAPIµÈµÈ,¶¼½«ÔÚÀíÂÛ½éÉÜÖ®ºóÏòÄã˵Ã÷,ÕâÑù¿ÉÒÔʹÄã×î¿ìµÄÒ»´ÎÐÔ°ÚÍѼæÈÝÐÔÎÊÌâ.
3.0°æµÄºÍ2.X°æµÄAPI·Ç³£ÏàËÆ,µ«ÊÇÓÐһЩÖØÒªµÄ¸Ä±äÐèҪעÒâ. ËùÓÐAPI½Ó¿Úº¯ÊýºÍÊý¾Ý½á¹¹µÄǰ׺¶¼ÓÉ"sqlite_
"¸ÄΪÁË"sqlite3_
". ÕâÊÇΪÁ˱ÜÃâͬʱʹÓÃSQLite 2.XºÍSQLite 3.0ÕâÁ½¸ö°æ±¾µÄʱºò·¢ÉúÁ´½Ó³åÍ».
ÓÉÓÚ¶ÔÓÚCÓïÑÔÓ¦¸ÃÓÃʲôÊý¾ÝÀàÐÍÀ´´æ·ÅUTF-16±àÂëµÄ×Ö·û´®²¢Ã»ÓÐÒ»ÖµĹ淶. Òò´ËSQLiteʹÓÃÁËÆÕͨµÄvoid* ÀàÐÍÀ´Ö¸ÏòUTF-16±àÂëµÄ×Ö·û´®. ¿Í»§¶ËʹÓùý³ÌÖпÉÒÔ°Ñvoid*Ó³Éä³ÉÊʺÏËûÃǵÄϵͳµÄÈκÎÊý¾ÝÀàÐÍ.
2.0 C/C++ ½Ó¿Ú
SQLite 3.0Ò»¹²ÓÐ83¸öAPIº¯Êý,´ËÍ⻹ÓÐһЩÊý¾Ý½á¹¹ºÍÔ¤¶¨Òå(#defines). (ÍêÕûµÄAPI½éÉÜÇë²Î¿´ÁíÒ»·ÝÎĵµ.)
²»¹ýÄãÃÇ¿ÉÒÔ·ÅÐÄ,ÕâЩ½Ó¿ÚʹÓÃÆðÀ´²»»áÏñËüµÄÊýÁ¿Ëù° ......
»¹Êdzõ̽£¬×öµÄÏîÄ¿ÒªÓõ½ÇáÇɵı¾µØÊý¾Ý¿â£¬ÓÚÊÇÕÒÁË sqlite 3 ÊÔÓÃÖ®£¬»¹²»´í£¬¹»ÇáÇÉ¡£
ÉÏÕâ¶ùÈ¥ÏÂÔسÌÐòºÍ²é¿´Îĵµ£º http://www.sqlite.org/download.html
Õâ»Ø¿ª·¢ÓõÄÊÇ C#£¬ÓÚÊÇÕÒÁ˸ö.NETµÄ¿â Finisar.SQLite £¬µ½Õâ¶ùÈ¥ÔØ http://adodotnetsqlite.sourceforge.net/
Òª¼ÇµÄÒ²²»ÊÇʲô´ó²»Á˵Ķ«Î÷£¬Ê¾ÀýÍøÕ¾É϶¼ÓУ¬¾ÍÊǼ¸µãÐèҪעÒâµÄµØ·½
1¡¢Finisar.SQLite °üÄÜÔص½3¸ö¶¯Ì¬¿â sqlite3.dll¡¢SQLite.dll¡¢SQLite.NET.dll£¬ÔÚ.NET¹¤³ÌÖÐ¶Ô SQLite.NET.dll Ìí¼ÓÒýÓà ´úÂëÖоͿÉÒÔ using Finisar.SQLite;£¬½«¶¯Ì¬¿â¿½±´ÖÁ³ÌÐòÔËÐÐĿ¼£¬¼´¿É¡£
2¡¢Õâ¸ö¿âÓÐÀàËÆ DbConnection¡¢DbCommand¡¢DbDataReader µÄ×é¼þ£ºSQLiteConnection ¡¢SQLiteCommand¡¢SQLiteDataReader£¬Ê¹ÓÃÒ²»ù±¾Ïàͬ¡£
µ«ÊÇÎÒÔÚʹÓôø²ÎÊýµÄ SQLiteCommand ʱ³öÁ˵ãÎÊÌ⣬ËäÈ»²Î¿¼Á˹ÙÍøµÄʾÀý £¨http://www.devart.com/dotconnect/sqlite/docs/Parameters.html£©µ«Ã»ÓÐʲô°ïÖú£º
ÎÊÌ⣺
SQLiteCommand myCommand1;
...
myCommand1.CommandText = "INSERT INTO dept (deptno, dname, loc) VALUES (?, ?, ?)";
myCommand1.Parameters.Add("param1", 30);
myC ......
sqlite3 *db;
sqlite3_stmt *stat;
char
*zErrMsg = 0;
char
temp[256], FileRoot[256];
char
buffer2[1024]="0";
sprintf(temp, _T("%s"), _T("utf.db"));
CCodingConv::GB2312_2_UTF8(FileRoot, 256, temp, 0);
sqlite3_open(FileRoot, &db);
if
(db == NULL)
{
return
-1;
}
sqlite3_key(db,"1q2w3e4r",8);
sqlite3_exec(db, "CREATE TABLE list (fliename varchar(128) UNIQUE, fzip text);", 0, 0, &zErrMsg);
sqlite3_prepare(db, "insert into list values ('
ÖÐÎÄGB2312
±àÂë',?);", -1, &stat, 0);
strcpy(temp, "
²âÊÔÊý¾ÝUTF-8
µÄÖ§³ÖÇé¿ö&qu ......
1:³£ÓýӿÚ
¸öÈ˱ȽÏϲ»¶
sqlite,
ʹÓÃ×î·½±ã£¬Î¨Ò»µÄ×¼±¸¹¤×÷ÊÇÏÂÔØ
250K
µÄÔ´£»¶øÇÒ×÷ÕߺÜÈÈÐÄ£¬ÓÐÎʱشð¡£
ÒÔÏÂÑÝʾһÏÂʹÓÃ
sqlite
µÄ²½Ö裬ÏÈ´´½¨Ò»¸öÊý¾Ý¿â£¬È»ºó²éѯÆäÖеÄÄÚÈÝ¡£
2
¸öÖØÒª½á¹¹ÌåºÍ
5
¸öÖ÷Òªº¯Êý£º
sqlite3 *pdb,
Êý¾Ý¿â¾ä±ú£¬¸úÎļþ¾ä±ú
FILE
ºÜÀàËÆ
sqlite3_stmt *stmt,
Õâ¸öÏ൱ÓÚ
ODBC
µÄ
Command
¶ÔÏó£¬ÓÃÓÚ±£´æ±àÒëºÃµÄ
SQL
Óï¾ä
sqlite3_open(),
´ò¿ªÊý¾Ý¿â
sqlite3_exec(),
Ö´ÐзDzéѯµÄ
sql
Óï¾ä
sqlite3_prepare(),
×¼±¸
sql
Óï¾ä£¬Ö´ÐÐ
select
Óï¾ä»òÕßҪʹÓÃ
parameter bind
ʱ£¬ÓÃÕâ¸öº¯Êý£¨·â×°ÁË
sqlite3_exec
£©
.
Sqlite3_step(),
ÔÚµ÷ÓÃ
sqlite3_prepare
ºó£¬Ê¹ÓÃÕâ¸öº¯ÊýÔڼǼ¼¯ÖÐÒƶ¯¡£
Sqlite3_close(),
¹Ø±ÕÊý¾Ý¿âÎļþ
»¹ÓÐһϵÁеĺ¯Êý£¬ÓÃÓڴӼǼ¼¯×Ö¶ÎÖлñÈ¡Êý¾Ý£¬Èç
sqlite3_column_text(),
È¡
text
ÀàÐ͵ÄÊý¾Ý¡£
sqlite3_column_blob
£¨£©£¬È¡
blob
ÀàÐ͵ÄÊý¾Ý
sqlite3_column_int(),
È ......
2010ÄêSQLiteѧϰ±Ê¼ÇÖ®Èý
Ò»£®ÈçºÎ±¸·ÝÊý¾Ý¿â
ÏÈ´ò¿ªÊý¾Ý¿âtest.db
E:\sqlite\tool\sqlite-3_6_22>sqlite3 D:\Test\debug\test.db
sqlite> .backup D:\\Test\\debug\\test.bak
×¢Ò⣺һ¶¨ÒªÓÃ\\˫б¸Ü
¶þ£®ÈçºÎ»Ö¸´Êý¾Ý¿â
ÏÈ´ò¿ªÊý¾Ý¿âtest.db
E:\sqlite\tool\sqlite-3_6_22>sqlite3 D:\Test\debug\test.db
sqlite> .restore D:\\Test\\debug\\test.bak
×¢Ò⣺һ¶¨ÒªÓÃ\\˫б¸Ü
Èý£®ÏÈÅжϱíÈç¹û²»´æÔÚ£¬ÔòÔÙ´´½¨±í
SQL¿ÉÒÔÈçÏÂд£¬¹©²Î¿¼£º
create table if not exists student(id integer primary key autoincrement,\
age smallint ,anchor smallint);
ËÄ£®ÈçºÎ²éѯSQLite3С¹¤¾ß»òÕßSQLite3.dll¶¯Ì¬Á´½Ó¿âµÄ°æ±¾
Ö´ÐÐ select sqlite_version();ÃüÁî¼´¿É
Î壮SQLite3µÄ×îÐÂ°æ± ......