-(NSMutableArray *)getStudentsInfo
{
NSMutableArray *studentsList = [[NSMutableArray alloc]init];
sqlite3_stmt* getStatement;
const char* sql = "select * from Person";
if (sqlite3_prepare_v2(database, sql, -1, &getStatement, NULL) != SQLITE_OK)
{
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
else{
while (sqlite3_step(getStatement) == SQLITE_ROW)
{
Person* pObj = [[Person alloc]init];
pObj.pNumber = sqlite3_column_int(getStatement,0);
pObj.pName = [NSString stringWithUTF8String:(char*)sqlite3_column_text(getStatement, 1)];
NSLog(@"Student Name is %@",pObj.pName);
pObj.pRoundTime = [NSString stringWithUTF8String:(char*)sqlite3_column_text(getStatement, 2)];
NSLog(@"Student Class is %@",pObj.pRoundTime);
pObj.pRoundCount = [NSString stringWithUTF8String:(char*)sqlite3_column_text(getStatement, 3)];
NSLog(@"Student Section is %@",pObj.pRoundCount);
pObj.pRestTime = [NSString stringWithUTF8String:(char*)sqlite3_column_text(getStatement, 4)];
NSLog(@"Student Section is %@",pObj.pRestTime);
pObj.pAlertTime = [NSString stringWithUTF8String:(char*)sqlite3_column_text(getStatement, 5)];
NSLog(@"Student Section is %@",pObj.pAlertTime);
pObj.pPreparationTime = [NSString stringWithUTF8String:(char*)sqlite3_column_text(getStatement, 6)];
NSLog(@"Student Section is %@",pObj.pPreparationTime);
[studentsList addObject:pObj];
}
printf("Successfully retrieved data from database");
}
sqlite3_finalize(getStatement);
return studentsList;
}
我在這裏有一個問題,我已經存儲所有這些字段存儲爲一個sqlite數據庫中的浮動值,除了前兩個字段。但是,當我想用select查詢我不會和顯示的記錄,以獲取所有這些記錄,並顯示如下錯誤:如何獲取存儲在sqlite數據庫中的float值?
*終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,原因是:「* + [NSString的stringWithUTF8String:]:NULL CSTRING」
eventhough我用sqlite3_column_double其示值誤差如雙不能點與他人。你能否正確寫下陳述 – subbu
我更新我的答案,查看。 –