iPhone學習 Sqlite資料庫讀寫圖片執行個體

來源:互聯網
上載者:User

iPhone學習 Sqlite資料庫讀寫圖片執行個體是本文要介紹的內容,內容不多,基本是基於代碼實現,我們來看內容講解。用 iPhone sqlite 資料庫讀寫圖片,先把你的圖片轉換成 NSData 形式,然後在資料庫添加一行 blob 資料,代碼如下data就是圖片) :

 
  1. NSMutableString *insertSql = [[NSMutableString alloc] initWithString:@"INSERT INTO "];  
  2. [insertSql appendString:BLOB];  
  3. [insertSql appendString:@" ("];  
  4. [insertSql appendString:BLOB_DATA];  
  5. [insertSql appendString:@") VALUES(?1)"];  
  6. sqlite3_stmt *insert_statement = nil;  
  7. sqlite3 *database = 你的資料庫;  
  8. if (sqlite3_prepare_v2(database, [insertSql UTF8String], -1, &insert_statement, NULL) == SQLITE_OK) {  
  9.     sqlite3_bind_blob(insert_statement, 1, [data bytes], [data length], NULL);  
  10.     if(sqlite3_step(insert_statement) != SQLITE_DONE) {  
  11.         NSLog(@"Db error %s", sqlite3_errmsg(database));  
  12.     }  
  13. } else {  
  14.     NSLog(@"Db error %s", sqlite3_errmsg(database));  
  15. }  
  16. sqlite3_finalize(insert_statement);  
  17. [insertSql release];  

小結:iPhone學習 Sqlite資料庫讀寫圖片執行個體的內容介紹完了,希望本文對你有所協助!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.