title: sqlite3_prepare_v2 throws SQLITE_ERROR in iPhone code
body: <p>I have a piece of code that used to work, and other iterations of it that DO work within the same app, and have compared code, and they are identical in structure.  This is driving me INSANE!!!!!!</p>
  
  <p>In this instance, sqlite3_prepare_v2 is throwing one of those useless SQLITE_ERROR exceptions.  Apparently, it can FIND the database, and OPEN the database, but it can't prepare a statement for it.   </p>
  
  <p>Does ANYONE have any ideas?  I'm desperate here.</p>
  
  <pre><code> second_maindatabaseName = @"database.db";
  NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDir = [documentPaths objectAtIndex:0];
  second_maindatabasePath = [documentsDir stringByAppendingPathComponent:second_maindatabaseName];
  
  // Setup the database object
  sqlite3 *database;
  // Init the entry requirements Array
  BOOL success;
  NSFileManager *fileManager = [NSFileManager defaultManager];
  success = [fileManager fileExistsAtPath:second_maindatabasePath];
  if(!success) {
  NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:second_maindatabaseName];
  [fileManager copyItemAtPath:databasePathFromApp toPath:second_maindatabasePath error:nil];
  [fileManager release];
  }
  if(sqlite3_open([second_maindatabasePath UTF8String], &amp;database) == SQLITE_OK) {
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  
  value1 = [defaults stringForKey:kConst1];   
  value2 = [defaults stringForKey:kConst2];   
  value3 = [defaults stringForKey:kConst3];   
  value4 = [defaults stringForKey:kConst4];   
  const char *sqlStatement = "SELECT * FROM myTable WHERE Field1 = ? AND Field2 = ? AND Field3 = ? AND Field4 = ?";
  sqlite3_stmt *compiledStatement;
  int error_code = sqlite3_prepare_v2(database, sqlStatement, -1, &amp;compiledStatement, NULL);
  if(error_code == SQLITE_OK) {
  // Loop through the results and add them to the feeds array
  sqlite3_bind_text(compiledStatement,1,[value1 UTF8String],-1,SQLITE_TRANSIENT);
  sqlite3_bind_text(compiledStatement,2,[value2 UTF8String],-1,SQLITE_TRANSIENT);
  sqlite3_bind_text(compiledStatement,3,[value3 UTF8String],-1,SQLITE_TRANSIENT);
  sqlite3_bind_text(compiledStatement,4,[value4 UTF8String],-1,SQLITE_TRANSIENT);
  
  while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
  // Read the data from the result row
  NSString *aNewValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
                          }
  } 
  sqlite3_finalize(compiledStatement);
  }
  sqlite3_close(database);
  </code></pre>