title: sqlite_prepare_v2 does not return SQLITE_OK
body: <p>I have been trying to save highscore into database and have been failing for past week, and I have no clue why it is not working. I keep receiving "Problem with prepare statement" and refuses to insert info into database. I have checked with database manager to make sure there is not a typo with sql statement, and when query is run on manager, it works fine - it's just the iphone that's giving me the problem. If anyone could please look over quickly and see something wrong with it and could let me know, I would really appreciate it!</p>
  
  <pre><code>- (NSMutableArray *) saveLocal {
      NSLog(@"save local database");
      @try {
          [self checkDB];
          sqlite3_stmt *sqlStatement2;
  
  
          NSString *sqlS = [NSString stringWithFormat:@"INSERT INTO localHighscore (difficulty, score, uname, puzzles, multiplier, oneshots, hints) VALUES (%i,%i,\"%@\",%i,%i,%i,%i)",[[MySingleton sharedMySingleton] goDifficulty],[[MySingleton sharedMySingleton] goScore],_player, [[MySingleton sharedMySingleton] goPuzzles], [[MySingleton sharedMySingleton] goMultiplier], [[MySingleton sharedMySingleton] goOneshots], [[MySingleton sharedMySingleton] goHints]];
          NSLog(@"%@",sqlS);
          const char *sql = [sqlS UTF8String];
  
  
          if(sqlite3_prepare_v2(localHighscore, sql, -1, &amp;sqlStatement2, NULL) == SQLITE_OK)
          {
              sqlite3_step(sqlStatement2);
              sqlite3_reset(sqlStatement2);
              sqlite3_finalize(sqlStatement2);
              NSLog(@"save complete");
          } else {
              NSLog(@"Problem with prepare statement");
          }  
          sqlite3_close(localHighscore);
      }@catch (NSException *exception) {
          NSLog(@"An exception occured: %@", [exception reason]);
      }@finally{
          NSLog(@"DB Loaded!");
      }
  }
  </code></pre>
  
  <p>and here is checkDB method which checks if database exists and creates one if it does not</p>
  
  <pre><code>- (void)checkDB {
      NSString *docsDir;
      NSArray *dirPaths;
  
      // Get the documents directory
      dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  
      docsDir = [dirPaths objectAtIndex:0];
  
      // Build the path to the database file
      databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"localHighscore.sqlite"]];
  
      NSFileManager *filemgr = [NSFileManager defaultManager];    
      if ([filemgr fileExistsAtPath: databasePath ] == NO)
      {
      const char *dbpath = [databasePath UTF8String];
          NSLog(@"file was not found");
          if (sqlite3_open(dbpath, &amp;localHighscore) == SQLITE_OK)
          {
              NSLog(@"db open");
              char *errMsg;
              const char *sql_stmt = "CREATE TABLE IF NOT EXISTS localHighscore(pk INTEGER PRIMARY KEY AUTOINCREMENT, difficulty TINYINT, score MEDIUMINT, uname VARCHAR(255), puzzles TINYINT, multiplier TINYINT, oneshots TINYINT, hints TINYINT)";
  
              if (sqlite3_exec(localHighscore, sql_stmt, NULL, NULL, &amp;errMsg) != SQLITE_OK)
              {
                  NSLog(@"Failed to create table");
              }
              sqlite3_close(localHighscore);            
          } else {
              NSLog(@"Failed to open/create database");
          }
      }
      [filemgr release];
  }
  </code></pre>
  
  <p>Thanks in advance for the help!</p>