1

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 ?

P.S

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...

Asaf Nevo
  • 11,338
  • 23
  • 79
  • 154

1 Answers1

0

To insert a blob value with a SQL string, you have to convert the bytes to hex and use a blob literal:

INSERT INTO MyTable(blob) VALUES(x'123456abcdef')
CL.
  • 173,858
  • 17
  • 217
  • 259
  • No. With what particular part of this do you habe a problem? – CL. Sep 10 '13 at 07:09
  • converting the byte[] to hex ... should i convert it to hex before the sql query, or should i let the sql system to convert the byte[] string to hex ? – Asaf Nevo Sep 10 '13 at 15:09
  • 1
    Only `ContentValues` can handle byte arrays. For usage in a SQL string, you have to do [the conversion yourself](http://stackoverflow.com/questions/2817752/java-code-to-convert-byte-to-hexadecimal). – CL. Sep 10 '13 at 17:01