已先使用FMDB讀取sqlite的某一table J的值
程式:
NSMutableArray* JData = [NSMutableArray arrayWithCapacity: 0];
FMResultSet *rs = [db executeQuery: @"SELECT uid, uidY, uidH, uidT, uidO from J"];
while ([rs next]) {
int uid = [rs intForColumn: @"uid"];
int uidY = [rs intForColumn: @"uidY"];
int uidH = [rs intForColumn: @"uidH"];
int uidT = [rs intForColumn: @"uidT"];
int uidO = [rs intForColumn: @"uidO"];
[JData addObject: [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: uid], @"uid",
[NSNumber numberWithInt: uidY], @"uidY",
[NSNumber numberWithInt: uidH], @"uidH",
[NSNumber numberWithInt: uidT], @"uidT",
[NSNumber numberWithInt: uidO], @"uidO",
nil]];
}
NSLog(@"%@", JData[2]);
結果:
uid = 3;
uidH = 0;
uidO = 3;
uidT = 0;
uidY = 98;
程式設計的目的:
讀取table J的值轉成二維陣列
以便直接讀取特定位置的值進行運算
請問:
1. 輸出結果順序與讀取順序不同,應如何修正?
讀取sqlite的table J欄位順序:uid, uidY, uidH, uidT, uidO
但顯示讀取後的欄位值順序卻是:uid, uidH, uidO, uidT, uidY
2. 如何讀取特定位置的值?
資料庫就像二維陣列
雖然可以讀取某列的值(如:JData[2]列出uid, uidH, uidO, uidT, uidY)
但要如何讀取某列某行的值(如:JData[2][2])
謝謝