title: sqlite db in iphone app error: no such table
body: <p>I have a problem when pushing data to my sqlite database in iphone application.
  here's how I create database:</p>
  
  <pre><code>-(IBAction)createButtonPressed:(id)sender
  {
      NSLog(@"createButtonPressed: called");
      status.text=[status.text stringByAppendingString:@"create button pressed.\n"];
      NSString *docsDir;
      NSArray *dirPaths;
  
      // Get the documents directory
      dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  
      docsDir = [dirPaths objectAtIndex:0];
  
      // Build the path to the database file
      self.databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"database.sqlite"]];
  
      NSFileManager *filemgr = [NSFileManager defaultManager];
  
      if ([filemgr fileExistsAtPath: databasePath ] == NO)
      {
          status.text=[status.text stringByAppendingString:@"creating database... "];
          status.text=[status.text stringByAppendingFormat:@"path: %@\n\n", databasePath];
  
      const char *dbpath = [databasePath UTF8String];
  
          if (sqlite3_open(dbpath, &amp;database) == SQLITE_OK)
          {
              status.text=[status.text stringByAppendingString:@"database opened successfully\n"];
  
              char *errMsg;
              const char *sql_stmt;
              NSString *sqlStatement=[[NSString alloc] init];
  
              /*
               CREATING JOB TABLE
               */
              sqlStatement=@"";
              [sqlStatement stringByAppendingString:@"CREATE TABLE IF NOT EXISTS JOB "];
              [sqlStatement stringByAppendingString:@"(ID INTEGER PRIMARY KEY AUTOINCREMENT, "];
              [sqlStatement stringByAppendingString:@"NUMBER TEXT, "];
              [sqlStatement stringByAppendingString:@"DATE_LOADING INTEGER, "];
              [sqlStatement stringByAppendingString:@"DATE_DEPARTURE INTEGER, "];
              [sqlStatement stringByAppendingString:@"DATE_UNLOADING INTEGER, "];
              [sqlStatement stringByAppendingString:@"ORIGIN INTEGER, "];
              [sqlStatement stringByAppendingString:@"DESTINATION INTEGER, "];
              [sqlStatement stringByAppendingString:@"SUPPLIER INTEGER, "];
              [sqlStatement stringByAppendingString:@"RAILROAD INTEGER, "];
              [sqlStatement stringByAppendingString:@"FOREMAN INTEGER, "];
              [sqlStatement stringByAppendingString:@"WEATHER INTEGER, "];
              [sqlStatement stringByAppendingString:@"COMMENT TEXT, "];
              [sqlStatement stringByAppendingString:@"MODIFY_STATUS INTEGER)"];
  
              sql_stmt = [sqlStatement UTF8String];
  
              if (sqlite3_exec(database, sql_stmt, NULL, NULL, &amp;errMsg) != SQLITE_OK)
              {
                  status.text=[status.text stringByAppendingString:@"failed to create JOB table\n"];
              }
              else
              {
                  status.text=[status.text stringByAppendingString:@"JOB table created\n"];
              };
  
  
          status.text=[status.text stringByAppendingString:@"closing database...\n"];
          sqlite3_close(database);
  
      }
      else
      {
          status.text=[status.text stringByAppendingString:@"failed to open/create database\n"];
      };
  }
  else
  {
      status.text=[status.text stringByAppendingString:@"database exists "];
      status.text=[status.text stringByAppendingFormat:@"path: %@\n\n", databasePath];
  };
  
  [status scrollRangeToVisible:NSMakeRange([status.text length], 0)];
  </code></pre>
  
  <p>}</p>
  
  <p>everything is with creating is OK. <strong>BUT!</strong>
  when I try to push data to my table I get an error: "no such table JOB"
  pushing data code:</p>
  
  <pre><code>NSLog(@"populateButtonPressed: called");
  status.text=[status.text stringByAppendingString:@"populate button pressed.\n"];
  
  NSFileManager *filemgr = [NSFileManager defaultManager];
  
  if ([filemgr fileExistsAtPath: databasePath ] == YES)
  {
      const char *dbpath = [databasePath UTF8String];
  
      if (sqlite3_open(dbpath, &amp;database) == SQLITE_OK)
      {
          status.text=[status.text stringByAppendingString:@"database opened successfully\n"];
  
          char *errMsg;
          const char *sql_stmt;
          NSString *sqlStatement=[[NSString alloc] init];
  
          /*
           POPULATING JOB TABLE
           */
          sqlStatement=@"INSERT INTO JOB (NUMBER, DATE_LOADING, DATE_DEPARTURE, DATE_UNLOADING, ORIGIN, DESTINATION, SUPPLIER, RAILROAD, FOREMAN, WEATHER, COMMENT, MODIFY_STATUS) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  
          sql_stmt = [sqlStatement UTF8String];
          sqlite3_stmt *stmt;
          sqlite3_prepare_v2(database, sql_stmt, -1, &amp;stmt, nil);
          sqlite3_bind_text(stmt, 1, "number", -1, SQLITE_STATIC); //number
          sqlite3_bind_int(stmt, 2, 100); //date_loading
          sqlite3_bind_int(stmt, 3, 101); //date_departure
          sqlite3_bind_int(stmt, 4, 102); //date_unloading
          sqlite3_bind_int(stmt, 5, 103); //origin
          sqlite3_bind_int(stmt, 6, 104); //destination
          sqlite3_bind_int(stmt, 7, 105); //supplier
          sqlite3_bind_int(stmt, 8, 106); //railroad
          sqlite3_bind_int(stmt, 9, 107); //foreman
          sqlite3_bind_int(stmt, 10, 108); //weather
          sqlite3_bind_text(stmt, 11, "commentstring", -1, SQLITE_STATIC); //comment
          sqlite3_bind_int(stmt, 12, 1);
  
          if (sqlite3_step(stmt)!=SQLITE_DONE)
          {
              status.text=[status.text stringByAppendingString:@"WARNING!!! Could not step (execute) stmt\n"];
              status.text=[status.text stringByAppendingFormat:@"error: %@\n", [NSString stringWithUTF8String:sqlite3_errmsg(database)]];
          }
          else
          {
              status.text=[status.text stringByAppendingString:@"it seems like stmt step (execute) was successfull"];
          };
  
          if(sqlite3_finalize(stmt)==SQLITE_DONE)
          {
              status.text=[status.text stringByAppendingString:@"finalizing stmt was successfull\n"];
          }
          else
          {
              status.text=[status.text stringByAppendingString:@"WARNING!!! failed finalizing stmt\n"];
          };
  
  
          status.text=[status.text stringByAppendingString:@"closing database...\n"];
          sqlite3_close(database);
  
      }
      else
      {
          status.text=[status.text stringByAppendingString:@"failed to open database\n"];
      };
  }
  else
  {
      status.text=[status.text stringByAppendingString:@"database does not exist. you need to create it.\n"];
  };
  
  [status scrollRangeToVisible:NSMakeRange([status.text length], 0)];
  </code></pre>
  
  <p>the database exists at path and opens successfully.
  iOS5 ipad application, uses ARC and <code>libsqlite3.dylib</code>, I'm running my application in simulator.</p>