SQLite for Iphone:记录未更新

发布于 2024-10-26 22:36:32 字数 658 浏览 3 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫南 2024-11-02 22:36:32

您最初存储在 /Resources 中的数据库文件不是应用安装后使用的数据库文件。

根据指南

另一方面,install() 将复制
来自预先存在的数据库文件
Titanium 的资源目录,或其中之一
其后代,
applicationDataDirectory/../databases/
并返回对打开的引用
数据库。如果文件已经存在
同名,复制动作
将会默默地失败并且数据库
将简单地打开。


简而言之,事实并非如此。

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

On the other hand, install() will copy
a pre-existing database file from
Titanium's Resources directory, or one
of its descendants, to
applicationDataDirectory/../databases/
and return a reference to the opened
database
. If a file already exists
with the same name, the copy action
will silently fail and the database
will simply be opened.

In short, it just doesn't work that way.

人疚 2024-11-02 22:36:32

我认为数据库只在首次安装到设备/模拟器上时与应用程序一起安装一次(无论如何,我在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文