SQLite ³õ̽
»¹Ê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);
myCommand1.Parameters.Add("param2", "SALES");
myCommand1.Parameters.Add("param3", "CHICAGO");
×ÜÊǻᱨ“ÕÒ²»µ½Î´ÃüÃûµÄ²ÎÊý”
¶ø»»ÁíÒ»ÖÖ×ö·¨£º
SQLiteCommand myCommand1;
...
myCommand1.CommandText = "UPDATE dept SET dname = :dname, loc = :loc WHERE deptno = @deptno";
myCommand1.Parameters.Add("@deptno", 20);
myCommand1.Parameters.Add("dname", "SALES");
myCommand1.Parameters.Add("loc", "NEW YORK");
²åÈëÊÇÄܳɹ¦£¬µ«ÊÇÊý¾Ý¶¼Îª¿Õ£¬ÕæÊǹÖÒì
×îÖÕÖ»ºÃÍÁÍÁµÄÆ´¸öSQLÈ¥Ö´ÐС£
3¡¢¹ØÓÚ Data Source=dbfile;Version=3;New=True;Compress=True; Õâ¸öÁ¬½Ó´®¡£
×îÐèҪ˵Ã÷µÄ¾ÍÊÇ New=True£¬ µ±New=Trueʱ£¬ÊÇʼÖÕ´´½¨ÐµÄÊý¾Ý¿â¡£
ËùÒÔµ±ÔÊý¾Ý¿âÓÐÄÚÈÝʱ£¬ÓÃNew=False£¬·ñÔò£¬Ä㽫ֻÄÜ¿´µ½Ò»¸ö¿ÕµÄÊý¾Ý¿âÎļþ¡£
Ïà¹ØÎĵµ£º
.dump ?TABLE? ... ÒÔSQLÓï¾ä·½Ê½ÏÔʾ±íµÄ½á¹¹¡£È磺
sqlite> .dump websties
BEGIN TRANSACTION;
COMMIT;
sqlite> .dump websites
BEGIN TRANSACTION;
CREATE TABLE [websites] (
[WebID] INTEGER NOT NULL PRIMARY KEY,
[WebName] VARCHAR(20) NULL
);
INSERT INTO "websites" VALUES(1,'CTOChina.net'); ......
SQLiteÊý¾Ý¿âµÄÌåϵ½á¹¹(·Òë×Ôsqlite.org)
1 ¼ò½é
±¾ÎĵµÃèÊöÁËSQLite¿âµÄÌåϵ½á¹¹£¬ÕâЩÐÅÏ¢¶ÔÄÇЩÏëÀí½âºÍÐÞ¸ÄSQLiteµÄÄÚ²¿¹¤×÷»úÖƵÄÈËÊÇÓÐÓõġ£
±¾ÎĵµÃèÊöSQLite 3.0°æ±¾£¬2.8°æ»ò¸üÔçÆڵİ汾Óë´ËÏàËÆ£¬Ö»ÊÇϸ½ÚÉÏÓÐËù²»Í¬¡£
2 ½Ó¿Ú
......
Ò»¡¢SQLite¼ò½é
SQLite ÊÇÓÃCÓïÑÔ±àдµÄ¿ªÔ´Êý¾Ý¿â£¬Ö÷ÒªÓÃÓÚǶÈëʽ£¬ÄãÒ²¿ÉÒÔ°ÑËü¼¯³ÉÔÚ×Ô¼ºµÄ×ÀÃæ³ÌÐòÖУ¬Ò²ÓÐÈ˽«ÆäÌæ´úAccess£¬ÓÃ×÷ºǫ́Êý¾Ý¿â¡£
SQLite Ö§³Ö¶àÊýSQL92±ê×¼£¬ÀýÈ磺Ë÷Òý¡¢ÏÞÖÆ¡¢´¥·¢ºÍ²é¿´Ö§³Ö¡£
Ö§³Ö NULL¡¢INTEGER¡¢REAL¡¢TEXT ºÍ BLOB Êý¾ÝÀàÐÍ£¬Ö§³ÖÊÂÎñ¡£
¶þ¡¢ÏÂÔØSQLite
SQLite¿ÉÒÔµ½¹Ù·½Õ¾µ ......
1¡¢ÈçºÎµÃµ½×îºó²åÈëÏîµÄ×Ô¶¯Ôö³¤IDÖµ£¿ ¶ÔÓ¦µÄC#´úÂë¶ÎÈçÏ£º
using (SQLiteConnection cn = new SQLiteConnection (¡°data source = Test.db¡±))
{
cn.Open ();
SQLiteCommand cmd = new SQLiteCommand ......
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¸¡µãÊý ......