Android Question [Solved] SQLite record byte

Discussion in 'Android Questions' started by makis_best, Apr 26, 2019.

  1. makis_best

    makis_best Active Member Licensed User

    Hi

    I have a table and I want to find how many bytes is every record.
    Is that possible?

    For example I have the table test with records

    AA Name Phone
    1 John 1234567890
    2 Tomas 7653345768
    3 Peter 3436467793

    and I want to get
    Record 1 total bytes 23
    Record 2 total bytes 28
    Record 3 total bytes 19

    Thank you
     
  2. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    I'm not aware of any built in SQLite function that returns the size of a row. You would probably have to read in each row & then calculate the size of it in your app based on the data in it.

    - Colin.
     
  3. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Something like this should work:

    Code:
    Sub TestGetByteCountRows
     
     
    Dim strSQL As String
     
    Dim lByteCount As Long
     
     strSQL = 
    "select rowid, * from table1 where rowid < 100"     
     lByteCount = GetByteCountRows(strSQL, 
    "table1")
     
    Log("TestGetByteCountRows, Bytes: " & lByteCount)
     
    End Sub

    Sub GetByteCountRows(strSQL As String, strTable As StringAs Long
     
     
    Dim c As Int
     
    Dim n As Long
     
    Dim strSQL2 As String
     
    Dim lByteCountRow As Long
     
    Dim lByteCountTotal As Long
     
    Dim RS1 As ResultSet
     
    Dim RS2 As ResultSet
     
    Dim iRowID As Int
     
    Dim arrBytes() As Byte
     
     RS1 = General.cConn.SQL1.ExecQuery(strSQL)
     RS1.Position = 
    0
     
    Dim arrColumns(RS1.RowCount) As String
     
     
    For c = 0 To RS1.ColumnCount - 1
      arrColumns(c) = RS1.GetColumnName(c)
     
    Next
     
     RS1.Position = -
    1
     
    Do While RS1.NextRow
      lByteCountRow = 
    0
      iRowID = RS1.GetInt2(
    0)
      
    For c = 1 To RS1.ColumnCount - 1
       strSQL2 = 
    "select cast(coalesce(" & arrColumns(c) & ", '') as blob) from " & strTable & " where rowid = ?"
       RS2 = General.cConn.SQL1.ExecQuery2(strSQL2, 
    Array As String(iRowID))
       RS2.Position = 
    0
       arrBytes = RS2.GetBlob2(
    0)
       lByteCountRow = lByteCountRow + arrBytes.Length
      
    Next
      
    Log("Record " & n & ": " & lByteCountRow)
      n = n + 
    1
      lByteCountTotal = lByteCountTotal + lByteCountRow
     
    Loop
     
     RS1.Close
     RS2.Close
     
     
    Return lByteCountTotal
     
    End Sub
    [CODE]


    RBS
     
  4. makis_best

    makis_best Active Member Licensed User

    Thanks....

    It works perfect... Just what I needed.
     
  5. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    No problem, glad it works.

    RBS
     
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