SQLite Forum

sqlite3_prepare_v2 does not seem to work.
I'm trying to get my head around sqlite3. I'm using the <sqlite3.h> lib that comes with Xcode.
The code is quite simple, but does not completely work as expected.

#include <sqlite3.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, const char * argv[])
  sqlite3 *db;
  if (sqlite3_open("the_insert.db", &db))
    printf("Could not open the_insert.db\n");
  printf("Database %s is open\n", "the_insert.db");
  // Prepare a statement for multiple use:
  // =====================================
  const char *query = "INSERT INTO someTable (second, third) VALUES (?,?)";
  int sqlSize = (int)strlen(query) + 1;
  sqlite3_stmt *stmt;
  int err = sqlite3_prepare_v2(db, query, sqlSize, &stmt, NULL);
  printf("err: %d\n", err);
  if (sqlite3_prepare_v2(db, query, sqlSize, &stmt, NULL))
    printf("Error executing prepare statement: \n");  //, sqlite3_errstr());

  printf("prepared\n"); // I NEVER GET THIS FAR!
   * The prepared statement executed multiple times
   * ==============================================
  for (...) {
      sqlite3_bind_int (stmt, 1, ...);
      sqlite3_bind_text(stmt, 2, ...);

       if (sqlite3_step(stmt))
          printf("execution failed\n");
          sqlite3_finalize(stmt);         // Only when things go wrong
          return ;
  // Get rid of the memory allocated for stmt; mandatory!
  sqlite3_close(db);  return 0;

The output is:
Database the_insert.db is open.
Error executing prepare statement:

What is wrong with my code?
What can there be wrong with my use of sqlite3_prepare_v2()?

Well... the preview doesn't look very readable; what can I do?