[ÊÕ£]
ÓÃ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ÊÇÕâÒ»Ìõ¼Ç¼ÓжàÉÙ¸ö×ֶΠ(¼´ÕâÌ
Ïà¹ØÎĵµ£º
  ......
Ê×ÏÈÉùÃ÷£ºÈç¹ûÄãÏëÖ±½Óalter£¬·ÅÆú°É¡£ÒÔÏÂÄÚÈÝ¿ÉÒÔºöÂÔÁË¡£
sqlite¹Ù·½ËµÃ÷ÈçÏ£º
SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE command in SQLite allows the user to rename a table or to add a new column to an existing table. It is not possible to rename a column, remove a column, o ......
SQLiteºÍÆäËû´ó²¿·ÖÏÖ´úSQLÊý¾Ý¿âÔÚ»ù±¾Éè¼ÆÄ¿±êÉÏÊDz»Í¬µÄ£¬ËüµÄÄ¿±êÊǼòµ¥¡£SQLite×ñÑÕâһĿ±ê£¬¼´Ê¹ÕâÑùż¶û»áµ¼ÖÂijЩÌØÐÔʵÏֵĵÍЧ»¯¡£ÏÂÃæÁоÙÁËSQLiteµÄһЩȱÏÝ£º
SQL-92ÌØÐÔ·½Ãæ
ÕýÈçÇ°ÃæÌáµ½µÄ£¬SQLite²»Ö§³ÖSQL-92µÄÔںܶàÆóÒµÊý¾Ý¿âϵͳÖпÉÓõÄһЩÌØÐÔ¡£
È磺
Íâ¼üÔ¼Êø£¨¿É½âÎöµÄ£¬µ«·ÇÇ¿ÖÆ£©
ºÜ¶àALT ......
Ö÷Ҫͨ¹ýpragmaÖ¸ÁîÀ´ÊµÏÖ¡£
±ÈÈ磺 ¿Õ¼äÊÍ·Å¡¢´ÅÅÌͬ²½¡¢Cache´óСµÈ¡£
²»Òª´ò¿ª¡£Ç°ÎÄÌá¸ßÁË£¬VacuumµÄЧÂʷdz£µÍ£¡
PRAGMA auto_vacuum;
PRAGMA auto_vacuum = 0 | 1;
²éѯ»òÉèÖÃÊý¾Ý¿âµÄauto-vacuum±ê¼Ç¡£
Õý³£Çé¿öÏ£¬µ±Ìá½»Ò»¸ö´ÓÊý¾Ý¿âÖÐɾ³ýÊý¾ÝµÄÊÂÎñʱ£¬Êý¾Ý¿âÎļþ²»¸Ä±ä´óС¡£Î´Ê¹ÓõÄÎļþÒ³±»±ê¼Ç²¢ÔÚÒÔ ......
ÕâÊÇÒ»¸öÓйطÖÒ³µÄʵÀý,½ö¹©²Î¿¼(´úÂëÀ´×ÔÍøÂç)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using System.Threading;
using System.Collections;
us ......