Android Question Read BLOB from SQLite and INSERT INTO MySQL BLOB

eduardo74

Member
Licensed User
Longtime User
I testing photo capture application, for making albums.
Picture are stored into SQLite db, but cannot insert into MySQL.

I using MYSQL lib and in

reading BLOB with :

....
Dim upic() AS Byte

baza1.Position = 0

upic= baza1.GetBlob("picture")
.....

and then wish to send to Mysql with statement:

query="INSERT INTO pics (pictures) VALUES ('" & Array As Object(upic) & "')"
db.ExecuteNonQuery(query)


row is inserted, but only 27 bytes instead of picture with cca 280kB.

Any idea?
 

OliverA

Expert
Licensed User
Longtime User
First: Please use code tags for your code.

Your probably saving only the array reference to your project. Technically, you should not need the
B4X:
Array As Object
but just use upic. The problem with that is that you may blow through the allowable statement size of your given SQL database. You should be using a prepared statement and ExecuteNonQuery2 to insert the byte array into your database.

B4X:
query="INSERT INTO pics (pictures) VALUES(?)"
db.ExecuteNonQuery2(query, Array As Object(upic))

Please note that in this case you do need to use
B4X:
Array As Object
, since it is a different use case for the variable.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
If you are using @DonManfred's library, then look into the PreparedStatement, SetPreparedBlob, and ExecutePreparedStatement methods. If you have any issues with that, you'll need to have some input from someone that has used these methods (I have not, nor do I have any experience using @DonManfred's library).
 
Upvote 0
Top