【发布时间】:2012-06-05 19:31:38
【问题描述】:
我正在使用 ios 5 上的 sqlite 数据库。我的应用程序所做的是它在文本字段中获取字符串并将其保存到数据库中。当我运行该应用程序时,它会崩溃并给出以下警告:
Thread1:程序接收到信号“SIGBRT”
它在 main.m 和这一行中给出了这个:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
有人可以帮我吗?将不胜感激! :( 我使用的是 xcode 4.2。
这是编译器说发生断言失败的方法。
- (void) addstrings{
if(addStmt == nil) {
const char *sql = "insert into strings(strings) Values(?)";
if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
}
sqlite3_bind_text(addStmt, 1, [strings UTF8String], -1, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(addStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
else
//SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid
strID = sqlite3_last_insert_rowid(database);
//Reset the add statement.
sqlite3_reset(addStmt);
}
【问题讨论】:
-
“保存到数据库”是指直接调用 SQLite,还是使用 CoreData?无论哪种情况,在保存点附近查看相关代码都会有所帮助。
-
我正在使用 sqlite 3 @wadesworld。我已经检查了很多次代码但没有任何线索:(
-
能否将堆栈跟踪添加到问题中。
标签: objective-c ios5 sqlite xcode4.2