(1) ÈçºÎ½¨Á¢×Ô¶¯Ôö³¤×Ö¶Î?
¼ò¶Ì»Ø´ð£ºÉùÃ÷Ϊ INTEGER PRIMARY KEY µÄÁн«»á×Ô¶¯Ôö³¤¡£
³¤Ò»µãµÄ´ð°¸£º Èç¹ûÄãÉùÃ÷±íµÄÒ»ÁÐΪ INTEGER PRIMARY KEY£¬ÄÇô£¬ ÿµ±ÄãÔÚ¸ÃÁÐÉϲåÈëÒ»NULLֵʱ£¬ NULL×Ô¶¯±»×ª»»ÎªÒ»¸ö±È¸ÃÁÐÖÐ×î´óÖµ´ó1µÄÒ»¸öÕûÊý£¬Èç¹û±íÊǿյģ¬ ½«»áÊÇ1¡£ (Èç¹ûÊÇ×î´ó¿ÉÄܵÄÖ÷¼ü 9223372036854775807£¬ÄǸö£¬½«¼üÖµ½«ÊÇËæ»úδʹÓõÄÊý¡££© È磬ÓÐÏÂÁÐ±í£º
CREATE TABLE t1(
a INTEGER PRIMARY KEY,
b INTEGER
);
ÔڸñíÉÏ£¬ÏÂÁÐÓï¾ä
INSERT INTO t1 VALUES(NULL,123);
ÔÚÂß¼ÉϵȼÛÓÚ£º
INSERT INTO t1 VALUES((SELECT max(a) from t1)+1,123);
ÓÐÒ»¸öеÄAPI½Ð×ö sqlite3_last_insert_rowid()£¬ Ëü½«·µ»Ø×î½ü²åÈëµÄÕûÊýÖµ¡£
×¢Òâ¸ÃÕûÊý»á±È±íÖиÃÁÐÉϵIJåÈë֮ǰµÄ×î´óÖµ´ó1¡£ ¸Ã¼üÖµÔÚµ±Ç°µÄ±íÖÐÊÇΨһµÄ¡£µ«ÓпÉÄÜÓëÒÑ´Ó±íÖÐɾ³ýµÄÖµÖصþ¡£ ÒªÏ뽨Á¢ÔÚÕû¸ö±íµÄÉúÃüÖÜÆÚÖÐΨһµÄ¼üÖµ£¬ÐèÒªÔÚ INTEGER PRIMARY KEY ÉÏÔö¼ÓAUTOINCREMENTÉùÃ÷¡£ÄÇô£¬ÐµļüÖµ½«»á±È¸Ã±íÖÐÔøÄÜ´æÔÚ¹ýµÄ×î´óÖµ´ó1¡£ Èç¹û×î´ó¿ÉÄܵÄÕûÊýÖµÔÚÊý¾Ý±íÖÐÔø¾´æÔÚ¹ý£¬INSERT½«»áʧ°Ü£¬ ²¢·µ»ØSQLITE_FULL´íÎó´úÂë¡£
------------------------------- ......
sqliteÊDz»´íµÄÄÚ´æÊý¾Ý¿â£¬ÄÚ´æÊý¾Ý¿âÊÇ´¦Àí´óÁ¿²¢·¢Êý¾ÝµÄÓÅÏÈÑ¡Ôñ¡£µ«ÓÐЩ´óÁ¿Êý¾ÝµÄ²¢·¢²¢²»ÊÇÊý¾Ý´¦Àí±¾ÉíµÄÎÊÌ⣬ÀýÈçÂß¼ÉϱØÐëÓÐÏȺó´ÎÐòµÄÊý¾ÝÊDz¢·¢ËٶȲ»Äܽâ¾öµÄÎÊÌâ¡£Å׿ªÕâЩÎÊÌâÒ»¸ö¼òµ¥´óÈÝÁ¿µÄ½â¾ö·½°¸ÊÇÓÃÒ»¸öÄÚ´æÊý¾Ý¿â×öÇ°¶ËÒ»¸öÓ²ÅÌÊý¾Ý¿â×öºó¶Ë£¬ÄÚ´æÊý¾Ý¿â¶¨ÆÚ°ÑÊý¾Ýͬ²½µ½ºó¶ËµÄÓ²ÅÌÊý¾Ý¿â¡£Õâ¸ö·½°¸ÓиöÎÊÌâ¾ÍÊÇÈçºÎͬ²½£¬Í¬²½·ÖΪÁ½ÖÖÒ»ÖÖÊǸüкϲ¢£¬Ò»ÖÖÊÇÖ±½Ó¸´ÖÆ¡£¸üкϲ¢ÊÇÖ¸°Ñ¸ü¸Ä¹ýµÄÊý¾ÝÌá½»µ½ºó¶ËÊý¾Ý¿â½øÐкϲ¢£¬Ö±½Ó¸´ÖÆÖ¸ÎÞÂÛÊÇ·ñ¸ü¸Ä¶¼°ÑÕû¸öÊý¾Ý¿âµÄÊý¾Ýͬ²½¹ýÀ´¡£´¦ÀíÕâÁ½ÖÖ·½Ê½µÄ°ì·¨ÊDz»Í¬µÄ£¬¸üкϲ¢¿ÉÒԼǼ¸ü¸ÄÊý¾ÝµÄÖ¸Áî¼òµ¥µÄ¿ÉÒԼǼ¸ü¸ÄµÄ±í£¬¸´ÔӵĿÉÒԼǼ¸ü¸ÄµÄÁÐÉõÖÁÏî¡£µÚÒ»ÖÖ·½Ê½Ö»Òª¼òµ¥µÄÆ¥ÅäsqlÖ¸ÁîºóÒ»ÖÖ·½Ê½ÐèҪģÄâÔËÐС£ÔÚijһʱ¼äµãÉϰѸü¸Ä¹ýµÄ±í¸üе½±¸·ÝÊý¾Ý¿âÉÏ¡£Ö±½Ó¸´ÖƾÍÊÇÎÞÂÛ±íÏîÊÇ·ñ¸ü¸Ä¶¼¸üе½±¸·ÝÊý¾Ý¿â¡£sqliteÓиö¿´ÆðÀ´ÊǸöÎÊÌâµÄÎÊÌ⣬¾ÍÊDz»ÄÜḬ̈߳²È«µÄ²åÈëºÍ¸üС£Õâ¸öÎÊÌâsqliteÔÚlinuxϵͳÉϽâ¾öµÄÊÇÂúºÃµÄʹÓõÄÊÇÓ²ÅÌ·ÖÇøµÄËø¿ÉÒÔºÍsqliteÒ³»º³åϵͳÍêÃÀµÄ½áºÏÔÚÒ»Æð¡£²»¹ýÒªÊÇÄÃsqliteµ±ÄÚ´æÊý¾Ý¿âÍÑÀëÓ²Å̵ÄÎļþϵͳ¿ÖžÍÒª×Ô¼ºÏë°ì·¨½â¾ö¶àÏß³ÌÎÊÌâ¡£²ÅÓÃÈí¼þËø½â¾öḬ̈߳²È« ......
ÕâЩÌìÒ»Ö±ÔÚæÏúÊÛ¹ÜÀíÈí¼þÒ×Âôͨ¿Í»§¶ËµÄ³ÌÐò±àд£¬ÓÉÓÚÐèÒª²ÉÓñ¾µØÊý¾Ý»º´æ»úÖÆÀ´Ìá¸ß³ÌÐòµÄÊý¾Ý·ÃÎÊЧÂÊ£¬ËùÒÔÐèÒªÔÚ¿Í»§¶ËʹÓÃÒ»¸öСÇɵı¾µØÊý¾Ý¿â¡£Õâ¸öÊý¾Ý¿âµ±È»ÒªÐ¡¶ø¾«º·µÄ¡£ÎÒÒ²²»Ïë×öÇ¿µÁ£¬ÓÚÊǾÍÑ¡ÔñSqlite°É——ÎļþÊý¾Ý¿â£¬Ö»ÒªÒ»¸öSqlite.dll¾Í¿ÉÒÔ²Ù×÷Êý¾Ý¿â¡£
²»µÃ²»³ÃÈ˱¾ÈËÊÇÓеã͵ÀÁ£¬Add Nhibernate+ActiveRecord×öO/R mapping£¬Ã²ËÆÕâÑùµÄ¼Ü¹¹ÓÐɱ¼¦ÓÃÅ£µ¶Ö®ÏÓ¡£
×òÌìÅöµ½Ò»¸ö·Ç³£¹ÖÒìµÄÎÊÌ⣬µ±ÎÒµ÷ÓÃActiveRecordBase.FindAllµÄʱºò£¬·µ»ØÒ»¸öÊý×éÄÚ²¿µÄËùÓÐÔªËض¼ÊÇnull¡£
Õâ¾ÍÆæ¹ÖÁË£¬Êý¾Ý¿âÀïÃæÒѾ´æÔÚÊý¾Ý¡£ÓÚÊÇÉÏÍø²é×ÊÁÏ£¬¿´µ½ÓÐÒ»¸ö¼Ò»ï˵²»ÄÜ°ÑPrimary keyÓ³ÉäΪIdentify£¬Ö»ÄÜÓÃNative¡£Ð޸ĺó»¹ÊDz»ÐУ¬TMD£¬ÍøÂçÉϵÄÆ×Ó»¹Õæ²»ÉÙ£¬ÌرðÊǹúÄÚ£¬ºöÓƵÄÈ˶࣬Õæ²ÅʵѧµÄÉÙ£¡
ÓÚÊÇ¿ªÊ¼²âÊÔÆäËû±íµÄFIND¹¦ÄÜ£¬Ò»Çй¤×÷Õý³£¡£¼û¹í£¬DAMN£¡
ÓÚÊÇÓÃ.schÃüÁî²é¿´±íµÄschemaÒìͬ£¬·¢ÏÖ³ýÁËPrimary keyµÄ¶¨ÒåÓÐÒ»µã²î±ðÍ⣬ÎÞÒì³£¡£
ÓÖ¿ªÊ¼»³ÒÉÊDz»ÊÇDLL¼ÓÔØÇé¿ö£¬ÁªÏëµ½ÎĵµËµÒª¼ÓÔØDynamicProxy£¬ÂíÉÏÏÂÔØа汾DynamicProxy¡£»¹ÊDz»¹ÜÓá£
±§×ÅËÀÂíµ±»îÂíÒ½ÊÔÊÔ¿´µÄÐÄ̬£¬ÐÞ¸ÄÁ˱íµÄPrimary Key¶¨Ò壬Ҳ¾ÍÊÇ°ÑÔÀ´Primary k ......
1¡£´Ówww.sqlite.orgÏÂÔØSQLite 3.3.4µÄ°æ±¾
ΪÁË·½±ã£¬ÎÒ°ÑËü½âѹÁË£¬¾ÍÒ»¸öSQLite3.exe£¬·ÅÈëWindowsĿ¼Ï¡£
Cmd ½øÈëÃüÁîÐÐ
1)
´´½¨Êý¾Ý¿âÎļþ:
>SQLite3 d:\test.db »Ø³µ
¾ÍÉú³ÉÁËÒ»¸ötest.dbÔÚdÅÌ¡£
ÕâÑùͬʱҲSQLite3¹ÒÉÏÁËÕâ¸ötest.db
2)
ÓÃ.help¿ÉÒÔ¿´¿´ÓÐʲôÃüÁî
>.help »Ø³µ¼´¿É
3)¿ÉÒÔÔÚÕâÀïÖ±½ÓÊäÈëSQLÓï¾ä´´½¨±í¸ñ ÓÃ;½áÊø£¬È»ºó»Ø³µ¾Í¿ÉÒÔ¿´µ½ÁË
4)¿´¿´Óд´½¨Á˶àÉÙ±í
>.tables
5)¿´±í½á¹¹
>.schema ±íÃû
6)¿´¿´Ä¿Ç°¹ÒµÄÊý¾Ý¿â
>.database
7)Èç¹ûÒª°Ñ²éѯÊä³öµ½Îļþ
>.output ÎļþÃû
> ²éѯÓï¾ä£»
²éѯ½á¹û¾ÍÊä³öµ½ÁËÎļþc:\query.txt
°Ñ²éѯ½á¹ûÓÃÆÁÄ»Êä³ö
>.output stdout
8)°Ñ±í½á¹¹Êä³ö£¬Í¬Ê±Ë÷ÒýÒ²»áÊä³ö
.dump ±íÃû
9)Í˳ö
>.exit »òÕß.quit
2¡£´Óhttp://sqlite.phxsoftware.com/ÏÂÔØAdo.netÇý¶¯¡£
ÏÂÔØÁË°²×°£¬ÔÚ°²×°Ä¿Â¼ÖдæÔÚSystem.Data.SQLite.dll
ÎÒÃÇÖ»ÐèÒª¿½±´Õâ¸öÎļþµ½ÒýÓÃĿ¼£¬²¢Ìí¼ÓÒýÓü´¿É¶ÔSQLiteÊý¾Ý¿â²Ù×÷ÁË
ËùÓеÄAdo.net¶ÔÏó¶¼ÊÇÒÔSQLite¿ªÍ·µÄ£¬±ÈÈçSQLiteConnection
Á¬½Ó´®Ö»ÐèÒªÈçÏ·½Ê½
Data Source=d:\test.db »òÕßDataSource=test.db--Ó¦ÓÃÔÚºÍÓ¦ÓóÌÐ ......
1¡£´Ówww.sqlite.orgÏÂÔØSQLite 3.3.4µÄ°æ±¾
ΪÁË·½±ã£¬ÎÒ°ÑËü½âѹÁË£¬¾ÍÒ»¸öSQLite3.exe£¬·ÅÈëWindowsĿ¼Ï¡£
Cmd ½øÈëÃüÁîÐÐ
1)
´´½¨Êý¾Ý¿âÎļþ:
>SQLite3 d:\test.db »Ø³µ
¾ÍÉú³ÉÁËÒ»¸ötest.dbÔÚdÅÌ¡£
ÕâÑùͬʱҲSQLite3¹ÒÉÏÁËÕâ¸ötest.db
2)
ÓÃ.help¿ÉÒÔ¿´¿´ÓÐʲôÃüÁî
>.help »Ø³µ¼´¿É
3)¿ÉÒÔÔÚÕâÀïÖ±½ÓÊäÈëSQLÓï¾ä´´½¨±í¸ñ ÓÃ;½áÊø£¬È»ºó»Ø³µ¾Í¿ÉÒÔ¿´µ½ÁË
4)¿´¿´Óд´½¨Á˶àÉÙ±í
>.tables
5)¿´±í½á¹¹
>.schema ±íÃû
6)¿´¿´Ä¿Ç°¹ÒµÄÊý¾Ý¿â
>.database
7)Èç¹ûÒª°Ñ²éѯÊä³öµ½Îļþ
>.output ÎļþÃû
> ²éѯÓï¾ä£»
²éѯ½á¹û¾ÍÊä³öµ½ÁËÎļþc:\query.txt
°Ñ²éѯ½á¹ûÓÃÆÁÄ»Êä³ö
>.output stdout
8)°Ñ±í½á¹¹Êä³ö£¬Í¬Ê±Ë÷ÒýÒ²»áÊä³ö
.dump ±íÃû
9)Í˳ö
>.exit »òÕß.quit
2¡£´Óhttp://sqlite.phxsoftware.com/ÏÂÔØAdo.netÇý¶¯¡£
ÏÂÔØÁË°²×°£¬ÔÚ°²×°Ä¿Â¼ÖдæÔÚSystem.Data.SQLite.dll
ÎÒÃÇÖ»ÐèÒª¿½±´Õâ¸öÎļþµ½ÒýÓÃĿ¼£¬²¢Ìí¼ÓÒýÓü´¿É¶ÔSQLiteÊý¾Ý¿â²Ù×÷ÁË
ËùÓеÄAdo.net¶ÔÏó¶¼ÊÇÒÔSQLite¿ªÍ·µÄ£¬±ÈÈçSQLiteConnection
Á¬½Ó´®Ö»ÐèÒªÈçÏ·½Ê½
Data Source=d:\test.db »òÕßDataSource=test.db--Ó¦ÓÃÔÚºÍÓ¦ÓóÌÐ ......
×Ô¼¸Ê®ÄêÇ°³öÏÖµÄÉÌÒµÓ¦ÓóÌÐòÒÔÀ´£¬Êý¾Ý¿â¾Í³ÉΪÈí¼þÓ¦ÓóÌÐòµÄÖ÷Òª×é³É²¿·Ö¡£ÕýÓëÊý¾Ý¿â¹ÜÀíϵͳ·Ç³£¹Ø¼üÒ»Ñù£¬ËüÃÇÒ²±äµÃ·Ç³£ÅӴ󣬲¢Õ¼ÓÃÁËÏ൱¶àµÄϵ
ͳ×ÊÔ´£¬Ôö¼ÓÁ˹ÜÀíµÄ¸´ÔÓÐÔ¡£Ëæ×ÅÈí¼þÓ¦ÓóÌÐòÖð½¥Ä£¿éÄ£¿é»¯£¬Ò»ÖÖÐÂÐÍÊý¾Ý¿â»á±È´óÐ͸´ÔӵĴ«Í³Êý¾Ý¿â¹ÜÀíϵͳ¸üÊÊÓ¦¡£Ç¶ÈëʽÊý¾Ý¿âÖ±½ÓÔÚÓ¦ÓóÌÐò½ø³Ì
ÖÐÔËÐУ¬ÌṩÁËÁãÅäÖã¨zero-configuration£©ÔËÐÐģʽ£¬²¢ÇÒ×ÊÔ´Õ¼Ó÷dz£ÉÙ¡£±¾ÎĽ«½éÉÜÁ÷ÐÐµÄ SQLite
Êý¾Ý¿âÒýÇ棬²¢ÃèÊöÈçºÎÔÚÓ¦ÓóÌÐò¿ª·¢ÖÐʹÓÃËü¡£
SQLite ÊÇ D. Richard Hipp Óà C ÓïÑÔ±àдµÄ¿ªÔ´Ç¶ÈëʽÊý¾Ý¿âÒýÇæ¡£ËüÊÇÍêÈ«¶ÀÁ¢µÄ£¬²»¾ßÓÐÍⲿÒÀÀµÐÔ¡£SQLite
Ö§³Ö¶àÊý SQL92 ±ê×¼£¬¿ÉÒÔÔÚËùÓÐÖ÷ÒªµÄ²Ù×÷ϵͳÉÏÔËÐУ¬²¢ÇÒÖ§³Ö´ó¶àÊý¼ÆËã»úÓïÑÔ¡£SQLite »¹·Ç³£½¡×³¡£Æä´´½¨Õß±£ÊصعÀ¼Æ
SQLite ¿ÉÒÔ´¦ÀíÿÌ츺µ£¶à´ï 100,00 ´Îµã»÷Â浀 Web Õ¾µã£¬²¢ÇÒ SQLite ÓÐʱºò¿ÉÒÔ´¦Àí 10 ±¶ÓÚÉÏÊöÊý×ֵĸºÔØ¡£
SQLiteÊÇÒ»¿îÇáÐ͵ÄÊý¾Ý¿â£¬ÊÇ×ñÊØACIDµÄ¹ØÁªÊ½Êý¾Ý¿â¹ÜÀíϵͳ£¬ËüµÄÉè¼ÆÄ¿±êÊÇǶÈëʽµÄ£¬¶øÇÒÄ¿Ç°ÒѾÔںܶàǶÈëʽ²úÆ·ÖÐʹÓÃÁËËü£¬ËüÕ¼ÓÃ×ÊÔ´
·Ç³£µÄµÍ£¬ÔÚǶÈëʽÉ豸ÖУ¬¿ÉÄÜÖ»ÐèÒª¼¸°ÙKµÄÄÚ´æ¾Í¹»ÁË¡£ËüÄܹ»Ö§³ÖWindows/Linux/UnixµÈµÈÖ÷Á ......
SQLite Tutorial in PHP
SQLite is an SQL database manager used locally or on a website, and compatible
in particularly with PHP.
Summary
Installing SQLite and creating a database
.
Installing SQLite. Verifying the installation by creating a base.
Creating and using a SQLite table
.
Creating a table. Deleting a table. Adding a record. Reading a record.
How to find and update a post
.
Filling a database. Dump of the whole base. Finding a record by ID. Searching a post. Updating a post.
Download
The complete source code of the scripts
in a ZIP archive.
More
SQLite and multi-users. How to treat concurrency issue with SQLite
. ......
SQLite Tutorial in PHP
SQLite is an SQL database manager used locally or on a website, and compatible
in particularly with PHP.
Summary
Installing SQLite and creating a database
.
Installing SQLite. Verifying the installation by creating a base.
Creating and using a SQLite table
.
Creating a table. Deleting a table. Adding a record. Reading a record.
How to find and update a post
.
Filling a database. Dump of the whole base. Finding a record by ID. Searching a post. Updating a post.
Download
The complete source code of the scripts
in a ZIP archive.
More
SQLite and multi-users. How to treat concurrency issue with SQLite
. ......