Ios 文件存在,但出现错误:";没有这样的表格”;
我的应用程序有一个问题,我不知道它来自哪里 因此,我将我的文件添加到突出显示的项目中 但当我想在我的表中初始化并选择时,我有一个错误:Ios 文件存在,但出现错误:";没有这样的表格”;,ios,objective-c,sqlite,Ios,Objective C,Sqlite,我的应用程序有一个问题,我不知道它来自哪里 因此,我将我的文件添加到突出显示的项目中 但当我想在我的表中初始化并选择时,我有一个错误: 无此类表格 我很确定这张桌子在这里,因为在我的终端我得到了这个: 我在我的代码中执行相同的请求: tableData=[sqlManager getList:@“从信息中选择名称”] sqlManager处理其他3个文件 我用这个来初始化 -(id)initDatabase:(NSString*)dbName { if (self = [super i
无此类表格
我很确定这张桌子在这里,因为在我的终端我得到了这个:
我在我的代码中执行相同的请求:
tableData=[sqlManager getList:@“从信息中选择名称”]代码>
sqlManager处理其他3个文件
我用这个来初始化
-(id)initDatabase:(NSString*)dbName {
if (self = [super init]) {
//Nom de la base de données
databaseName = dbName;
//Obtention du chemin complet de la base de données
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
}
return self;
}
编辑
我的查询是这样执行的:
-(NSMutableDictionary *)getList:(NSString*)typeOfRequest{
sqlite3 *database;
const char *sqlStatement = [typeOfRequest UTF8String];
NSMutableDictionary *aromaArray = [[NSMutableDictionary alloc] init];
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
sqlite3_stmt *compiledStatement;
//Compilation de la requete et verification du succes
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
NSDictionary *dictionary = [self indexByColumnName:compiledStatement]; // Creation d'un dictionnaire des noms de colonnes
NSMutableArray *array = [[NSMutableArray alloc] init];
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
char *tab = (char*)sqlite3_column_text(compiledStatement, [[dictionary objectForKey:nil] intValue]);
NSString *finalUpperCase = [[NSString stringWithUTF8String:tab] capitalizedString];
if (finalUpperCase != nil && finalUpperCase.length >0 && !([finalUpperCase isEqualToString:@"Null"])) {
[array addObject:finalUpperCase];
}
}
aromaArray = [self getDictionnary:array];
}
else {
NSAssert1(0, @"Erreur :. '%s'", sqlite3_errmsg(database));
}
sqlite3_finalize(compiledStatement); // Finalise la requete et libere le statement
}
else {
NSAssert(0, @"Erreur d'ouverture de la base de donnees");
}
sqlite3_close(database);
return aromaArray;
}
有时候Xcode很混乱,它的派生数据保留了文件的引用,所以有时候需要清除产品并再次运行它
退出XCode
转到派生数据的文件夹,将其删除(也从垃圾箱中删除)
打开XCode clean项目并再次尝试构建它
对于不足的插入和更新查询:
插入和更新查询
将此文件复制到捆绑包(目标)时,此文件为只读。要使其可读并能够进行插入查询,请遵循以下解决方案:
这段代码在applicationdocuments目录中创建绑定的默认数据库的可写副本。将其置于appDelegate
上的application didnishlaunchingwithoptions
,现在您将能够测试您的查询:
// First, test for existence.
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"info_max.sqlite3"];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success) return;
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"info_max.sqlite3"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success)
{
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
您还必须尝试将该数据库(sqlite)文件移出项目目录,再次添加该文件并清除所有缓存数据
这对我来说很有用。你确定你的目标中包含了info\u max.sqlite3
吗?所谓目标,你的意思是:?你是否在任何地方连接到你的数据库?记住添加sqlite3_open([databasePath UTF8String],&database)退出Xcode并删除派生数据并清理项目。同时从你的设备上删除应用程序,再次运行并给我反馈。这很奇怪,因为我现在正在使用这种应用程序。如果itI did 3 NSLog出现问题,请尝试NSLog您的查询:NSLog(@“%@”,databasePath);NSLog(@“%@”,数据库名称);NSLog(@“%@”,请求类型);前两个re(null)…让我们来看看。