1

I want to store blob data into sqlite, It adds imageData as null although bloc has value. What should I put bloc value into sql?

String x = getResultAsOnlyValue("soapImage", xdata);
byte[] bloc = Base64.decode(x, Base64.DEFAULT);
Bitmap bmp = BitmapFactory.decodeByteArray(bloc,0,bloc.length);
SQLiteStatement statement =  db.compileStatement("insert into ImageTable (imageData) values(?)"); 
statement.bindBlob(0, bloc); 
statement.execute();
Mustafa Güven
  • 15,526
  • 11
  • 63
  • 83

2 Answers2

1

EDITED: ANSWER TO THE QUESTION

String x = getResultAsOnlyValue("soapImage", xdata);
byte[] bloc = Base64.decode(x, Base64.DEFAULT);
Bitmap bmp = BitmapFactory.decodeByteArray(bloc,0,bloc.length);
SQLiteDatabase db = getDb();
ContentValues values = new ContentValues();
values.put("ImageData", bloc);
db.insert("imageTable", null, values);

After this operation if you get NS_ERROR_FILE_CORRUPTED error while trying to run the db via sqlitemanager that means you need to upgrade your db to sqlite3. In this link it tells you to how to do this.

Community
  • 1
  • 1
Mustafa Güven
  • 15,526
  • 11
  • 63
  • 83
0

Good morning, try this answer out: Convert Drawable to BLOB Datatype

I think it's what you're looking for.

Community
  • 1
  • 1
dbDev
  • 1,553
  • 1
  • 15
  • 22
  • actually I guess the problem is related to sqlitemanager version because it throws "NS_ERROR_FILE_CORRUPTED" error after adding blob data. After some googling i found this faq, "I get an error while trying to open/connect to an sqlite db file. Why?" If you get an error, an alert shows the exception name: NS_ERROR_FILE_CORRUPTED. This could be due to (a) the file you are opening is not an sqlite db file, or (b) you are trying to open an sqlite db file created with an older library of sqlite To convert from sqlite2 to sqlite3, please follow the instructions at Convert_sqlite2_to_sqlite3_format – Mustafa Güven Feb 22 '12 at 15:03