0
我有我的主束2个数据库,我需要同时访问,以获得他们的数据并加以比较,在一个iphone应用程序中访问多个sqlite数据库?
当我试图访问其中一人单独面对我没有问题。 但是当我尝试访问它们时,我得到的数据库数据都不是两个! 我用这个功能来intstantiate数据库
+(void) InstantiateYourDatabase:(NSString *)DatabaseName {
//Using NSFileManager we can perform many file system operations.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *dpname=DatabaseName;
_dbPath = [self getDBPath:dpname];
BOOL success = [fileManager fileExistsAtPath:_dbPath];
NSLog(@"success == %i",success);
if(!success) {
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:DatabaseName];
success = [fileManager copyItemAtPath:defaultDBPath toPath:_dbPath error:&error];
}
}
,这打开连接
+(void) openconnection
{
NSString *[email protected]"Encrypteed.sqlite";
NSString *cDBKey [email protected]"secret";
if(sqlite3_open([_dbPath UTF8String],&database)==SQLITE_OK)
{
NSLog(@"connection to the database,,opened");
}
else
NSLog(@"connection failed");
}
然后在视图中做了另一个类的负载我用
[SqliteClass InstantiateYourDatabase:@"db1.sqlite"];
[SqliteClass openconnection];
NSMutableArray *array=[[NSMutableArray alloc]initWithArray: [SqliteClass getNames:@"names"]];
[SqliteClass InstantiateYourDatabase:@"db.sqlite"];
[SqliteClass openconnection];
NSMutableArray *toCompareArray=[[NSMutableArray alloc]init ];
[toCompareArray addObjectsFromArray:[SqliteClass getNames:@"Name"]];
SQLite的类onther类,其中我提到的所有方法,,,“getNames”也是一个类的方法... 我得到一个数据库中的数据,,, 我试过很多锡= MES ,,有任何我的数据库没有错,我在谷歌搜索没有任何很好的提示,,
,但我认为多线程是一个解决方案,虽然我不知道多线程
想法任何想法?
以及我试图使用SqliteClass的对象和实例方法在另一个应用程序。用同样的老结果,,我得到的错误味精,,发现没有这样的表:nameOfTable ,, _dbPath是静态的字符串,, ü可以给我一个提示有关创建这样的服务ü建议! –
您有没有使用CoreData的原因?它大大简化了这一点! –
使用SQLite直接会更快,,我没有使用任何连包装,, 现在它的作品我只用2点开放式的方法,而不是访问一个开放的方法,,以“MAC OS”的应用程序,而不是IOS ,,,我没有任何想法,为什么!但维持我需要现在,, 和日Thnx很多乌拉圭回合的时间.. –