溫馨提示×

溫馨提示×

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

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

sqlite3 數(shù)據(jù)操作 查詢單個信息

發(fā)布時間:2020-07-18 16:52:26 來源:網(wǎng)絡 閱讀:671 作者:緣起愿落 欄目:開發(fā)技術



 打開數(shù)據(jù)庫
    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 * p_w_picpath = [UIImage p_w_picpathWithData: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 = p_w_picpath;
            
            
        }
    }
    
    sqlite3_finalize(stmt);
    [Database closeDB];

向AI問一下細節(jié)

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

AI