Hello,

I'm trying to INSERT many records using sqlite3_bind_text(). This is what I do:

sqlite3_stmt *statement = NULL;
const char *sql = "INSERT INTO mytable(foo, bar) VALUES (?,?);"
int result = sqlite3_prepare(sqliteDatabase, sql, -1, &statement, NULL);

// Do a bunch of binds and execute...
for (i = 0; i < 100; i++)
{
const char *keyString = "one"
const char *valueString = "two"

int resultBindKey = sqlite3_bind_text ( statement, 1, keyString, -1, SQLITE_STATIC); int resultBindContent = sqlite3_bind_text ( statement, 2, valueString, -1, SQLITE_STATIC);

if ((resultBindKey == SQLITE_OK) && (resultBindContent == SQLITE_OK)) {
BOOL waitingForRow = YES;

do {
     int result = sqlite3_step(statement);

     switch (result) {
          case SQLITE_BUSY:
          break;
     case SQLITE_OK:
     case SQLITE_DONE:
          waitingForRow = NO;
          break;
     case SQLITE_ROW:
          waitingForRow = NO;
          break;
     default:
          waitingForRow = NO;
          break;
     }
} while (waitingForRow);
}

// Finish...
result = sqlite3_finalize(statement);

The first iteration works fine, but after that I get a SQLITE_MISUSE (ID 21) when trying to sqlite3_bind_text(). I thought that I was supposed to prepare the statement once, then do a bunch of binds and at the end, finalize.

What am I missing?

Thanks,

-- Tito

Reply via email to