加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flash SQLite包装类

发布时间:2020-12-15 06:51:56 所属栏目:百科 来源:网络整理
导读:[转] 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.M
[转] 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,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);
        }
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读