title: Move unencrypted tables to encrypted sqlite database
body: <p>I want to know how to transfer my unencrypted sqlite tables to encrypted sqlite database. I'm using sqlcipher to encrypt a database. </p>
  
  <p>I've tried this code, but it didn't work.</p>
  
  <pre><code>NSString *databasePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
                            stringByAppendingPathComponent: @"contacts_enc.sqlite"];
  
  
  sqlite3 *db;
  if (sqlite3_open([databasePath UTF8String], &amp;db) == SQLITE_OK) {
  
      const char* key = [@"1234" UTF8String];
      sqlite3_key(db, key, strlen(key));
  
      if (sqlite3_exec(db, (const char*) "SELECT count(*) FROM sqlite_master", NULL, NULL, NULL) == SQLITE_OK) {
          NSLog(@"password is correct, or, database has been initialized") ;
  
          //START
  
          sqlite3_exec(db, "ATTACH DATABASE 'contacts.sqlite' AS encrypted KEY '1234';", NULL, NULL, NULL);
          sqlite3_exec(db, "CREATE TABLE encrypted.account(_id,username,password);", NULL, NULL, NULL);
          sqlite3_exec(db, "INSERT INTO encrypted.account SELECT * FROM account;", NULL, NULL, NULL);
          sqlite3_exec(db, "DETACH DATABASE encrypted;", NULL, NULL, NULL);
  
          //END
      }
  }
  </code></pre>