温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

sqlite 数据 格式转化

发布时间:2020-07-22 04:08:36 来源:网络 阅读:739 作者:缘起愿落 栏目:开发技术




    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