B4J Question Save SQLite BLOB field to binary file?

tsteward

Well-Known Member
Licensed User
Longtime User
I want to save the data in a BLOB field to a binary file but don't know how.

My failed code
B4X:
Dim dumpdata As ResultSet = sql1.ExecQuery("SELECT * FROM BINFiles WHERE FileID = '1'")
    Do While dumpdata.NextRow
        File.WriteString(File.DirApp,"testdump.bin",dumpdata.GetBlob("data"))
    Loop
    dumpdata.Close
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You cannot use WriteString with binary data.
Do you assume that there is a single matching result? Otherwise your code will overwrite the file.
B4X:
Dim b() As Byte = dumpData.GetBlob(...)
Dim out As OutputStream = File.OpenOutput(File.DirApp,"testdump.bin")
out.WriteBytes(b, 0, b.Length)
out.Close
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Thank Erel,
Yes I know there is a single match result. This is also just test code to see if my idea will work.
 
Upvote 0
Top