### Get Number of Records

This Sub returns the number of records for a given table.
Despite getting the number of records, it can also be used to check if a table is empty.
Option 1
' Get the number of records for a given table
' Parameter Tablename
' Returns number of records found or -1 if error occurs
`Sub getRecordCount(sql1 as SQL,table As String) As Int
Dim cnt As Int = -1
Try
cnt = sql1.ExecQuerySingleResult("SELECT Count(*) FROM " & table)
Catch
Log(LastException.message)
End Try
Return cnt
End Sub`
Option 2
' Get the number of records for a given table
' Parameter Tablename
' Returns number of records found or -1 if error occurs
`Sub getRecordCount(sql1 as SQL, table As String) As Int
Dim cnt As Int = -1
Dim cur As ResultSet
Try
cur = sql1.ExecQuery("SELECT Count(*) FROM " & table)
If cur.NextRow Then
cnt = cur.GetInt2(0)
End If
Catch
Log(LastException.message)
End Try
Return cnt
End Sub`

Changed: , Category: SQLite, File: T6C254M1826.htm, ID: 1826