[英]SQLite database connection is making changes in memory but not saving to the file - AS3 AIR
I'm trying to write to a local SQLite database using the flash.data.*
classes in AIR. 我正在尝试使用AIR中的
flash.data.*
类写入本地SQLite数据库。 I'm opening a synchronous connection in CREATE
mode and using the begin()
and commit()
methods to execute the queries. 我在
CREATE
模式下打开同步连接,并使用begin()
和commit()
方法执行查询。 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 . 正在调用查询
execute()
和连接commit()
方法的成功处理程序,连接对象的totalChanges
属性正在递增,除了没有写入数据库文件之外,一切看起来都很好。 Any ideas what I could be doing wrong? 我有什么想法可能做错了吗?
I don't think it's related to... 我不认为这与...有关
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.
Did you check options defined by pragma? 你检查了pragma定义的选项吗? For example http://www.sqlite.org/pragma.html#pragma_synchronous can cause this behavior.
例如, http://www.sqlite.org/pragma.html#pragma_synchronous可能会导致此行为。
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.
谢谢大家的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.