### Insert a BLOB in SQLite Database

Example on how to insert a BLOB (GIF, PNG, JPG File in a SQLite database.
Table: Images; Fields: ID, Title TEXT, Image BLOB
`Sub Process_Globals
Private gSQL As SQL
...
End Sub`
'Insert will be in table Images the Blobfilename as title and the blob file
'When testing ensure the blob files are in the objects folder
`Sub InsertBlob(blobname As String)
Log("SQL Insert BLOB :: Start")
If File.Exists(File.DirApp, blobname) = False Then
Log("BLOB File NOT Exists: " & File.DirApp & ", " & blobname)
Return
End If
Log("BLOB File Exists: " & File.DirApp & ", " & blobname)
'convert the image file to a bytes array
Dim InputStream1 As InputStream
InputStream1 = File.OpenInput(File.DirApp, blobname)
Dim OutputStream1 As OutputStream
OutputStream1.InitializeToBytesArray(1000)
File.Copy2(InputStream1, OutputStream1)
Dim Buffer() As Byte 'declares an empty array
Buffer = OutputStream1.ToBytesArray
'write the image to the database
Log("SQL Insert ...")
gSQL.ExecNonQuery2("INSERT INTO images VALUES(NULL, ?, ?)", Array As Object(blobname, Buffer))
Log("SQL Insert BLOB :: End")
End Sub`
Test with
InsertBlob("blobtest.gif")
InsertBlob("blobtest.bmp")
InsertBlob("blobtest.png")

Changed: , Category: SQLite, File: T6C254M1829.htm, ID: 1829