SQLiteµÄ·â×°Àà
package
{
import flash.data.SQLConnection;
import flash.data.SQLResult;
import flash.data.SQLStatement;
import flash.errors.SQLError;
import flash.events.SQLErrorEvent;
import flash.events.SQLEvent;
import flash.filesystem.File;
import mx.collections.ArrayCollection;
public class DBUtil
{
/**
* Êý¾Ý¿â²Ù×÷Àà±ð
**/
private const typeArr:Array = ['select','insert','update','delete','create','alter','drop'];
/**
* Á¬½Ó
**/
private var conn:SQLConnection;
/**
* ÉùÃ÷
**/
private var stmt:SQLStatement;
/**
* ½á¹û¼¯ºÏ
**/
private var rsAC:ArrayCollection;
public function DBUtil()
{
}
/**
* »ñµÃÁ¬½Ó
**/
private function getConn():SQLConnection
{
if(this.conn == null){
conn = new SQLConnection();
conn.addEventListener(SQLEvent.OPEN, sqlOpen);
conn.addEventListener(SQLErrorEvent.ERROR, sqlError);
}
return this.conn;
}
/**
* ¹Ø±ÕÁ¬½Ó
**/
private function closeConn():void
{
if(this.conn != null){
this.conn.close();
this.conn = null;
}
}
/**
* »ñµÃÉùÃ÷
**/
private function getStatement():SQLStatement
{
if(this.stmt == null)
{
stmt = new SQLStatement();
stmt.sqlConnection = getConn();
stmt.addEventListener(SQLErrorEvent.ERROR, sqlError);
}
return this.stmt;
}
/**
* ¹Ø±ÕÉùÃ÷
**/
private functio
Ïà¹ØÎĵµ£º
±¾ÆªÎÄÕÂÀ´Ô´ÓÚ£º¿ª·¢Ñ§Ôº http://edu.codepub.com ÔÎÄÁ´½Ó£ºhttp://edu.codepub.com/2009/0825/14358.php
SQLiteÊǸöµäÐ͵ÄǶÈëʽDBMS£¬ËüÓкܶàÓŵ㣬ËüÊÇÇáÁ¿¼¶µÄ£¬ÔÚ±àÒëÖ®ºóºÜС£¬ÆäÖÐÒ»¸öÔÒò¾ÍÊÇÔÚ²éѯÓÅ»¯·½Ãæ±È½Ï¼òµ¥£¬ËüÖ»ÊÇÔËÓÃË÷Òý»úÖÆÀ´½øÐÐÓÅ»¯µÄ£¬¾¹ý¶ÔSQLiteµÄ²éѯÓÅ»¯µÄ·ÖÎöÒÔ¼°¶ÔÔ´´úÂëµÄ ......
1£º´ÓsqliteµÄ¹ÙÍøÉÏÏÂÔØÔ´Âë http://www.sqlite.org/download.html
2£º´ò¿ªvs2008¹¤³Ìн¨Ò»¸ö¿ÕµÄdll¹¤³Ì¡£
3£º°Ñsqlite3.h,sqlite3.cpp,sqlite3.def·Ö±ð¼ÓÈëµ½head file ºÍsource fileÏ¡£
4£º±àÒë³ÌÐò¡£ ÕâʱֻÄܵõ½sqlite3.dllÎļþ¡£
5£º´ò¿ªvs2008×Ô´øµÄÃüÁîÐУº Çе½sqlite3.defËùÔÚµÄĿ¼¡£
6£ºÔËÐÐ ......
Ç°Á½ÆªÈÕÖ¾ÎÒÒѾ×ܽáÁ˱¾µØÊý¾Ý´æ´¢µÄÇ°Á½ÖÖ£ºÎļþºÍÅäÖÃÏî¡£»¹Ê£ÏÂ×îºóÒ»ÖÖÊý¾Ý¿â´æ´¢——SQLite¡£
Ò»¡¢SQLite¼ò½é
ÔÚAndroidƽ̨ÉÏ£¬¼¯³ÉÁËÒ»¸öǶÈëʽ¹ØϵÐÍÊý¾Ý¿â—SQLite£¬SQLite3Ö§³Ö NULL¡¢INTEGER¡¢REAL£¨¸¡µãÊý×Ö£©¡¢TEXT(×Ö·û´®Îı¾)ºÍBLOB(¶þ½øÖƶÔÏó)Êý¾ÝÀàÐÍ£¬ËäÈ»ËüÖ§³ÖµÄÀàÐÍËäȻֻÓÐÎåÖÖ ......
ÊÂÎñ£¨DbTransaction£©£º
SQLite ȱʡΪÿ¸ö²Ù×÷Æô¶¯Ò»¸öÊÂÎñ£¬ËùÒÔ³ÉÅú²åÈëµÄʱºò£¬Æô¶¯ÊÂÎñ£¬±È²»Æô¶¯ÊÂÎñ¿ìn±¶¡£
ÔÚûÆô¶¯ÊÂÎñ֮ǰÍùSqliteÊý¾Ý¿âÀï²åÈë1000¶àÌõÊý¾ÝµÄÇé¿ö,½á¹ûÿ´Î¶¼ÐèÒªÒ»Á½·ÖÖÓ²ÅÄÜÍê³É.
¶øÔÚÆô¶¯ÊÂÎïÒÔºóËùÐèÒªµÄʱ¼äÖ±½Ó±ä³É²»µ½2Ãë!ÔÀ´sqlite»¨Á½·ÖÖÓÊÇÓÉÓÚExecuteNonQuery·½·¨Ö´ÐÐʱ×Ô¼ºÌá½» ......
@ǶÈëʽ¹ØϵÐÍÊý¾Ý¿âSQLite
Ìصã
1.Ö§³ÖÎåÖÖÊý¾ÝÀàÐÍ null,INTEGER,REAL(¸¡µãÊý),TEXT(×Ö·û´®Îı¾)ºÍBLOB£¨¶þ½øÖÆÎı¾£©Êý¾ÝÀàÐÍ£¬ËäÈ»
ËüÖ»ÓÐÎåÖÖ£¬µ«Êµ¼ÊÉÏsqlite3Ò²½ÓÊÖvarcher(n),char(n),decimal(p,s)µÈÊý¾ÝÀàÐÍ£ ......