How could I programmatically insert several rows into an sqlite3 table for iOS? This is a code snippet of my current method:
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);
This way I only get the first row inserted, how can I tell sqlite that I want each 'for' loop to be a row insertion? I couldn't find any example of this...
Thanks!