Android Question DBUTILS update record with image and WHERE clause

Discussion in 'Android Questions' started by FormCommander, May 9, 2018.

  1. FormCommander

    FormCommander Member Licensed User

    Hello,
    have successfully made my first steps with databases, works great, but now I stuck on a simple thing. I want to insert a image in a BLOB field. Found the way to do this, but cannot create the UPDATE statement, get always an SQL query error. How can I do this with DBUTILS or a SQL statement ?
    regards
    Rudolf

    Sub Insert_rec (nPUserID As Int,cPOrderID As String ,cPText As String ,cPBarCode As String,cPObject As String,cPLong As String,cPLat As String ,cPDate As String,cPImage As String) As Boolean

    Dim ListOfMaps As List
    ListOfMaps.Initialize
    Dim nID As Int
    Dim dbmap As Map
    dbmap.Initialize

    dbmap.put("ORDER_ID",cPOrderID)
    dbmap.put("USER_ID",nPUserID)
    dbmap.put("TEXT",cPText)
    dbmap.put("BARCODE",cPBarCode)
    dbmap.put("LONG",cPLong)
    dbmap.put("LAT",cPLat)
    dbmap.put("DATETIME",cPDate)
    dbmap.put("OBJECT",cPObject)
    dbmap.put("IMAGE",cPImage)
    dbmap.put("SYNC",0)

    ListOfMaps.Add(dbmap)
    DBUtils.InsertMaps(SQLobj,"photos",ListOfMaps)

    Dim cCur As Cursor
    cCur = SQLobj.ExecQuery("SELECT last_insert_rowid()")
    cCur.Position = 0
    nID = cCur.GetInt2(0)
    Log("Last ID:" & nID)
    ListOfMaps.Clear

    InsertBlob(nID,cPhotoDir,cPhotoFile)

    Return True
    End Sub

    Sub InsertBlob(nID As Int, cDir As String,cFile As String)
    'convert the image file to a bytes array
    Dim InputStream1 As InputStream
    InputStream1 = File.OpenInput(cDir,cFile)
    Dim OutputStream1 As OutputStream
    OutputStream1.InitializeToBytesArray(1000)
    File.Copy2(InputStream1, OutputStream1)
    Dim Buffer() As Byte 'declares an empty array
    Buffer = OutputStream1.ToBytesArray

    SQLobj.ExecNonQuery2("UPDATE photos SET IMAGE (?) WHERE ID = " & nID, Array As Object(Buffer))



    End Sub
     
  2. DonManfred

    DonManfred Expert Licensed User

    1. Use code tags when posting code!

    2. Try it with
    Code:
    SQLobj.ExecNonQuery2("UPDATE photos SET IMAGE =? WHERE ID = ?"Array As Object(Buffer,nID))
     
  3. FormCommander

    FormCommander Member Licensed User

    Hello DonManfred,
    Thank you ! seems to work, no more error.
    I did not find a way to tag code, no icon for this in the editor, how to do this ?
    regards
    Rudolf
     
  4. DonManfred

    DonManfred Expert Licensed User

  5. FormCommander

    FormCommander Member Licensed User

    Tank you ! did not check the insert details
    regards
    Rudolf
     
  6. Star-Dust

    Star-Dust Expert Licensed User

    See also this library:
    https://www.b4x.com/android/forum/threads/sd-sqliteextra.90805/

    Method ReadBitmap and UpdateBitmap
     
  7. FormCommander

    FormCommander Member Licensed User

    Hello,
    great ! that makes some thing much easiser
    regards
    Rudolf
     
  8. Star-Dust

    Star-Dust Expert Licensed User

    Of nothing ... but Rudolf is a woman's name in Austria?
     
  9. DonManfred

    DonManfred Expert Licensed User

    Only in the Evening when Rudolf transform itself into a Rudolfine :D
    Sorry, couldn´t resist. Don´t take it too serious, Rudolf ;-)
     
    Johan Hormaza and Star-Dust like this.
  10. FormCommander

    FormCommander Member Licensed User

    Hello,
    DonManfred: you are right, but I dont think that there is a Rudolfine here in Austria with 190 tall and 120 kilos ;-)
    regards
    Rudolf
     
    DonManfred likes this.
  11. Star-Dust

    Star-Dust Expert Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice