2

我一直在研究一个问题几个小时,如果有任何外部意见,我将不胜感激。我是 iOS、Objective-C 和 SQLite 的新手,正在尝试执行 SQLite 更新语句。问题是 UI 冻结并且似乎挂在 SQLite 中的进程中。

这是代码:

NSString *docsPath = [paths objectAtIndex:0];
NSString *path = [docsPath stringByAppendingPathComponent:@"SQLite3Database.sqlite"];
SQLite3_instance *db = [SQLite3_instance databaseWithPath:path]; 
[db open];

NSString *execUpdate = [NSString stringWithFormat:@"update ListItem set status=%i,message=\"%@\",GPSLong=%@, GPSLat=%@,lastUpdated=DateTime('now') where userID = %@",[Status_Picker selectedRowInComponent:0],messageTextField.text , longitude, latitude,loggedinUserID];
NSLog(@"execUpdate: %@", execUpdate);
if (![db executeUpdate:execUpdate])
    NSLog(@"Data insert failed %@", db.lastErrorMessage);

此代码在单击 UIButton 后在 IBAction 中执行,但如前所述,UI 在进程中挂起。上述代码的输出如下:

* execUpdate: 更新 ListItem 设置状态=0,message="",GPSLong=44.48916, GPSLat=6.28739,lastUpdated=DateTime('now') where userID = 1 *

谁能看到这段代码是如何挂起的?

看起来问题是 Xcode 内存泄漏。在我的头撞到墙上几个小时后,关闭并再次启动它解决了这个问题。

4

1 回答 1

1

您确定另一个进程/线程没有针对数据库打开事务吗?这将导致此行为。

于 2013-10-10T01:15:22.050 回答