Android Question [Solved] SQLite record byte

makis_best

Well-Known Member
Licensed User
Longtime 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
 

Computersmith64

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime 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

Something like this should work:

B4X:
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 String) As 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
 
Upvote 0
Top