闪光CS4+ SQLITE

发布于 2024-08-21 16:44:51 字数 140 浏览 8 评论 0原文

我正在寻找一些有关在 Flash CS4 中使用 SQLITE 和 AIR 的信息,我找不到任何好的示例,它们都是为 Flex 构建的(我不想使用它)。谁能给我一些如何使用 Flash CS4 执行此操作的基本示例,或者指导我一些代码示例/教程?我到处都找不到...

I'm looking for some information regarding using SQLITE with AIR in Flash CS4, I cannot find any good examples, they're all built for Flex (which I don't want to use). Can anyone give me some basic examples of how to do this with Flash CS4 or direct me to some code examples / tutorials? I cannot find any anywhere...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬心 2024-08-28 16:44:51

以下是一个示例: http://www.flashmove.com/forum/ showthread.php?t=34778

import flash.data.SQLResult;
import flash.filesystem.File;
import flash.data.SQLStatement;
import flash.data.SQLConnection;
import flash.data.SQLColumnSchema;
import flash.data.SQLTableSchema;
import flash.data.SQLSchemaResult;
import flash.events.SQLEvent;
import flash.events.SQLErrorEvent;
import flash.events.MouseEvent;


var sqlFile:File;
var sqlConn:SQLConnection;
var sqlStatement:SQLStatement;
init();
//- BUTTONS
go_mc.buttonMode = true;
go_mc.addEventListener(MouseEvent.MOUSE_DOWN, runQuery)
readDB_mc.buttonMode = true;
readDB_mc.addEventListener(MouseEvent.MOUSE_DOWN, readDB)

var exampleQuery:String = "INSERT INTO users (First_Name, Last_Name) VALUES ('Betty', 'Boil')";
query_txt.text = exampleQuery;


/**
 * Setup connection to db file
 */
function init():void {
    sqlConn = new SQLConnection();
    sqlConn.addEventListener(SQLEvent.OPEN, connOpenHandler);
    sqlConn.addEventListener(SQLErrorEvent.ERROR, errorHandler);

    sqlFile = new File(File.applicationDirectory.nativePath);
    sqlFile = sqlFile.resolvePath("users.db");
    feedback("Path to db file: "+sqlFile.nativePath);

    sqlConn.open(sqlFile);
}

function connOpenHandler(event:SQLEvent):void {
    feedback("DB Open");
    sqlStatement = new SQLStatement();
    sqlStatement.sqlConnection = sqlConn;
    sqlStatement.addEventListener(SQLErrorEvent.ERROR, errorHandler);

    dbScheme();
    readDB();
}

/**
 * Output the DB structure
 */
function dbScheme() {
    feedback("Schema...");
    sqlConn.loadSchema();
    var result:SQLSchemaResult = sqlConn.getSchemaResult();

    var table:SQLTableSchema = result.tables[0];
    //var column:SQLColumnSchema = table.columns[0]
    feedback("\tTable: "+table.name)
    for (var i=0; i<table.columns.length; i++) {
        feedback("\tColumn "+i+" - "+table.columns[i].name);
    }
}
/**
 * Output DB contents
 */
function readDB(e:Event = null) {
    sqlStatement.addEventListener(SQLEvent.RESULT, selectResultHandler);
    sqlStatement.text = "SELECT * FROM users";
    sqlStatement.execute();
}

/**
 * Run custom query
 */
function runQuery(e:MouseEvent) {
    var sqlQuery:String = query_txt.text;
    feedback("Query: "+sqlQuery);

    sqlStatement.addEventListener(SQLEvent.RESULT, queryResultHandler);
    sqlStatement.text = sqlQuery;
    sqlStatement.execute();
}
function queryResultHandler(e:SQLEvent){
    sqlStatement.removeEventListener(SQLEvent.RESULT, queryResultHandler);
    readDB();
}
/**
 * Handle readDB (SELECT) query
 */
function selectResultHandler(event:SQLEvent):void {
    feedback("Query Results...");
    sqlStatement.removeEventListener(SQLEvent.RESULT, selectResultHandler);

    var result:SQLResult = sqlStatement.getResult();

    if (result.data != null) {
        var numRows:int = result.data.length;
        for (var i:int = 0; i < numRows; i++) {
            var row:Object = result.data[i];
            feedback("\tid:"+ row.id+ ", name:"+ row.First_Name+" "+row.Last_Name);
        }
    }
}

function errorHandler(event:*):void {
    feedback("An error occured while executing the statement.");
}
function feedback(w:*) {
    output_txt.appendText(w+"\n");
    output_txt.verticalScrollPosition = output_txt.maxVerticalScrollPosition;
}

Here is an example from: http://www.flashmove.com/forum/showthread.php?t=34778

import flash.data.SQLResult;
import flash.filesystem.File;
import flash.data.SQLStatement;
import flash.data.SQLConnection;
import flash.data.SQLColumnSchema;
import flash.data.SQLTableSchema;
import flash.data.SQLSchemaResult;
import flash.events.SQLEvent;
import flash.events.SQLErrorEvent;
import flash.events.MouseEvent;


var sqlFile:File;
var sqlConn:SQLConnection;
var sqlStatement:SQLStatement;
init();
//- BUTTONS
go_mc.buttonMode = true;
go_mc.addEventListener(MouseEvent.MOUSE_DOWN, runQuery)
readDB_mc.buttonMode = true;
readDB_mc.addEventListener(MouseEvent.MOUSE_DOWN, readDB)

var exampleQuery:String = "INSERT INTO users (First_Name, Last_Name) VALUES ('Betty', 'Boil')";
query_txt.text = exampleQuery;


/**
 * Setup connection to db file
 */
function init():void {
    sqlConn = new SQLConnection();
    sqlConn.addEventListener(SQLEvent.OPEN, connOpenHandler);
    sqlConn.addEventListener(SQLErrorEvent.ERROR, errorHandler);

    sqlFile = new File(File.applicationDirectory.nativePath);
    sqlFile = sqlFile.resolvePath("users.db");
    feedback("Path to db file: "+sqlFile.nativePath);

    sqlConn.open(sqlFile);
}

function connOpenHandler(event:SQLEvent):void {
    feedback("DB Open");
    sqlStatement = new SQLStatement();
    sqlStatement.sqlConnection = sqlConn;
    sqlStatement.addEventListener(SQLErrorEvent.ERROR, errorHandler);

    dbScheme();
    readDB();
}

/**
 * Output the DB structure
 */
function dbScheme() {
    feedback("Schema...");
    sqlConn.loadSchema();
    var result:SQLSchemaResult = sqlConn.getSchemaResult();

    var table:SQLTableSchema = result.tables[0];
    //var column:SQLColumnSchema = table.columns[0]
    feedback("\tTable: "+table.name)
    for (var i=0; i<table.columns.length; i++) {
        feedback("\tColumn "+i+" - "+table.columns[i].name);
    }
}
/**
 * Output DB contents
 */
function readDB(e:Event = null) {
    sqlStatement.addEventListener(SQLEvent.RESULT, selectResultHandler);
    sqlStatement.text = "SELECT * FROM users";
    sqlStatement.execute();
}

/**
 * Run custom query
 */
function runQuery(e:MouseEvent) {
    var sqlQuery:String = query_txt.text;
    feedback("Query: "+sqlQuery);

    sqlStatement.addEventListener(SQLEvent.RESULT, queryResultHandler);
    sqlStatement.text = sqlQuery;
    sqlStatement.execute();
}
function queryResultHandler(e:SQLEvent){
    sqlStatement.removeEventListener(SQLEvent.RESULT, queryResultHandler);
    readDB();
}
/**
 * Handle readDB (SELECT) query
 */
function selectResultHandler(event:SQLEvent):void {
    feedback("Query Results...");
    sqlStatement.removeEventListener(SQLEvent.RESULT, selectResultHandler);

    var result:SQLResult = sqlStatement.getResult();

    if (result.data != null) {
        var numRows:int = result.data.length;
        for (var i:int = 0; i < numRows; i++) {
            var row:Object = result.data[i];
            feedback("\tid:"+ row.id+ ", name:"+ row.First_Name+" "+row.Last_Name);
        }
    }
}

function errorHandler(event:*):void {
    feedback("An error occured while executing the statement.");
}
function feedback(w:*) {
    output_txt.appendText(w+"\n");
    output_txt.verticalScrollPosition = output_txt.maxVerticalScrollPosition;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文