【发布时间】:2012-09-24 01:28:36
【问题描述】:
我正在使用以下代码在 SQLite 中打开数据库并执行插入查询。
// Open the database and store the handle as a data member
if (sqlite3_open([databaseFile UTF8String], &databaseHandle) == SQLITE_OK)
{
const char *sqlStatement = [insertStmt cStringUsingEncoding:NSUTF8StringEncoding];
char *error;
if (sqlite3_exec(databaseHandle, sqlStatement, NULL, NULL, &error) == SQLITE_OK)
{
NSLog(@"Config table values inserted.");
registration_done = YES;
}
else
{
NSLog(@"Error: %s", error);
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
if (sqlite3_exec(databaseHandle, sqlStatement, NULL, NULL, &error) == SQLITE_OK) {
NSLog(@"Config table values inserted 2.");
registration_done = YES;
}
else {
NSLog(@"Error: %s", error);
}
}
}
else{
sqlite3_close(databaseHandle);
}
sqlite3_close(databaseHandle);
但我收到以下错误,之后应用程序将终止:
-[__NSCFType UTF8String]:无法识别的选择器发送到实例 0x15d9a0
数据库文件和表是在 /Caches/ 目录中创建的,因为我使用的是 Phonegap(2.1.0)。在调用上述 Objective-C 代码之前,Phonegap 正在正确执行查询,这意味着在 /Caches/ 目录中成功创建了表。
【问题讨论】:
标签: iphone objective-c ios cordova sqlite