Android Question SQL Blob Null issues

DrownedBat

Member
Licensed User
Longtime User
Hello all,
I've been experimenting with an app that retrieves information from other SQL databases and creates a new database from the available data (like a registry of sorts). I've had some wonderful success with it when it comes to all other fields save for the Blob field type.

It seems to be an issue with detecting whether or not a Cursor.GetBlob("Field") is null or not. I've confirmed that the blob fields are NULL in the database, but when attempting to detect this, the program blows through the failsafes and hangs up on loading the bitmap (which does not exist).

I've gone through the following threads with no success:
https://www.b4x.com/android/forum/t...-sqlite-blob-is-empty-null.31406/#post-324273
https://www.b4x.com/android/forum/threads/blob-null.70887/#post-450080

It doesn't matter if I use "If Buffer=Null..." or "If Buffer.Length>0", it keeps detecting SOMETHING there. Just for kicks, I checked the Buffer.Length and it returned a 5. It seems strange that after I set Buffer=Null and then load the (confirmed) Null blob, the buffer.length is still returning 5. I've gotten around this by using "If Buffer.Length>10" and there's no issue, but it may create some problems down the road if I ever starting using some tiny, tiny .png files.

Any ideas out there about why/how a null Buffer has a .length of 5?
Fight on, my B4A brothers & sisters!
 

udg

Expert
Licensed User
Longtime User
According to SQLite documentation:
For a string value X, the length(X) function returns the number of characters (not bytes) in X prior to the first NUL character. Since SQLite strings do not normally contain NUL characters, the length(X) function will usually return the total number of characters in the string X. For a blob value X, length(X) returns the number of bytes in the blob. If X is NULL then length(X) is NULL. If X is numeric then length(X) returns the length of a string representation of X.

B4X:
select length(myblob) from mytable where rowid=rid;
You should end up with length(myblob) = null if myblob is null or length(myblob) = 0 if myblob is an empty string. Test it and let us know.

udg
 
Upvote 0
Top