iPhone學習 Sqlite資料庫讀寫圖片執行個體是本文要介紹的內容,內容不多,基本是基於代碼實現,我們來看內容講解。用 iPhone 的 sqlite 資料庫讀寫圖片,先把你的圖片轉換成 NSData 形式,然後在資料庫添加一行 blob 資料,代碼如下data就是圖片) :
- NSMutableString *insertSql = [[NSMutableString alloc] initWithString:@"INSERT INTO "];
- [insertSql appendString:BLOB];
- [insertSql appendString:@" ("];
- [insertSql appendString:BLOB_DATA];
- [insertSql appendString:@") VALUES(?1)"];
- sqlite3_stmt *insert_statement = nil;
- sqlite3 *database = 你的資料庫;
- if (sqlite3_prepare_v2(database, [insertSql UTF8String], -1, &insert_statement, NULL) == SQLITE_OK) {
- sqlite3_bind_blob(insert_statement, 1, [data bytes], [data length], NULL);
- if(sqlite3_step(insert_statement) != SQLITE_DONE) {
- NSLog(@"Db error %s", sqlite3_errmsg(database));
- }
- } else {
- NSLog(@"Db error %s", sqlite3_errmsg(database));
- }
- sqlite3_finalize(insert_statement);
- [insertSql release];
小結:iPhone學習 Sqlite資料庫讀寫圖片執行個體的內容介紹完了,希望本文對你有所協助!