Android Question Insert String (Base64) in SQLITE

ricardo selle

Member
Licensed User
Hello,
I'm trying to send to SQLITE a string with data type BASE64.

Any query for the record before entering the string with 64 type, gets return OK.

But after modifying the record by saving the "Image" field, a problem occurs, and any query returns error when accessing the record.

SQL structure:
-----------------------------
ID_Image (INT auto)
Image (BLOB) *//but I already tried TEXT


Code:

*// Base64Image library is correctly referenced.
*// Database is correctly associated with dbSQL.


Sub Globals
Dim Base64Con As Base64Image
End Sub

Sub Camera1_PictureTaken (Data() As Byte)

camera1.StartPreview
Dim out As OutputStream

out = File.OpenOutput(strFilePath, strFileName, False) 'strFilePath and strFileName is predefined.
out.WriteBytes(Data, 0, Data.Length)
out.Close

'convert Image to string
Dim B64Str As String
B64Str = Base64Con.EncodeFromImage(CaminhoExportar, strNomeArquivo)

dbSQL.ExecNonQuery("UPDATE tbl_image Set Image = '" & B64Str & "' WHERE ID_image = " & intImageCode) 'intImageCode is predefined.


End Sub

So far so good. No fault occurs.
The problem is that when accessing this data at another time, access error occurs in dbCursor.
 

DonManfred

Expert
Licensed User
Longtime User
Please use [CODE]code here...[/CODE] tags when posting code.

codetag001.png

codetag002.png

codetag003.png
 
Upvote 0

ricardo selle

Member
Licensed User
B4X:
Sub Camera1_PictureTaken (Data() As Byte)

camera1.StartPreview
Dim out As OutputStream

out = File.OpenOutput(strFilePath, strFileName, False) 'strFilePath and strFileName is predefined.
out.WriteBytes(Data, 0, Data.Length)
out.Close

'convert Image to string
Dim B64Str As String
B64Str = Base64Con.EncodeFromImage(CaminhoExportar, strNomeArquivo)

dbSQL.ExecNonQuery("UPDATE tbl_image Set Image = '" & B64Str & "' WHERE ID_image = " & intImageCode) 'intImageCode is predefined.


End Sub
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
The problem is that when accessing this data at another time, access error occurs in dbCursor
What is the error?

Shooting from the hip (not knowing what the error is): I think you're running into an issue with the size limitation of a SQL statement (if not now, you will in the future). The way you are doing the image saving now, you are making the Base64 string part of the SQL string that updates the database. That may cause issues with certain image sizes (especially since Base64 encoding enlarges the data needing to be stored). The default limit for SQLite for the length of an SQL statement is 1000000 (https://www.sqlite.org/limits.html). You should really look into ExecNonQuery2 (here: https://www.b4x.com/b4j/help/jsql.html#sql_execnonquery2).
 
Upvote 0
Top