码迷,mamicode.com
首页 > 数据库 > 详细

sqlite3 数据操作 查询单个信息

时间:2014-09-20 02:21:46      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:sqlite3 数据操作 查询单个信息



 打开数据库
    sqlite3 * db = [Database openDB];
    
    sqlite3_stmt * stmt = nil;
    NSString * sqlString = [NSString stringWithFormat:@"select * from Student where id = %d" , aID];
    int result = sqlite3_prepare_v2(db, [sqlString UTF8String], -1, &stmt,NULL);
    Student * student = nil;
    if (result == SQLITE_OK) {
        if (sqlite3_step(stmt) == SQLITE_ROW) {
            int ID = sqlite3_column_int(stmt, 0);


            const unsigned char * name = sqlite3_column_text(stmt, 1);
            
            const unsigned char * gender = sqlite3_column_text(stmt ,2);
            int age = sqlite3_column_int(stmt, 3);
            
            int lenght = sqlite3_column_bytes(stmt, 4);
            
            const void * photo = sqlite3_column_blob(stmt, 4);
            
            NSData * photoData = [NSData dataWithBytes:photo length:lenght];
            
            UIImage * image = [UIImage imageWithData:photoData];
            
            student = [[Student alloc]init];
            student.ID = ID;
            student.name = [NSString stringWithUTF8String:(const char *)name];
            student.gender = [NSString stringWithUTF8String:(const char *)gender];
            student.age = age;
            
            student.photo = image;
            
            
        }
    }
    
    sqlite3_finalize(stmt);
    [Database closeDB];

sqlite3 数据操作 查询单个信息

标签:sqlite3 数据操作 查询单个信息

原文地址:http://qccccc.blog.51cto.com/6004423/1555368

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!