title: iOS SQLite insert and select not working?
body: <p>I am trying to read/write to a SQLite db but I keep getting errors. I've verified that the db exists in ...iPhone Simulator/Applications/5.1/app#/Documents/kipSQLDB.db</p>
  
  <p>I've done INSERT and SELECT to it from Terminal.</p>
  
  <p>But from the app it just errors out. (Additional question - is there a way with sqlite to get informative error messages like mysql_error in mysql? When I error in the app I get nothing but some symbols. </p>
  
  <p>Here's my code:</p>
  
  <p>.h</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  #import &lt;sqlite3.h&gt;
  
  @interface SQLiteController : NSObject { 
  
  //file management
  NSFileManager *fileManager;
  NSString *documentsDirectory;
  
  //sqlite data
  sqlite3* databaseHandle;
  
  }
  
  - (void) initSQLiteDB; 
  
  - (void) insertData : (NSString* ) fName : (NSString* ) lName : (NSString* ) companyName; 
  
  - (NSArray* ) getData;
  
  @end
  </code></pre>
  
  <p>.m</p>
  
  <pre><code>- (void) insertData : (NSString* ) fName : (NSString* ) lName : (NSString* ) companyName { 
  
  NSString* insertStatement = [NSString stringWithFormat:@"INSERT INTO nameList (userFName, userLName, userCompany) VALUES (\"%@\", \"%@\", \"%@\")", fName, lName, companyName];
  NSLog(@"%@", insertStatement);
  
  char *error;
  if ( sqlite3_exec(databaseHandle, [insertStatement UTF8String], NULL, NULL, &amp;error) == SQLITE_OK) {
  
      int recordID = sqlite3_last_insert_rowid(databaseHandle);
      NSLog(@"A record was inserted into the database %@ with the id of %i", databaseHandle, recordID);
  } else { 
      NSLog(@"Error: %s", error);
  }
  }
  
  - (NSArray* ) getData {
  
  NSMutableArray* dataArray = [[NSMutableArray alloc] init];
  
  NSString* getStatement = @"SELECT * FROM nameList";
  
  sqlite3_stmt *statement;
  if (sqlite3_prepare_v2(databaseHandle, [getStatement UTF8String], -1, &amp;statement, NULL) == SQLITE_OK){
  
      // Iterate over all returned rows
      while (sqlite3_step(statement) == SQLITE_ROW) {
  
          int recordID = sqlite3_column_int(statement, 0);
          NSString* fNameFromDB = [NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
          NSLog(@"%@", fNameFromDB);
      }
  } else { 
      NSLog(@"No soup for you!");
  }
  
  return 0;
  
  }
  @end
  </code></pre>