Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

[ÊÕ£] ÓÃ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ÊÇÕâÒ»Ìõ¼Ç¼ÓжàÉÙ¸ö×ֶΠ(¼´ÕâÌ


Ïà¹ØÎĵµ£º

sqliteʹÓÃ×ܽá1

Ç°Ðò£º... 1
Ò»¡¢ °æ±¾... 1
¶þ¡¢ »ù±¾±àÒë... 2
Èý¡¢ SQLITE²Ù×÷ÈëÃÅ... 2
£¨1£© »ù±¾Á÷³Ì... 2
£¨2£© SQLÓï¾ä²Ù×÷... 4
£¨3£© ²Ù×÷¶þ½øÖÆ... 8
£¨4£© ÊÂÎñ´¦Àí... 10
ËÄ¡¢ ¸øÊý¾Ý¿â¼ÓÃÜ... 10
Îå¡¢ ºó¼Ç... 25
Ç°Ðò£º
Sqlite3 µÄÈ·ºÜºÃÓá£Ð¡ÇÉ¡¢Ëٶȿ졣µ«ÊÇÒòΪ·Ç΢ÈíµÄ²úÆ·£¬°ïÖúÎĵµ×ܾõµÃ²»¹» ......

sqliteʹÓÃ×ܽá3

£¨4£©              ÊÂÎñ´¦Àí
sqlite ÊÇÖ§³ÖÊÂÎñ´¦ÀíµÄ¡£Èç¹ûÄãÖªµÀÄãҪͬ²½É¾³ýºÜ¶àÊý¾Ý£¬²»·Â°ÑËüÃÇ×ö³ÉÒ»¸öͳһµÄÊÂÎñ¡£
ͨ³£Ò»´Î sqlite3_exec ¾ÍÊÇÒ»´ÎÊÂÎñ£¬Èç¹ûÄãҪɾ³ý1ÍòÌõÊý¾Ý£¬sqlite¾Í×öÁË1Íò´Î£º¿ªÊ¼ÐÂÊÂÎñ->ɾ³ýÒ»ÌõÊý¾Ý->Ìá½»ÊÂÎ ......

SQLite¼ò½é

1¡¢SQLite¼ò½é
¡¡¡¡SQLiteµÚÒ»¸öAlpha°æ±¾µ®ÉúÓÚ2000Äê5ÔÂ. ÖÁ½ñÒѾ­ÓÐ4¸öÄêÍ·ÁË. SQLiteÒ²Ó­À´ÁËÒ»¸ö°æ±¾ SQLite 3ÒѾ­·¢²¼.
¡¡
¡¡SQLiteÊÇÒ»¿îÇáÐ͵ÄÊý¾Ý¿â£¬ÊÇ×ñÊØACIDµÄ¹ØÁªÊ½Êý¾Ý¿â¹ÜÀíϵͳ£¬ËüµÄÉè¼ÆÄ¿±êÊÇǶÈëʽµÄ£¬¶øÇÒÄ¿Ç°ÒѾ­ÔںܶàǶÈëʽ²úÆ·ÖÐʹÓÃÁËËü£¬ËüÕ¼ÓÃ×Ê
Ô´·Ç³£µÄµÍ£¬ÔÚǶÈëʽÉ豸ÖУ¬¿ÉÄÜÖ»ÐèÒª ......

sqlite´úÂëµÄ±àд

 ÏÂÔØ´úÂë
È¡µÃÒ»·Ý¶þ½øÖÆ¿½±´, »òÕßÊÇÔ´´úÂë²¢×Ô¼º±àÒëËü. ¹ØÓÚ ÏÂÔØÒ³£¨download£© µÄ¸ü¶àÐÅÏ¢.
´´½¨Ò»¸öÐÂÊý¾Ý¿â
ÔÚ DOS ÃüÁîÐÐÏÂ, ÊäÈë: "sqlite3 test.db". ½«´´½¨Ò»¸öеÄÊý¾Ý¿âÎļþÃû½Ð"test.db". (Äã¿ÉÒÔʹÓò»Í¬µÄÃû×Ö)
ÊäÈë SQL ÃüÁîÔÚÌáʾ·ûÏ´´½¨ºÍдÈëеÄÊý¾Ý.
д³ÌÐòʹÓà SQLite
ÏÂÃæÊÇÒ»¸ö¼òµ¥µ ......

sqlceÓësqliteÊý¾Ý¿âµÄ±È½Ï

×î½üÓÉÓÚÏîÄ¿ÐèÒª£¬ ÒªÔÚwince4.2, wince5.0, mobileÈýÖÖ»úÐÍÉÏÃæ×ö´óÊý¾ÝÁ¿µÄ²éѯ£¬³õ²½¹À¼ÆÔÚ50W-500WÌõ¼Ç¼֮¼ä¡£
ÓÉÓÚÒÔÇ°×ömobile5µÄÊý¾Ý¿âÏîÄ¿Ö÷ÒªÊDzÉÓÃC#À´Ð´£¬¶øÇÒÊý¾ÝÁ¿Ò²¶¥¶à¼¸ÍòÌõ£¬ËùÒÔ£¬ÎªÁËÈ·±£ÏîÄ¿ºóÆÚÉÙ×ßÍä·£¬ÎÒÌØÒâ×öÁËÒ»ÏÂÒƶ¯Êý¾Ý¿âÐÔÄܲâÊÔ¡£ÏÂÃæÊÇÕâÖܵŤ×÷¼Ç¼¡£¹©´ó¼Ò²Î¿¼¡£
Ò». ÓÉÓÚwince4.2 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ