SQLite for Iphone:记录未更新
我正在使用Appcelerator。我正在使用以下代码来获取数据库记录。我使用 SQLite 客户端 NavCatLite 作为 SQLite GUI 来查看和插入数据。我遇到一个奇怪的问题,当我通过 SQLite 客户端更新记录时,它确实反映在我的代码中。为什么不刷新数据?我什至关闭了客户端,因为我认为它会缓存连接,但它也没有帮助。代码如下:
/** * All Db Functions Goes here */
var resumeDB = Titanium.Database.install('resume.db', 'myResume');
//var resumeDB = Titanium.Database.open('cold');
//Iterate through ResultSet
var myResultSet = resumeDB.execute('SELECT * FROM cvs');
while (myResultSet.isValidRow())
{
Ti.API.info("Result iS = "+myResultSet.fieldByName('sb_title'));
myResultSet.next();
} // Do something that iterates
resumeDB.close();
Ps:这不是只读数据库。用户每次都会插入和获取数据。
I am using Appcelerator. I am using the following code to fetch db records. I am using an SQLite Client, NavCatLite as a SQLite GUI for viewing and Inserting Data. I am having a Weird issue that when I update a record via SQLite client, it does reflect in my code. Why is it not refreshing the data? I even closed the client as I thought it would be caching the connection but it did not help either. Code is given below:
/** * All Db Functions Goes here */
var resumeDB = Titanium.Database.install('resume.db', 'myResume');
//var resumeDB = Titanium.Database.open('cold');
//Iterate through ResultSet
var myResultSet = resumeDB.execute('SELECT * FROM cvs');
while (myResultSet.isValidRow())
{
Ti.API.info("Result iS = "+myResultSet.fieldByName('sb_title'));
myResultSet.next();
} // Do something that iterates
resumeDB.close();
P.s: This is not a Read-only Database. The user will be inserting and fetching Data every time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您最初存储在
/Resources
中的数据库文件不是应用安装后使用的数据库文件。根据指南
简而言之,事实并非如此。
The database file that you initally store in
/Resources
is not the database file that is used by the app post-install.Per the guide
In short, it just doesn't work that way.
我认为数据库只在首次安装到设备/模拟器上时与应用程序一起安装一次(无论如何,我在 iPhone 上看到过这种情况,不确定 Android 是否如此)。第一次运行应用程序时,您的数据库将复制到另一个位置,此后运行的是副本,而不是更新的数据库。尝试删除 build/iphone / build/android 目录的内容并再次运行应用程序以强制更新。如果这不起作用,请尝试重置模拟器/从设备上删除应用程序并重新安装。
I think the database is only installed once, along with the app when it is first installed onto the device/simulator (I've seen this with iPhone anyway, not sure about Android). The first time the app is run your database is copied to another location, and thereafter it's the copy that's run, not your updated database. Try deleting the contents of your build/iphone / build/android directories and running the app again to force an update. If that doesn't work, try resetting the simulator / deleting the application off the device and installing again.