我如何以编程方式将几行插入到 iOS 的 sqlite3 表中?这是我当前方法的代码片段:
sqlite3 *database;
if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = "insert into TestTable (id, colorId) VALUES (?, ?)";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
for (int i = 0; i < colorsArray.count; i++) {
sqlite3_bind_int(compiledStatement, 1, elementId);
long element = [[colorsArray objectAtIndex:i] longValue];
sqlite3_bind_int64(compiledStatement, 2, element);
}
}
if(sqlite3_step(compiledStatement) == SQLITE_DONE) {
sqlite3_finalize(compiledStatement);
}
else {
NSLog(@"%d",sqlite3_step(compiledStatement));
}
}
sqlite3_close(database);
这样我只插入了第一行,我如何告诉 sqlite 我希望每个“for”循环都是一个行插入?我找不到任何这样的例子......
谢谢!