【发布时间】:2011-05-17 15:41:49
【问题描述】:
您好,我在 iphone 中使用数据库。过了一段时间,我的应用程序给出了这个错误
sqlite error 14 [unable to open database file]
我的应用程序运行良好,但有时会产生上述错误。解决方案是什么? 有代码:
[lovkid openDatabase:[appDelegate getDBPath]];
NSString *Flag = [NSString stringWithFormat:@"%@", appDelegate.selectimage];
int recId = (int)appDelegate.Id;
NSLog(@"recID = %d",appDelegate.Id);
updateStmt1 = nil;
if(updateStmt1 == nil)
{
const char *sql ="UPDATE 'char' SET `Pic`=? WHERE `id`=?";
if(sqlite3_prepare_v2(database1, sql, -1, &updateStmt1, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database1));
}
sqlite3_bind_text(updateStmt1, 1, [Flag UTF8String], -1, SQLITE_STATIC);
sqlite3_bind_int(updateStmt1, 2, recId);
if(SQLITE_DONE != sqlite3_step(updateStmt1))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database1));
else
NSLog(@"no error");
sqlite3_reset(updateStmt1);
sqlite3_finalize(updateStmt1);
...
【问题讨论】:
-
你能提供一些代码来展示你是如何使用 sqlite 的吗?
-
您在此处编写的函数看起来是正确的。显示 1.openDatabase 和 2.getDBPath 的函数定义。我倾向于认为您的代码中缺少部分。提供这两个函数,我们应该可以很快搞清楚这个。