sqlite3データベースからの読み込みにいくつか問題があります。sqlite3データベースから選択できません
-(void) readMessengesFromDatabase {
sqlite3 *database;
messenges = [[NSMutableArray alloc] init];
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
NSLog(@"Connection OK");
const char *sqlStatement = "select * from MessagesData";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) NSLog(@"connect to table OK"); else NSLog(@"connect to table FALSE");
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { //не проходит условие
NSLog(@"Connection to table OK");
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
NSLog(@"Read rows OK");
NSString *dbMessageID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
NSString *dbMessageText = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *dbMessageDate = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSString *dbMediaOrNot = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
Message *messege = [[Message alloc] initWithName:dbMessageText messageID:dbMessageID messageDate:dbMessageDate mediaOrNot:dbMediaOrNot];
[messenges addObject:messege];
[messege release];
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
私の最初のNSLogは、データベースへの接続が正常であることを私に示しています。しかし次のステップ "select * from MessagesData"とif(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) NSLog(@"connect to table OK"); else NSLog(@"connect to table FALSE");
は私に "connect to table FALSE"と表示しています。私のデータベースのテーブルwhithターミナルから選択し、エラー"データベースファイルを開くことができません"を得ました。私のミスはどこですか?私のコードには何の問題もありません。
あなたは、コアデータを使用しないことを選択した任意の理由を働い教えてください? – wlangstroth
または少なくともFMDBですか? – Eugene
私はコアデータを使用して幸せですが、私のプログラミングレベルはまだそれを使用するために低いです:) – RomanHouse