title: Why do I get a SQLITE_MISUSE : Out of Memory error?
body: <p>I am writing an <em>iOS</em> application that directly accesses <code>SQLite</code>. I have done this sort of thing many times on <em>Android</em>, so I'm struggling to see where my error lies - however my inserts are returning the <code>SQLITE_MISUSE</code> error (code 21), with the message "out of Memory". Below are the steps I have taken to lead me to this insert.</p>
  
  <p>First, the <strong>table creation</strong>:</p>
  
  <pre><code>NSString *sql = @"CREATE TABLE IF NOT EXISTS UsersTable (lastName TEXT,id TEXT PRIMARY KEY NOT NULL,picture BLOB,firstName TEXT,age TEXT,email TEXT,sex TEXT,height TEXT,weight TEXT)";
  
  //create the database if it does not yet exist
  NSFileManager *filemgr = [NSFileManager defaultManager];
  if ([filemgr fileExistsAtPath: path ] == NO)
  {
      const char *dbpath = [path UTF8String];
  
      //This was if (sqlite3_open(dbpath, &amp;store) == SQLITE_OK) , but it has not made a difference.
      if (sqlite3_open_v2(dbpath, &amp;store, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) == SQLITE_OK)
      {
          char *errMsg = NULL;
          const char *sql_stmt = [sql UTF8String];
  
          if (sqlite3_exec(store, sql_stmt, NULL, NULL, &amp;errMsg) != SQLITE_OK)
          {
              NSLog(@"Failed to create table: %s", errMsg);
          }
          if (errMsg)
              sqlite3_free(errMsg);
      }
      else
      {
          NSLog(@"Failed to open/create database");
      }
  }
  </code></pre>
  
  <p>Next, the <strong>insert</strong> (currently using the email address for the user ID):</p>
  
  <pre><code>INSERT INTO UsersTable (id,lastName,firstName,email) VALUES ("jsmith@foobar.com","Smith","John","jsmith@foobar.com")
  </code></pre>
  
  <p>I am using one selector for all database interactions, so the above text is passed here:</p>
  
  <pre><code>-(int)execSQL:(NSString *)statement
  {
      NSLog(@"%@",statement);
  
      const char *insert_stmt = [statement UTF8String];
      sqlite3_stmt *stmnt;
  
      sqlite3_prepare_v2(store, insert_stmt, -1, &amp;stmnt, NULL);
      int result = sqlite3_step(stmnt);
  
      sqlite3_finalize(stmnt);
  
      if (result != SQLITE_OK)
      {
          NSLog(@"Error: %s", sqlite3_errmsg(store));//This prints "Error: out of memory"
      }
      return result;
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>