mercredi 14 octobre 2015

how to assign a sqlite3 table to nsarray

I am developing a chatting app in that i am using sqlite for storing and retrieving chat history i am able to insert the values but while retrieving i am getting the nil in array here is my code

messageArray=[DBObject AllRowFromTableName:@"chatTable" withUserID:myJID withFriendID:chatWithUser];


for (int i=0; i<[messageArray count]; i++) {

    Message *msg=[[Message alloc] init];
          msg.text=[[messageArray objectAtIndex:i] msg];
    if ([[messageArray objectAtIndex:i] lft_rght]==0) {
        msg.fromMe=YES;
    }
    else{
        msg.fromMe=NO;
    }

    msg.type=SOMessageTypeText;

    NSString *dateString =[[messageArray objectAtIndex:i] tim_dte];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"HH:mm,yyyy/MM/dd"];
    NSDate *dateFromString = [[NSDate alloc] init];
    dateFromString = [dateFormatter dateFromString:dateString];
    msg.date=dateFromString;

    [self.chatHistoryArray addObject:msg];

this is my retrieving class ad database class is

 -(NSMutableArray *)AllRowFromTableName:(NSString *)tableName withUserID:(NSString *)userid withFriendID:(NSString *)friendid

   {
NSMutableArray *array=[[NSMutableArray alloc] init];

NSString *sqlString=[NSString stringWithFormat:@"select *from chatTable where toid='%@' and fromid='%@'",userid,friendid];

sqlite3_stmt *statement;
if (sqlite3_prepare_v2(db, [sqlString UTF8String], -1, &statement, nil)==SQLITE_OK) {

    while (sqlite3_step(statement)==SQLITE_ROW) {
         Message *tempSkeleton=[[Message alloc] init];

        tempSkeleton.mToID =[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 1)];

        tempSkeleton.mFromID=[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 2)];
        tempSkeleton.text=[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 3)];

        //tempSkeleton.fromMe=[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 3)];
        tempSkeleton.fromMe=((int)sqlite3_column_int(statement, 4)) ?  YES : NO;
        tempSkeleton.tim_dte=[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 5)];




        [array addObject:tempSkeleton];
        //  NSLog(@"IN LOOP=>%@",array);

    }



}

i am getting msg.text empty can ay body help me please

Aucun commentaire:

Enregistrer un commentaire