Android Question Initialize error in GetBlob

Smee

Well-Known Member
Licensed User
Longtime User
I have a database table with 1 test record in it. (it is there). I have loaded a picture into a blob field using this code
B4X:
    Dim InputStream1 As InputStream
    InputStream1 = File.OpenInput(File.DirDefaultExternal, Main.strFbUID & ".png")
    Dim OutputStream1 As OutputStream
    OutputStream1.InitializeToBytesArray(1000)
    File.Copy2(InputStream1, OutputStream1)
    Dim Buffer() As Byte 'declares an empty array
    Buffer = OutputStream1.ToBytesArray
   
    Dim m As Map,Table1 As List
    m.Initialize
    Table1.Initialize   
    m.Put("Name", Main.strFbName)
    m.Put("PicURL", Main.strFbPhotoUrl)
    m.Put("FbUID", Main.strFbUID)
    m.Put("Picture",Array As Object(Buffer))
    Table1.Add(m)
    ec.InsertMaps(Main.dbSQL,"Users", Table1)

I try to read the picture to an image using this code
B4X:
    Dim Cursor1 As Cursor
    Cursor1 = dbSql.ExecQuery2("SELECT Picture FROM Users WHERE FbUID=?" , Array As String(strFbUID))
    Cursor1.Position = 0
    Dim Buffer() As Byte 'declare an empty byte array
            Buffer = Cursor1.GetBlob("Picture")
            Dim InputStream1 As InputStream
            InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
            bmpName.Initialize2(InputStream1)
            InputStream1.Close
            bmpName.Initialize3(Smiley)
    Cursor1.Close

I get an error when the program trys to execute this line.
bmpName.Initialize2(InputStream1)

The error log is this

This is the first time I have used blobs or even a paramatised query so I do not really know where my error is originating. It may even be when I load the image to the database although no error is showing

Thanks for any help
 

imbault

Well-Known Member
Licensed User
Longtime User
You should try to test the buffer just after Buffer = Cursor1.GetBlob("Picture") like

B4X:
If Buffer <> Null And Buffer.Length >1 Then
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
You should try to test the buffer just after Buffer = Cursor1.GetBlob("Picture") like

B4X:
If Buffer <> Null And Buffer.Length >1 Then

Thanks I will do that. I have managed to solve it however. It seems that it would not work using a map. I changed it to the following
B4X:
Main.dbSQL.ExecNonQuery2("INSERT INTO Users VALUES(?,?,?,?)", Array As Object(Main.strFbName,Main.strFbPhotoUrl,Main.strFbUID, Buffer))

and it now works.

Thanks again
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…