`
keren
  • 浏览: 1558119 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

flash SQLite包装类

 
阅读更多
[转]http://www.flepstudio.com/flash/actionscript3/documentation/html/com_flepstudio_air_sqlite_SQLite.html
package com.flepstudio.air.sqlite
{
    import flash.data.*;
    import flash.events.*;
    import flash.filesystem.File;
    import flash.display.MovieClip;
     
    [Event(name="open", type="flash.events.SQLEvent")]
    [Event(name="close", type="flash.events.SQLEvent")]
    [Event(name="error", type="flash.events.SQLErrorEvent")]
     
    /**
     * SQLite is a ValueObject for the FlepStudio API.
     * This class manages the SQLite database in Adobe Air
     *
     * @author Filippo Lughi
     * @version Actionscript 3.0
     */
    public class SQLite extends MovieClip
    {
        private var _connection:SQLConnection;
        private var _databaseFileName:String;    
        private var _databaseFile:File;
        private var _statement:SQLStatement;
         
        public function SQLite()
        {
            addEventListener(Event.ADDED_TO_STAGE,init);
        }
         
        private function init(evt:Event):void
        {
            removeEventListener(Event.ADDED_TO_STAGE,init);
            trace("I am ready to dispatch events to my parent/root");
        }
         
         
        /**
         * get the database file name
         */
        [Bindable]
        public function get file_name():String
        {
            return _databaseFileName;
        }
         
         
        /**
         * set the database file name
         */
        public function set file_name(s:String):void
        {
            _databaseFileName=s;
        }
         
         
        /**
         * get the database file
         */
        public function get file():File
        {
            return _databaseFile;
        }
         
         
        /**
         * set the database file
         */
        public function set file(f:File):void
        {
            _databaseFile=File.documentsDirectory.resolvePath(file_name);
        }
         
         
        /**
         * get the database connection
         */
        [Bindable]
        public function get connection():SQLConnection
        {
            return _connection;
        }        
         
         
        /**
         * set the database connection
         */
        public function set connection(conn:SQLConnection):void
        {
            _connection=conn;
        }
         
         
        /**
         * get the statement
         */
        [Bindable]
        public function get statement():SQLStatement
        {
            return _statement;
        }        
         
         
        /**
         * set the statement
         */
        public function set statement(s:SQLStatement):void
        {
            _statement=s;
        }
         
         
        /**
         * connect to database
         */
        public function connect():void
        {
            _connection=new SQLConnection();
            _connection.addEventListener(SQLEvent.OPEN,onDatabaseOpen);
            _connection.addEventListener(SQLEvent.CLOSE,onDatabaseClose);
            _connection.addEventListener(SQLErrorEvent.ERROR,onDatabaseError);
            _connection.openAsync(_databaseFile,SQLMode.READ);
        }
         
         
        /**
         * create the database
         */
        public function create():void
        {
            _connection=new SQLConnection();
            _connection.addEventListener(SQLEvent.OPEN,onDatabaseCreated);
            _connection.addEventListener(SQLEvent.CLOSE,onDatabaseClose);
            _connection.addEventListener(SQLErrorEvent.ERROR,onDatabaseError);
            _connection.openAsync(_databaseFile,SQLMode.CREATE);
        }
         
         
        /**
         * populate the database
         */
        public function execute(query:String=null):void
        {
            _statement=new SQLStatement();
            _statement.sqlConnection=_connection;
            _statement.text=query;
            _statement.addEventListener(SQLEvent.RESULT,onQueryResult);
            _statement.addEventListener(SQLErrorEvent.ERROR,onQueryError);
            _statement.execute();
        }
         
         
        /**
         * disconnect to database
         */
        public function close():void
        {
            _connection.close();
        }
         
         
        /**
         * dispatch when query has been done
         */
        private function onQueryResult(evt:SQLEvent):void
        {
            trace(_statement.getResult().data);
            dispatchEvent(evt);
        }
         
         
        /**
         * dispatch if a query error occurs
         */
        private function onQueryError(evt:SQLErrorEvent):void
        {
            dispatchEvent(evt);
        }
         
         
        /**
         * dispatch when database is open
         */
        private function onDatabaseOpen(evt:SQLEvent):void
        {
            _connection.removeEventListener(SQLEvent.OPEN,onDatabaseOpen);
            dispatchEvent(evt);
        }
         
         
        /**
         * dispatch when database is created
         */
        private function onDatabaseCreated(evt:SQLEvent):void
        {
            _connection.removeEventListener(SQLEvent.OPEN,onDatabaseCreated);
            dispatchEvent(new SQLEvent("created"));
        }
         
         
        /**
         * dispatch when database is close
         */
        private function onDatabaseClose(evt:SQLEvent):void
        {
            _connection.removeEventListener(SQLEvent.CLOSE,onDatabaseClose);
            dispatchEvent(evt);
        }
         
         
        /**
         * dispatch a database error
         */
        private function onDatabaseError(evt:SQLErrorEvent):void
        {
            _connection.removeEventListener(SQLErrorEvent.ERROR,onDatabaseError);
            dispatchEvent(evt);
        }
    }
}
分享到:
评论

相关推荐

    SQLite_Wrapper_SQLite_C++包装类

    SQLite_Wrapper_SQLite_C++包装类

    SQLite帮助类SQLiteHelper

    一些小型的应用程序需要使用到数据库,sqlite可以说是最好的选择。这里个人整理了一般简单通用的操作类SQLiteHelper

    android数据库SQLite通用类

    通用的SQLite数据库操作类,将增删改查集成,其他继承该类即可

    sqlite帮助类 SqliteHelper.cs

    是使用sqlite封装好的帮助类 ,有执行sql语句和执行带参数的sql语句及一次执行多条(事务)及执行带存储过程参数的的SQL语句等基础操作。

    C#操作SQLITE代码类

    C#操作SQLite代码类 一个朋友写的,拿来分享给大家,希望有用

    Sqlite 操作类 C# .net

    Sqlite 操作类 C# .net,嵌入式SQL //创建一个数据库文件 string datasource = @"d:/ChinaPower.s3db"; // System.Data.SQLite.SQLiteConnection.CreateFile(datasource); //连接数据库 System.Data....

    SQLiteHelper辅助类

    SQLiteHelper的辅助类,共四种,需要的朋友拿去参考。

    易语言Sqlite数据库类模块

    易语言Sqlite数据库类模块源码,Sqlite数据库类模块,初始化_SQLITE,销毁_SQLITE,添加纪录_批量,添加纪录,读取记录_单个字段_文本值,读取记录_多个字段,修改记录,删除记录,取记录集,填充记录们to超级列表框,分页_初始...

    delphi封装的sqlite3类

    SQLite3.pas SQLiteTable3.pas

    Android Sqlite操作类(原创)

    现用项目中Sqlite操作类, 1.数据库初始化 2.数据库版本升级 3.从表中查询数据,并返回ArrayList,简单操作不需要建类 4.单一行查询返回、int 返回、string查询返回

    Sqlite的C#通用类和Sqlite工具

    Sqlite的C#通用类和Sqlite工具(SQLiteExpertPersSetup.exe),直接使用

    c++ sqlite帮助类

    自己编写的一个c++ 版sqlite数据库访问帮助类,主要对sqlite的常用的几个接口函数进行封装成一个类,实现查询、事务处理等基本数据库访问应用,简单,好用,希望对大家有用,注意传人的参数是stl 的string 类型,...

    Android开发中的SQLite数据库的增删改查工具类

    手写简化适用于安卓开发中的SQLite数据库工具类,包含数据的增删改查,适用于各个需要本地数据库开发。

    SQLite数据库访问类

    数据库SQLite访问类,自己测试过,没问题,包含事物处理,操作方便。

    SqliteHelper sqlite数据库 公共帮助类

    SqliteHelper sqlite数据库 公共帮助类,提供各种操作数据库方法,从而简单的对数据库数据进行操作

    CppSqlite Sqlite封装类

    CppSqlite是一个封装了Sqlite操作的类,极其方便了开发者操作sqlite

    操作sqlite的封装类

    基于sqlite3 api封装了操作类:SqliteConnect(连接类)SqliteQuery(查询类)SqliteRecord(记录集类)Value(值转换类)

    sqlite3封装类

    很多年前写的一个sqlite通用类模块。该资源只包含sqldb.cpp和sqldb.h两个文件。sqllite3源码可从官方网下载。 封装该类的目的:统一sqlite数据库接口,以方便windows/linux平台间使用sqlite数据库。 该类封装了...

    SQLite3数据库操作类1.66

    SQLite3数据库操作类1.66

Global site tag (gtag.js) - Google Analytics