DatabaseTableRowCount
Posted: Sun Oct 21, 2012 4:11 am
Hello everyone,
In some occasion we would like to know how many row a table has. To Redim a Dynamic array before to load an entire table.
The first solution consist of running a 1st pass to count the row, Redim the Array then a 2nd pass to load to table inside the array.
This solution is not very effective especially if the table contains several thousand lines. After an extensive search I have found a
better solution here : http://www.w3schools.com/sql/sql_func_count.asp
Here is the solution that I came up :
If it can be useful for someone else.
Best regards
Guimauve
In some occasion we would like to know how many row a table has. To Redim a Dynamic array before to load an entire table.
The first solution consist of running a 1st pass to count the row, Redim the Array then a 2nd pass to load to table inside the array.
This solution is not very effective especially if the table contains several thousand lines. After an extensive search I have found a
better solution here : http://www.w3schools.com/sql/sql_func_count.asp
Here is the solution that I came up :
Code: Select all
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : DatabaseTableRowCount
; File Name : DatabaseTableRowCount.pb
; File version: 1.0.0
; Programming : OK
; Programmed by : Guimauve
; Date : 20-10-2012
; Last Update : 20-10-2012
; PureBasic code : 5.00 B6
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Procedure.l DatabaseTableRowCount(DataBaseID.i, TableName.s)
If DatabaseQuery(DatabaseID, "SELECT COUNT(*) FROM " + TableName)
NextDatabaseRow(DatabaseID)
Protected TableRowCount.l = GetDatabaseLong(DataBaseID, 0)
FinishDatabaseQuery(DataBaseID)
EndIf
ProcedureReturn TableRowCount
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Best regards
Guimauve