私は Xcode 4.3 で sqlite データベースから情報を取得しようとしている初心者の iPhone 開発者です。データベース (DB_Info.sqlite という名前) を .h および .m ファイルと同じディレクトリに置き、データベースを Xcode の左側のバーのフォルダー セクションにドラッグしました。
私のコードを簡単に見て、私の間違いがどこにあるか教えてください。NSLogs を使用して、最後の if ステートメントで問題が発生した場所を特定し、それをコメントに記述しました。よろしくお願いします!
#import <sqlite3.h>
@implementation Player
{
sqlite3 *DB_Info;
NSString *databasePath;
NSString *docsDir;
NSArray *dirPaths;
}
-(Player*)createPlayer:(NSString*)playerName
{
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"DB_Info.sqlite"]];
const char *dbpath = [databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &DB_Info) == SQLITE_OK) { //works fine
NSString *querySQL = [NSString stringWithFormat: @"SELECT * FROM playerlist WHERE fullName=\"%@\"", playerName];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(DB_Info, query_stmt, -1, &statement, NULL) == SQLITE_OK) { //PROBLEM: This is where the problem is, and the if statement never goes through
//....rest of code here
} else {
NSLog(@"Error");
}
}