您好,登錄后才能下訂單哦!
sqlite3 * db = [Database openDB];
sqlite3_stmt * stmt = nil
int result = sqlite3_prepare_v2(db, "select * from Student", -1, &stmt, NULL);
NSMutableArray * studentArray = [NSMutableArray array];
if (result == SQLITE_OK)
{
while (sqlite3_step(stmt) == SQLITE_ROW) //存在一行數(shù)據(jù)
{
從數(shù)據(jù)庫中取出NSInteger 格式的數(shù)據(jù)
int ID = sqlite3_column_int(stmt, 0);
從數(shù)據(jù)庫中取出 text 格式的數(shù)據(jù)
const unsigned char * name = sqlite3_column_text(stmt, 1);
const unsigned char * gender = sqlite3_column_text(stmt, 2);
blob 類型的獲取
1. 獲取長度
int length = sqlite3_column_bytes(stmt, 4);
2. 獲取數(shù)據(jù)
const void * photo = sqlite3_column_blob(stmt, 4);
3.轉(zhuǎn)換成NSData
NSData * photoData = [NSData dataWithBytes:photo length:length];
4.轉(zhuǎn)成 UIImage
UIImage * p_w_picpath = [UIImage p_w_picpathWithData:photoData];
封裝Student模型
Student * student = [[Student alloc]init];
student.ID = ID;
student.name = [NSString stringWithUTF8String:(const char*)name];
student.age = age;
student.gender = [NSString stringWithUTF8String:(const char *)gender];
student.photo = p_w_picpath;
添加到數(shù)組中
[studentArray addObject:student];
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。