B4J Question ExecQuerySingleResult Unable To Retrieve Blob Field?

RichardN

Well-Known Member
Licensed User
Longtime User
An SQLite database contains images stored in a Blob field referenced against a unique name. If the clue returns no result the Sub should return Null. I am having a problem with ExecQuerySingleResult. The Log shows:
Main - 178: Cannot cast type: {Type=String,Rank=0, RemoteObject=True} to: {Type=Byte,Rank=1, RemoteObject=True}

I have tried passing the search parameter as an Object instead of a String with no success. Can SingleResult only ever retrieve String Data? I don't understand this?

Return an Image or Null if not found:
Private Sub GetPicture(clue As String) As Image
    
    Dim Buffer() As Byte
    
    'Picture is a Blob field
    'UniqueName a string field
    
    Buffer = SqlPictureDb.ExecQuerySingleResult2("SELECT Picture FROM Photos WHERE UniqueName = ?",Array As String(clue))
    
    If Buffer.Length = 0 Then Return Null
    
    Dim InputStream1 As InputStream
    InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
    
    Dim Img As Image
    Img.Initialize2(InputStream1)
    InputStream1.Close
    Return Img
    
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…