title: Unable to find table but not always
body: <p>Sometimes when I run my application I get the error: No such table "tablename". Then my database gets empty and the app crash. </p>
  
  <p>I am 100% sure that the table exists. The weird thing is that it doesn't happen often, about 1/30 so is hard to debug. I don't use any code to delete the table.  </p>
  
  <p>This is how I open the database:</p>
  
  <pre><code>- (id)initWithDB:(NSString*)dbName{
      if(self = [super init])
      {
          NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
          NSString *documentsDirectory = [paths objectAtIndex:0];
          NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:dbName];
  
          if (sqlite3_open([writableDBPath UTF8String], &amp;_database) != SQLITE_OK) {
              NSLog(@"could not prepare statement: %s\n", sqlite3_errmsg(_database));
              NSLog(@"Failed to open database!");
          }
          else {
          //WAL mode on to write and read database at the same time
          sqlite3_exec(_database, "PRAGMA journal_mode=WAL;", 0, 0, 0);
          }
  
      }
      return self;
  }
  </code></pre>