SQLite始终为iphone中的文本值返回(null)

SQLite始终为iphone中的文本值返回(null),iphone,sqlite,Iphone,Sqlite,我正在尝试从表中检索数据。但它总是返回null。这是我的密码 -(NSString *)filePath { NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentDir=[paths objectAtIndex:0]; return [documentDir stringByAppendi

我正在尝试从表中检索数据。但它总是返回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值。我仍然得到空结果。

您的SELECT语句返回的表只有一列,即来自MeetingAttenders的distinct name列,但您的sqlite3\u column\u文本调用正在尝试从列索引4读取。尝试将4更改为0,并查看它是否返回所需的数据。

您的SELECT语句返回的表只有一列,即来自MeetingAttenders的distinct name列,但您的sqlite3\u column\u文本调用正在尝试从列索引4读取。尝试将4改为0,看看它是否返回您需要的数据。

谢谢。它工作得很好。我想我们应该把表中的列号传递给sqlite3\u column\u文本。没问题,乐意帮忙。我建议您在iPhone上使用FMDB访问SQLite数据库,它是一个易于使用且坚如磐石的SQLite开源Objective-C包装器。这里有一个链接:谢谢BP。它工作得很好。我想我们应该把表中的列号传递给sqlite3\u column\u文本。没问题,乐意帮忙。我建议您在iPhone上使用FMDB访问SQLite数据库,它是一个易于使用且坚如磐石的SQLite开源Objective-C包装器。以下是一个链接: