SQLite 数据库连接正在内存中进行更改,但未保存到文件 - AS3 AIR
我正在尝试使用 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.
I'm trying to write to a local SQLite database using the flash.data.*
classes in AIR. I'm opening a synchronous connection in CREATE
mode and using the begin()
and commit()
methods to execute the queries. Everything seems to be executing as expected. The query execute()
and connection commit()
method's success handler is being called, the connection object's totalChanges
property is being incremented, everything looks good except the database file is not being written to. Any ideas what I could be doing wrong?
I don't think it's related to...
- the query itself since that was
throwing errors whenever something
didn't match up. - the file mode for the same reason.
- file permissions - currently set to 777
Simplified version of the code:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您检查了 pragma 定义的选项吗?例如 http://www.sqlite.org/pragma.html#pragma_synchronous 可能会导致这种行为。
Did you check options defined by pragma? For example http://www.sqlite.org/pragma.html#pragma_synchronous can cause this behavior.
我要问的第一件事是,你怎么知道它没有被碰过?时间戳?或者您正在查询该项目但没有找到它?
我问的主要原因是,我对这段代码表示怀疑:
var database:File = new File(File.applicationDirectory.nativePath + "//" + PATH_TO_DB );
我认为 // 是不正确,我认为您的数据库可能最终位于您认为的其他地方,最有可能位于根文件系统。如果我的理论是正确的,那么您正在将数据写入与您想象的不同的数据库,而不仅仅是“在内存中”。
The first thing I would ask is, how do you know it isn't being touched? Timestamp? Or are you querying for the item and not finding it?
The main reason I ask is, I'm suspicious of this code:
var database:File = new File(File.applicationDirectory.nativePath + "//" + PATH_TO_DB );
I think the // is incorrect, and I think possibly your DB is ending up somewhere other than where you think it is, most likely at the root filesystem. If my theory is correct, you are writing data to a different db than you think you are, not just "in memory".
我解决了这个问题。我最终重写了访问数据库的代码。我不确定问题到底出在哪里,我一定是忽略了这一点。感谢大家的帮助。
I fixed the issue. I ended up rewriting the code for accessing the database. I'm not sure exactly where the problem was, something I must have been overlooking. Thanks for everyone's help.