方法實(shí)例中數(shù)據(jù)庫鍵值分別為: 0:id,1:title笙什,2:price胚想,3:image,4:goodsid,5:number
其中id為主鍵统屈,goodsid為商品編號(hào)veriable代表變量牙躺,count代表計(jì)數(shù),其中column方法中的count代表對應(yīng)鍵值在數(shù)據(jù)庫中的位置孽拷,從0開始;而bind方法中的count代表對應(yīng) sqlite3_prepare_v2()方法中的未確定變量(即問好)的位置膜宋,bind中的count從1開始进肯,逐一替換prepare語句中的問號(hào)棉磨。
一、SQLite3語句前期準(zhǔn)備
文件導(dǎo)入
#import<sqlite3.h>
1.SQLite3常用語句
column方法:
veriable = sqlite3_column_int(stmt, count)
veriable = sqlite3_column_double(stmt, count)
veriable = sqlite3_column_text(stmt, count)
圖片加載步驟:
int length = sqlite3_column_bytes(stmt, count)//返回?cái)?shù)據(jù)的字節(jié)長度
const void * value = sqlite3_column_blob(stmt, count)\//獲取數(shù)據(jù)的二進(jìn)制內(nèi)容
NSData * imageData = [NSData dataWithBytes:value length:length];//將二進(jìn)制位(blob)轉(zhuǎn)換為NSData的類型乘瓤,用于保存圖音視頻信息
——column函數(shù)用來讀取數(shù)據(jù)庫單個(gè)鍵值的內(nèi)容,count代表該條鍵值在數(shù)據(jù)庫中的位置衙傀,計(jì)數(shù)從0開始,一一對應(yīng)
bind方法:
sqlite3_bind_int(stmt, 1, goodsID);
sqlite3_bind_double(stmt, 2, newPrice);
sqlite3_bind_text(stmt, 1, [newName UTF8String], -1, nil);
sqlite3_bind_blob(stmt, 3, [imageData bytes], (int)[imageData length], nil);
——bind函數(shù)用于捆綁prepare語句火本,兩語句一起組成數(shù)據(jù)庫操作方法