Android Question read and write BLOB text field SQLite

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

  1. magi6162

    magi6162 Active Member Licensed User

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

    thanks
     
  2. derez

    derez Expert Licensed User

  3. magi6162

    magi6162 Active Member Licensed User

    i see
    example image not text

    help me please

    thanks
     
  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:
    Code:
    Dim Buffer() As Byte 'declare an empty byte array
        Buffer = res.GetBlob("Info")
        
    Dim InputStream1 As InputStream
        InputStream1.InitializeFromBytesArray(Buffer, 
    0, Buffer.Length)
        
    Dim bc As ByteConverter
        
    Dim st As String = bc.StringFromBytes(Buffer, "UTF8")
        InputStream1.Close
    After that you can use File.WriteString to put the string in a file.

    To put a blob in the DB :
    Code:
    Dim InputStream1 As InputStream
            InputStream1 = 
    File.OpenInput([file directory],[file name])
            
    Dim OutputStream1 As OutputStream
            OutputStream1.InitializeToBytesArray(
    1000)
            
    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 Active Member Licensed User

    Thank you

    :):):)
     
Loading...