SQLite Forum

sqlite3_prepare_v2 does not seem to work.
> Well... the preview doesn't look very readable; what can I do?

At the top of the text box there's a drop down for what style to use. You can always change it to Plain Text to get rid of any fancy behavior.

If you click on the words "Markup style:" there, and then on "Markdown Formatting Rules" you get a guide of all the Markdown stuff. There's a section on "Literal/Verbatim Text - Code Blocks"

The most basic way to mark a section as without style is to use backticks before and after. Triple backticks seems best when going around a big block.

#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;