溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

sqlite 數據 格式轉化

發布時間:2020-07-22 04:08:36 來源:網絡 閱讀:789 作者:緣起愿落 欄目:開發技術




    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) //存在一行數據
        {
        


從數據庫中取出NSInteger 格式的數據

            int ID = sqlite3_column_int(stmt, 0);
           

從數據庫中取出 text  格式的數據      

   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. 獲取數據
            const void * photo = sqlite3_column_blob(stmt, 4);
            
           

3.轉換成NSData
            
            NSData * photoData = [NSData dataWithBytes:photo length:length];
         

4.轉成 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;
            
           

添加到數組中
            [studentArray addObject:student];
        }
    }

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女