Android Question SQLLite and images

malcfreem

Member
Licensed User
Longtime User
Hi everyone. My new app is coming along very nicely now.

I have successfully created an SQLLite database and a table within it. Ultimately, records will be downloaded and inserted into my table, but for now I simply want to add a BLOB field to my table and then insert an image programmatically. I am thinking I could add bitmaps to the project, but how, then, can I insert them in the new field?

For testing purposes I start by deleting the database if present, then adding 4 dummy records to my table using CREATE TABLE in an ExecNonQuery and then using ExecNonQuery2 (to handle field types) to insert the four records.

Can you please advise (preferably with a bit of code as an example) how I do this?

Thanks in anticipation of any help - very much appreciated.

Malcolm
 

mangojack

Well-Known Member
Licensed User
Longtime User
Have you searched the forum ? There are tutorials available showing how to do just that.
In fact the first Tutorial by Erel in "Similar Threads' at the top of the page has sample code to do just that

As it turns out only last night I created a simple app using that code just to test storing and retrieving an image from a db.

I offer it to you to display the very basics of what your trying to achieve.
 

Attachments

  • ImageDB Test.zip
    55.9 KB · Views: 640
Upvote 0

mkvidyashankar

Active Member
Licensed User
Longtime User
i am trying to update imagefield using this code

B4X:
Dim OutputStream1 As OutputStream
        OutputStream1.InitializeToBytesArray(1000)
        bitmap_small.WriteToStream(OutputStream1,100,"JPEG")
               
        Dim Buffer() As Byte
        Buffer = OutputStream1.ToBytesArray
        
    'write the image to the database
        sql1.ExecNonQuery2("UPDATE player SET profilepic VALUES(?) where playername= '" & pname & "'", Array As Object(Buffer))

but getting syntax error in sql statement near VALUES. please help
 
Upvote 0

mkvidyashankar

Active Member
Licensed User
Longtime User
yes got it

B4X:
sqlstring = "UPDATE player SET profilepic = ?  where playername= '" & pname & "'"
 
Upvote 0
Top