Android Question read and write BLOB text field SQLite

Discussion in 'Android Questions' started by magi6162, Jul 2, 2015.

  1. magi6162

    magi6162 Well-Known Member Licensed User

    I can not read and write a blob field of a table in SQLite .
    can anyone help me ?
    maybe an example ?

  2. derez

    derez Expert Licensed User

  3. magi6162

    magi6162 Well-Known Member Licensed User

    i see
    example image not text

    help me please

  4. derez

    derez Expert Licensed User

    This is how you get a blob from a DB and convert it to a string, where "res" is the result of the query to the DB:
    Dim Buffer() As Byte 'declare an empty byte array
        Buffer = res.GetBlob("Info")
    Dim InputStream1 As InputStream
    0, Buffer.Length)
    Dim bc As ByteConverter
    Dim st As String = bc.StringFromBytes(Buffer, "UTF8")
    After that you can use File.WriteString to put the string in a file.

    To put a blob in the DB :
    Dim InputStream1 As InputStream
            InputStream1 = 
    File.OpenInput([file directory],[file name])
    Dim OutputStream1 As OutputStream
    File.Copy2(InputStream1, OutputStream1)
    Dim Buffer() As Byte 'declares an empty array
            Buffer = OutputStream1.ToBytesArray
    Then insert the buffer to the DB as blob.
    Last edited: Jul 4, 2015
    B4JExplorer likes this.
  5. keirS

    keirS Well-Known Member Licensed User

    The limits of a text field and a blob field are the same in SQLite. So there is little advantage to storing text in a blob.
  6. magi6162

    magi6162 Well-Known Member Licensed User

    Thank you

  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