简体   繁体   中英

Android Sqlite insert Drawable to db using rawquery()

I have a table with a Blob datatype column which saves profile pictures (small Drawlable object).

Usually i would run the SqLiteDatabse.insert() method with ContentValues object so all the converting stuff wont be implement by me.

From my own reasons i need to use an "Insert or Replace" Sqlite query and to insert the profile picture's Drawable using a String query so i will have to implement my own convertion from byte[] to String in order to use the SqLiteDatabse.rawQuery() method.

can you please provide a way of doing it manually and not using ContentValue object ?

PS

I can solve this by creating 2 queries:

  1. check if the raw exists
  2. if not - create it, if so - update it

and then i will be able to use the ContentValue object conveniently. but it sounds really inefficient to do so...

要插入带有SQL字符串的blob值,必须将字节转换为十六进制并使用blob文字

INSERT INTO MyTable(blob) VALUES(x'123456abcdef')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM