【发布时间】:2011-04-05 23:33:47
【问题描述】:
我正在尝试使用 AIR 中的 flash.data.* 类写入本地 SQLite 数据库。我在CREATE 模式下打开一个同步连接,并使用begin() 和commit() 方法来执行查询。一切似乎都按预期执行。正在调用查询execute() 和连接commit() 方法的成功处理程序,连接对象的totalChanges 属性正在递增,除了没有写入数据库文件 之外,一切看起来都很好。有什么想法我可能做错了吗?
我认为这与...无关
- 查询本身,因为那是 每当有事时抛出错误 不匹配。
- 文件模式出于同样的原因。
- 文件权限 - 当前设置为 777
简化版代码:
var database:File = new File(File.applicationDirectory.nativePath + "//" + PATH_TO_DB );
var connection:SQLConnection = new SQLConnection();
connection.open( database, SQLMode.CREATE );
connection.begin();
var statement:SQLStatement = new SQLStatement();
statement.sqlConnection = connection;
statement.addEventListener(SQLEvent.RESULT, onQueryResult);
statement.addEventListener(SQLErrorEvent.ERROR, onQueryError);
statement.text = "INSERT INTO myCrazyTable (foo) VALUES ('bar')";
statement.execute();
connection.commit(new Responder(onCommitComplete));
function onQueryResult(event:SQLEvent):void {
trace("Query successful"); // this is getting called
}
function onQueryError(event:SQLErrorEvent):void {
trace("Error in query: " + event.error.message);
}
function onCommitComplete(event:SQLEvent):void {
trace("Commit Success"); // this is getting called
connection.close();
}
// Database isn't getting touched.
【问题讨论】:
标签: database sqlite file-io air dao