我正在使用SQLite我能够创建表和alter table但是在向表中添加列之后,数据不会被提取。
到目前为止,我的实现插入表格值如下
NSString *sqlString=[NSString stringWithFormat:@"insert into %@(toid,fromid,msg,timedate,left,messageID,chatStatus) values('%@','%@','%@','%@',%d,'%@','%@')",tableName,userid,friendid,message,timedate,(int)leftright,messageID,chatStatus];
下面我从表中获取数据
-(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) {
ChatHistorySkeleton *tempSkeleton=[[ChatHistorySkeleton alloc] init];
tempSkeleton.u_id =[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 1)];//f_id
// NSString *strn = [NSString stringWithFormat:@"%@",tempSkeleton.mToID];
tempSkeleton.f_id=[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 2)];
tempSkeleton.msg=[[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.lft_rght=(int)sqlite3_column_int(statement, 4);
tempSkeleton.tim_dte=[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 5)];
//if messageID Null
char *messageIDForEmptyCheck = (char *)sqlite3_column_text(statement, 6);
NSString *messageID1 = messageIDForEmptyCheck?[[NSString alloc]initWithUTF8String:messageIDForEmptyCheck]:@"";
tempSkeleton.messageID=messageID1;
//if chat status Null
char *chatStatus = (char *) sqlite3_column_text(statement,7);
NSString *chatStatus1 = chatStatus?[[NSString alloc]initWithUTF8String:chatStatus]:@"";
tempSkeleton.chatStatus=chatStatus1;
[array addObject:tempSkeleton];
// NSLog(@"IN LOOP=>%@",array);
}
}
return array;
}
我只是改变了表并添加了两列messageID,chatstatus但这两个值显示为空。我缺少什么?