【发布时间】:2014-01-20 16:51:53
【问题描述】:
这是我用来向表中插入数据的代码,
sqlite3 *database;
NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"mobdb.sqlite"];
if(sqlite3_open([dbPath UTF8String],&database)==SQLITE_OK)
{
const char *sqlstatement = "INSERT INTO mobDetails (nMonId, nScore) VALUES (?,?)";
sqlite3_stmt *compiledstatement;
if(sqlite3_prepare_v2(database,sqlstatement , -1, &compiledstatement, NULL)==SQLITE_OK)
{
NSString * str1 =@"1";
NSString * str2 =@"12";
sqlite3_bind_int(compiledstatement, 1, [str1 integerValue]);
sqlite3_bind_int(compiledstatement, 2, [str2 integerValue]);
if(sqlite3_step(compiledstatement)==SQLITE_DONE)
{
NSLog(@"done");
}
else
{
NSLog(@"ERROR");
}
sqlite3_reset(compiledstatement);
}
else
{
NSAssert1(0, @"Error . '%s'", sqlite3_errmsg(database));
}
sqlite3_close(database);
}
它显示“完成”消息,但没有插入表中的数据可以帮助我。
还有如何在表格中插入字符串?
【问题讨论】:
-
尝试将 mobdb.sqlite 放在文档文件夹中,然后插入。
-
“如何使用 xcode 在 sqlite 表中插入值” - 绝不。 Xcode 不是 SQLite 编辑器。