1
テーブルからデータを取得しようとしています。しかし、常に(null)を返します。ここに私のテーブル構造SQLiteは常にiphoneのTEXT値を(null)返します
私は私のテーブルに名前の値を持ってここに私のコード
-(NSString *)filePath
{
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir=[paths objectAtIndex:0];
return [documentDir stringByAppendingPathComponent:@"database.sql"];
}
-(void)openDB
{
//sqlite#_open
if(sqlite3_open([[self filePath]UTF8String], &newDB)!=SQLITE_OK)
{
sqlite3_close(newDB);
NSAssert(0,@"Database fialed to open");
}
}
-(void)readAttendeesFormeetingId:(NSInteger)mId
{
NSLog(@"readAttendeesFormeetingId==> %d",mId);
sqlite3_stmt *stmtAgenda=nil;
attendeesArray = [[NSMutableArray alloc]init];
SQLiteConnClass *objsqlite1=[[SQLiteConnClass alloc]init];
newdb=[objsqlite1 openDB];
if (stmtAgenda==nil) {
const char *sql1 = "SELECT DISTINCT name FROM MeetingAttendees where meetingId= ? AND isPresent = 1";
if (sqlite3_prepare_v2(newdb, sql1, -1, &stmtAgenda, NULL) != SQLITE_OK) {
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(newdb));
}
}
sqlite3_bind_int(stmtAgenda, 1, mId);
while(sqlite3_step(stmtAgenda) == SQLITE_ROW) {
const char *agendaTitle=(const char *)sqlite3_column_text(stmtAgenda,4);
NSString *stragendaTitle=agendaTitle == NULL ? nil:[[NSString alloc] initWithUTF8String:agendaTitle];
//NSString *stragendaTitle = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(stmtAgenda, 4)];
NSLog(@"agendaTitle %@",stragendaTitle);
[attendeesArray addObject:stragendaTitle];
[stragendaTitle release];
}
// Reset the statement for future reuse.
sqlite3_reset(stmtAgenda);
sqlite3_close(newDB);
}
されています。いずれの行にもNULL値は含まれません。まだ私はnullの結果を得ています。
ありがとうございましたBP。それは完全に動作します。私はテーブルからsqlite3_column_textに列番号を渡すべきだと思った。 – iOSAppDev
問題ありません、喜んで助けてください。私はiPhoneでSQLiteデータベースへのアクセスにFMDBを使用することをお勧めします。これはSQLiteのための実用的なオープンソースのObjective-Cラッパーを使いやすくしています。ここにリンクがあります:https://github.com/ccgus/fmdb –