[ÊÕ£]
ÓÃsqlite Ö´Ðбê×¼ sql Óï·¨
http://www.umgr.com/blog/PostView.aspx?bpId=36294
1. Ö´ÐÐsqlÓï¾ä
int sqlite3_exec(sqlite3*£¬ const char *sql£¬ sqlite3_callbacksql Óï·¨
£¬ void *£¬ char **errmsg );
Õâ¾ÍÊÇÖ´ÐÐÒ»Ìõ sql Óï¾äµÄº¯Êý¡£
µÚ1¸ö²ÎÊý²»ÔÙ˵ÁË£¬ÊÇÇ°Ãæopenº¯ÊýµÃµ½µÄÖ¸Õ롣˵ÁËÊǹؼüÊý¾Ý½á¹¹¡£
µÚ2¸ö²ÎÊýconst char *sql ÊÇÒ»Ìõ sql Óï¾ä£¬ÒÔ\0½áβ¡£
µÚ3¸ö²ÎÊýsqlite3_callback Êǻص÷£¬µ±ÕâÌõÓï¾äÖ´ÐÐÖ®ºó£¬sqlite3»áÈ¥µ÷ÓÃÄãÌṩµÄÕâ¸öº¯Êý¡£
µÚ4¸ö²ÎÊývoid * ÊÇÄãËùÌṩµÄÖ¸Õësql Óï·¨
£¬Äã¿ÉÒÔ´«µÝÈκÎÒ»¸öÖ¸Õë²ÎÊýµ½ÕâÀÕâ¸ö²ÎÊý×îÖջᴫµ½»Øµ÷º¯ÊýÀïÃ棬Õâ¸öÖ¸Õë±È½ÏÖØÒª£¬¿ÉÒÔÓÃÀ´×÷²ÎÊýµÄ´«µÝ¡£Èç¹û²»ÐèÒª´«µÝÖ¸Õë¸ø»Øµ÷º¯Êý£¬¿ÉÒÔÌîNULL¡£µÈÏÂÎÒÃÇÔÙ¿´»Øµ÷º¯ÊýµÄд·¨£¬ÒÔ¼°Õâ¸ö²ÎÊýµÄʹÓá£
µÚ
5 ¸ö²ÎÊýchar ** errmsg ÊÇ´íÎóÐÅÏ¢¡£×¢ÒâÊÇÖ¸ÕëµÄÖ¸Õë¡£sqlite3ÀïÃæÓкܶà¹Ì¶¨µÄ´íÎóÐÅÏ¢¡£Ö´ÐÐ sqlite3_exec
Ö®ºó£¬Ö´ÐÐʧ°Üʱ¿ÉÒÔ²éÔÄÕâ¸öÖ¸Õ루ֱ½Ó
printf(“%s\n”£¬errmsg)£©µÃµ½Ò»´®×Ö·û´®ÐÅÏ¢£¬Õâ´®ÐÅÏ¢¸æËßÄã´íÔÚʲôµØ·½¡£sqlite3_execº¯Êýͨ¹ýÐÞ¸ÄÄã´«ÈëµÄÖ¸ÕëµÄÖ¸
Õ룬°ÑÄãÌṩµÄÖ¸ÕëÖ¸Ïò´íÎóÌáʾÐÅÏ¢£¬ÕâÑùsqlite3_execº¯ÊýÍâÃæ¾Í¿ÉÒÔͨ¹ýÕâ¸ö char*µÃµ½¾ßÌå´íÎóÌáʾ¡£
˵Ã÷£ºÍ¨³££¬
sqlite3_callback ºÍËüºóÃæµÄ void * ÕâÁ½¸öλÖö¼¿ÉÒÔÌî NULL¡£ÌîNULL±íʾÄã²»ÐèÒª»Øµ÷¡£±ÈÈçÄã×ö insert
²Ù×÷£¬×ö delete ²Ù×÷£¬¾ÍûÓбØҪʹÓûص÷¡£¶øµ±Äã×ö select ʱ£¬¾ÍҪʹÓûص÷£¬ÒòΪ sqlite3
°ÑÊý¾Ý²é³öÀ´£¬µÃͨ¹ý»Øµ÷¸æËßÄã²é³öÁËʲôÊý¾Ý¡£
2.exec µÄ»Øµ÷
typedef int (*sqlite3_callback)(void*£¬int£¬char**£¬ char**);
ÄãµÄ»Øµ÷º¯Êý±ØÐ붨Òå³ÉÉÏÃæÕâ¸öº¯ÊýµÄÀàÐÍ¡£ÏÂÃæ¸ø¸ö¼òµ¥µÄÀý×Ó£º
// sqlite ÿ²éµ½Ò»Ìõ¼Ç¼£¬¾Íµ÷ÓÃÒ»´ÎÕâ¸ö»Øµ÷
int LoadMyInfo( void * para£¬ int n_column£¬ char ** column_value£¬ char ** column_name )
{
//paraÊÇÄãÔÚ sqlite3_exec Àï´«ÈëµÄ void * ²ÎÊý
//ͨ¹ýpara²ÎÊý£¬Äã¿ÉÒÔ´«ÈëһЩÌØÊâµÄÖ¸Õ루±ÈÈçÀàÖ¸Õë¡¢½á¹¹Ö¸Õ룩£¬È»ºóÔÚÕâÀïÃæÇ¿ÖÆת»»³É¶ÔÓ¦µÄÀàÐÍ£¨ÕâÀïÃæÊÇvoid*ÀàÐÍ£¬±ØÐëÇ¿ÖÆת»»³ÉÄãµÄÀàÐͲſÉÓã©¡£È»ºó²Ù×÷ÕâЩÊý¾Ý
//n_columnÊÇÕâÒ»Ìõ¼Ç¼ÓжàÉÙ¸ö×ֶΠ(¼´ÕâÌ
Ïà¹ØÎĵµ£º
SQL-92ÌØÐÔ·½Ãæ
ÕýÈçÇ°ÃæÌáµ½µÄ£¬SQLite²»Ö§³ÖSQL-92µÄÔںܶàÆóÒµÊý¾Ý¿âϵͳÖпÉÓõÄһЩÌØÐÔ¡£
È磺
Íâ¼üÔ¼Êø£¨¿É½âÎöµÄ£¬µ«·ÇÇ¿ÖÆ£©
ºÜ¶àALTER TABLEÌØÐÔ
һЩTRIGGERÏà¹ØµÄÌØÐÔ
RIGHTºÍFULL OUTER JOIN
¸üÐÂÒ»¸öVIEW
GRANTºÍREVOKE
Äã¿ÉÒÔÔÚSQLiteµÄÖ÷Ò³ÉÏ»ñÈ¡×îÐÂÐÅÏ¢¡£
http://www.sqlite.org/omitted.html
......
Ç°Ðò£º... 1
Ò»¡¢ °æ±¾... 1
¶þ¡¢ »ù±¾±àÒë... 2
Èý¡¢ SQLITE²Ù×÷ÈëÃÅ... 2
£¨1£© »ù±¾Á÷³Ì... 2
£¨2£© SQLÓï¾ä²Ù×÷... 4
£¨3£© ²Ù×÷¶þ½øÖÆ... 8
£¨4£© ÊÂÎñ´¦Àí... 10
ËÄ¡¢ ¸øÊý¾Ý¿â¼ÓÃÜ... 10
Îå¡¢ ºó¼Ç... 25
Ç°Ðò£º
Sqlite3 µÄÈ·ºÜºÃÓá£Ð¡ÇÉ¡¢Ëٶȿ졣µ«ÊÇÒòΪ·Ç΢ÈíµÄ²úÆ·£¬°ïÖúÎĵµ×ܾõµÃ²»¹» ......
SQLiteÊÇÒ»¿îÇáÐ͵ÄÊý¾Ý¿â£¬ÊÇ×ñÊØACIDµÄ¹ØÁªÊ½Êý¾Ý¿â¹ÜÀíϵͳ£¬ËüµÄÉè¼ÆÄ¿±êÊÇǶÈëʽµÄ£¬¶øÇÒÄ¿Ç°ÒѾÔںܶàǶÈëʽ²úÆ·ÖÐʹÓÃÁËËü£¬ËüÕ¼ÓÃ×ÊÔ´·Ç³£µÄµÍ£¬ÔÚǶÈëʽÉ豸ÖУ¬¿ÉÄÜÖ»ÐèÒª¼¸°ÙKµÄÄÚ´æ¾Í¹»ÁË¡£ËüÄܹ»Ö§³ÖWindows/Linux/UnixµÈµÈÖ÷Á÷µÄ²Ù×÷ϵͳ£¬Í¬Ê±Äܹ»¸úºÜ¶à³ÌÐòÓïÑÔÏà½áºÏ£¬±È ......
תÔØʱÇë×¢Ã÷³ö´¦ºÍ×÷ÕßÁªÏµ·½Ê½£ºhttp://blog.csdn.net/absurd
×÷ÕßÁªÏµ·½Ê½£ºLi XianJing <xianjimli at hotmail dot com>
¸üÐÂʱ¼ä£º2006-12-19
SqliteÊÇÒ»¸öÓÃCÓïÑÔʵÏÖµÄСÐÍSQLÊý¾Ý¿âÒýÇæ¡£ËüÌå»ýСÇɵ«¹¦ÄÜÇ¿´ó£¬¶ÔÓ²¼þ×ÊÔ´ÒªÇóºÜµÍ¶øÇÒÐÔÄܱíÏÖ׿Խ£¬·Ç³£ÊʺÏÓÚǶÈëʽӦÓû·¾³¡£×î½ü·¢ÏÖsqlite²¢²»Ö§³ÖÖÐÎ ......
Åжϱí´æÔڵķ½·¨ºÜ¼òµ¥,ÍøÉϺܶà:
SELECT COUNT(*) from sqlite_master where type='table' and name='%s'" % tname;
ÄÇôÅжÏ×Ö¶ÎÊÇ·ñ´æÔÚ, »òÕß˵ÈçºÎÅжϱíµÄ°æ±¾ÊÇ·ñ×îоÍÖ»ÐèÒª:
select * from sqlite_master where tbl_name='tblContactList';
sqlite_master µÄ±í½á¹¹ÈçÏÂ:
type |name  ......