Opening multiple databases with SQLite

前端之家收集整理的这篇文章主要介绍了Opening multiple databases with SQLite前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@interface database : NSObject {
    sqlite3 * db;
    sqlite3_stmt  query
    NSStringqueryStringdbPath
}

-(void) opendb(BOOLattach_user_databases

@end@implementation database

 opendb

    dbpath =[[NSBundle mainBundle] pathForResource:@"levels" ofType"db"];
    sqlite3_open([dbpath UTF8String],&db);

    [self attach_user_databases

    sqlite3_prepare_v2,0)">[queryString UTF8String-1query NULLattach_user_databases

  int dbcount  0 result
  NSFileManagerfm [ defaultManagerNSArraypaths NSSearchPathForDirectoriesInDomains(NSDocumentDirectoryNSUserDomainMask YESdocumentsDirectory paths objectAtIndex:NSDirectoryEnumeratordocs fm enumeratorAtPathdocumentsDirectoryfilewhile((file docs nextObject]))
    if([[file pathExtension isEqualToString"sqlite3"])
      ++dbcount
      fullPath documentsDirectory stringByAppendingPathComponent
      sqlite3_stmt attach
      sqlite3_prepare_v2 stringWithFormat"ATTACH DATABASE '%@' AS 'DB%i'"fullPath UTF8String
      sqlite3_step
      sqlite3_finalize
    
  dbcount ==
    queryString @"SELECT * FROM levels WHERE ROWID=?"return NOelsecviewNSMutableStringcreateView  stringWithString"CREATE TEMP VIEW LV AS SELECT * FROM levels"for i=i<=;++createView appendFormat" UNION SELECT * FROM DB%i.levels"
    sqlite3_prepare_v2createView UTF8String
    sqlite3_step
    sqlite3_finalize"SELECT * FROM LV WHERE ROWID=?"@end
原文链接:https://www.f2er.com/sqlite/201319.html

猜你在找的Sqlite相关文章