B4J Question How to Read a BLOB image in a record and write it in another BLOB record

Diego Marcelo Croatto

Member
Licensed User
Longtime User
Hi.... I load a image form a BLOB record using GetBlob and this image need write to another BLOB record
I can't get the correct data to put into the Query chain.


I try this:

Globals:
    Dim Buffer() As Byte
    Dim SQLString As String
    Dim CursorDB As ResultSet
    Dim SQL1 As SQL
    Dim bmp As B4XBitmap


I get the image stored in 'Imagen' BLOB record where Codigo = 'BUB11000001' "FIRST RECORD" (previously loaded with an external SQLite editor)
And store it in Buffer





Get Image from BLOW Record:
    SQLString="select * FROM Productos where Codigo=('BUB11000001')"
    CursorDB = SQL1.ExecQuery(SQLString)

    Buffer = CursorDB.GetBlob("Imagen")

    If Buffer<>Null Then
    
    bmp = CMDSub.BytesToImage(Buffer)
    
    CMDSub.FitImageToView(bmp, ImageView1) 'CMDSub -->External Module and FitToView (Scale the image)

    End If


And next I try to write this image into 'Imagen' BLOB record where Codigo = 'BUB11000006' in a SQLite database but the image don't store in the BLOB format.

SQLite store:
        SQLString="UPDATE Productos SET Imagen='"& Array As Object(Buffer) &"' where Codigo=('BUB11000006')"
        Log(SQLString)
        SQL1.ExecNonQuery(SQLString)


Can anything help me.... Thank's a Lot!!!!
 

OliverA

Expert
Licensed User
Longtime User
Use ExecNonQuery2
B4X:
SQLString="UPDATE Productos SET Imagen=? WHERE Codigo=?"
Log(SQLString)
SQL1.ExecNonQuery2(SQLString, Array As Object(Buffer, "BUB11000006"))
If you are doing a lot of inserts in a row, then look into AddNonQueryToBatch/ExecNonQueryBatch (see https://www.b4x.com/b4j/help/jsql.html#sql_execnonquerybatch).

P.S.: Don't post the same/similar question more than once
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…