title: Can iPhone sqlite apps attach to other databases?
body: <p>The ATTACH DATABASE command is useful for transferring rows between sqlite database files and allows you to join rows from tables across databases
  e.g.</p>
  
  <pre><code>$ sqlite3 BookLoansDB.sqlite 
  sqlite&gt; ATTACH DATABASE '/Users/.../Documents/BooksDB.sqlite' AS books_db;
  sqlite&gt; select B.BookName, B.Pages, BL.LentTo from main.tblBookLoan BL inner join books_db.tblBook B on B.BookID = BL.BookID;
  The Client|512|Jenny
  The Pelican Brief|432|Mike
  </code></pre>
  
  <p>How can I do the same from objective-c on the iPhone.  I've had no success with this kind of code:</p>
  
  <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentDirectory = [paths objectAtIndex:0];
  const char *booksDBPath = [[documentDirectory stringByAppendingPathComponent:@"BooksDB.sqlite"] UTF8String];
  const char *bookLoansDBPath = [[documentDirectory stringByAppendingPathComponent:@"BookLoansDB.sqlite"] UTF8String];
  sqlite3 *bookLoansDB;
  int result = sqlite3_open(bookLoansDBPath, &amp;bookLoansDB);
  sqlite3_stmt *attachStmt;
  NSString *attachSQL = [NSString stringWithFormat: @"ATTACH DATABASE \'%s\' AS books_db", bookLoansDBPath];
  result = sqlite3_prepare_v2(bookLoansDB, [attachSQL UTF8String] , -1, &amp;attachStmt, nil);
  char *errorMessage;
  result = sqlite3_exec(bookLoansDB, [attachSQL UTF8String], NULL, NULL, &amp;errorMessage);
  sqlite3_stmt *selectStmt;
  NSString *selectSQL = @"select * from main.tblBookLoan BL inner join books_db.tblBook B on B.BookID = BL.BookID";
  result = sqlite3_prepare_v2(bookLoansDB, [selectSQL UTF8String] , -1, &amp;selectStmt, nil);
  // result == 1
  result = sqlite3_step(selectStmt) ; 
  // result == 21
  if (result == SQLITE_ROW)
  {
      //do something
  }
  </code></pre>
  
  <p>Can it even be done?</p>