I copied this code from the tutorial on SQL. My aim is to take a picture with the camera have a very simple database with two columns (name Text, image BLOB). Cant quiet tell what is wrong but reading back the file from the sql database cause my app to stop...I think the syntax is wrong, but not sure why, when perhaps saving to and reading from the database. Perhaps someone can tell me where i am going wrong please.
I mean in the SQL write and read statements...
Dim blobfilename as string.....contains the file name of my camera jpg
I mean in the SQL write and read statements...
Dim blobfilename as string.....contains the file name of my camera jpg
B4X:
Sub InsertBlob
'convert the image file to a bytes array
Dim InputStream1 As InputStream
InputStream1 = File.OpenInput(File.DirDefaultExternal, BlobFileName)
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 Photos VALUES(?, ?)", Array As Object(BlobFileName, Buffer))
End Sub
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 Photos WHERE name = ?", Array As String(BlobFileName))
Dim Buffer() As Byte 'declare an empty byte array
Cursor1.Position = 0
Buffer = Cursor1.GetBlob("image")
Dim InputStream1 As InputStream
InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
Dim Bitmap1 As Bitmap
Bitmap1.Initialize2(InputStream1)
InputStream1.Close
Panel1.SetBackgroundImage(Bitmap1)
End Sub