How to check if a BLOB is null

How do you check if a column value in a SQLite database is null if it is of type Blob?

I get the cursor as follows:

public Cursor fetchArticle(int i) throws SQLException { Cursor mCursor = mDatabase.query(true, "api_content", new String[] { "_id", "ArticleName", "ArticleText","ImageLink", "Image" }, KEY_ID + "=" + i, null, null, null, null, null); if (mCursor != null) { mCursor.moveToFirst(); } return mCursor; } 

How to check if the value of the Image, index 4 column is null? I tried the following:

  • Using the isNull () method, which always returns false when in fact the value should certainly be null
  • Using articleCursor.getBlob(4) == null , where articleCursor is a valid cursor (returns false)

To complicate matters even further when I print out articleCursor.getBlob(4)[0] , it returns values ​​like 78 or 91 that are not like something that I consider null .

And again, it is not possible for the database to have any data in this column; it must be zero. Any ideas? Thanks!

+4
source share
2 answers

Below is the query to get the value of Y or N

 select id, case when myblob is not null then 'Y' else 'N' end, myblob 

If blob is null, it returns N else Y.

-2
source

The getBlob () method always matters. If the value of this column is empty or zero when you use the length of the method, the result is 1.

Example:

 byte[] image = cursor.getBlob(cursor.getColumnIndex("image")); if(image.length == 1) { //column data is empty } else{ //column has data } 

I hope this can help you.

-2
source

Source: https://habr.com/ru/post/1385245/


All Articles