我目前正在关注一个培训视频来学习 Flex,并且我正在尝试尽可能接近视频说明,我一直在尝试找出如何解决错误
错误 #2044:未处理的 SQLErrorEvent:。errorID=3115,操作=执行,消息=错误 #3115:SQL 错误。,详细信息=没有这样的表:'存档列表'
该表应根据培训使用此代码创建。
<fx:Script>
<![CDATA[
import mx.utils.OnDemandEventDispatcher;
public var ArchiveFile:File;
public var dbConnection:SQLConnection;
private function createDatabase():void
{
ArchiveFile = File.applicationStorageDirectory.resolvePath("archive.db");
dbConnection = new SQLConnection();
dbConnection.addEventListener(SQLEvent.OPEN, onDatabaseOpen);
dbConnection.addEventListener(SQLEvent.CLOSE, onDatabaseClose);
dbConnection.openAsync(ArchiveFile);
}
private function onDatabaseOpen(evt:SQLEvent):void
{
trace("Database is now open");
var statement:SQLStatement = new SQLStatement();
statement.sqlConnection = dbConnection;
statement.text = "CREATE TABLE IF NOT EXISTS archivelist (id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT , journal TEXT)";
statement.execute();
}
private function onDatabaseClose(evt:SQLEvent):void
{
trace("Database is now closed");
}
private function saveJournal():void
{
var statement:SQLStatement = new SQLStatement();
statement.sqlConnection = dbConnection;
statement.text = "INSERT INTO archive (title , journal) VALUES ('"+title_txt.text+"','"+journal_txt.text+"')";
statement.execute();
title_txt.text = "";
journal_txt.text = "";
}
]]>
然后使用此代码在另一个视图上调用
<fx:Script>
<![CDATA[
import flash.data.SQLConnection
import flash.filesystem.File
import mx.collections.ArrayCollection;
public var ArchiveFile:File
public var dbConnection:SQLConnection;
public var selectQuery:SQLStatement;
private function createDatabase():void
{
ArchiveFile = File.applicationDirectory.resolvePath("archive.db");
dbConnection = new SQLConnection();
dbConnection.addEventListener(SQLEvent.OPEN, onDatabaseOpen);
dbConnection.addEventListener(SQLEvent.CLOSE, onDatabaseClose);
dbConnection.openAsync(ArchiveFile)
}
private function onDatabaseOpen(evt:SQLEvent):void
{
trace("Database is now open");
selectQuery = new SQLStatement();
selectQuery.sqlConnection = dbConnection;
selectQuery.text = "SELECT * FROM archivelist ORDER BY title ASC";
selectQuery.addEventListener(SQLEvent.RESULT, onQueryResult);
selectQuery.execute();
}
private function onQueryResult(evt:SQLEvent):void
{
archivefiles.dataProvider = new ArrayCollection(selectQuery.getResult().data);
}
private function onDatabaseClose(evt:SQLEvent):void
{
trace("Database is now Closed");
}
]]>
重要的是要注意,在视频中,培训师在名为 database.db 的视图下有一个蓝色文件,他们没有提供这个文件或如何制作它。为了我自己的方式,我已将我的数据库重命名为归档,并将我的表重命名为归档列表。我的最终目标是制作 1 个可供多个视图访问/写入的数据库。与最佳实践,所以我试图尽可能接近培训。我非常感谢提供的任何帮助。如果有人觉得这是一个新问题,我提前道歉,我已经在谷歌上研究了这个问题,并用训练视频检查了每个角色几个小时。我发现每个人似乎都有不同的方式,我正在尝试采用最佳实践方式。
谢谢你