Blobs
The last two methods write an image file to the database and then read it and set it as the activity background.
Code:
Sub InsertBlob
'convert the image file to a bytes array
Dim InputStream1 As InputStream
InputStream1 = File.OpenInput(File.DirAssets, "smiley.gif")
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
SQL1.ExecNonQuery2("INSERT INTO table2 VALUES('smiley', ?)", Array As Object(Buffer))
End Sub
Here we are using a special type of OutputStream which writes to a dynamic bytes array.
File.Copy2 copies all available data from the input stream into the output stream.
Then the bytes array is written to the database.
Code:
Sub ReadBlob
Dim Cursor1 As Cursor
'Using ExecQuery2 is safer as it escapes special characters automatically.
'In this case it doesn't really matter.
Cursor1 = SQL1.ExecQuery2("SELECT image FROM table2 WHERE name = ?", Array As String("smiley"))
Cursor1.Position = 0
Dim Buffer() As Byte 'declare an empty byte array
Buffer = Cursor1.GetBlob("image")
Dim InputStream1 As InputStream
InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
Dim Bitmap1 As Bitmap
Bitmap1.Initialize2(InputStream1)
InputStream1.Close
Activity.SetBackgroundImage(Bitmap1)
End Sub