DatabaseRows()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

DatabaseRows()

Post by Flype »

About Database functions, in PHP language we can do :

Code: Select all

$nbresult = mysql_num_rows($result)
A native DatabaseRows() function could be useful for counting the number of rows after a DatabaseQuery(). DatabaseColumns() exists so why not for Rows.

Code: Select all

Procedure.l DatabaseRows()
  Protected i
  i=0
  While NextDatabaseRow()
    i+1
  Wend
  ProcedureReturn i
EndProcedure

If DatabaseQuery("select * from test;")
  Debug DatabaseRows()
Else
  Debug DatabaseError()
EndIf
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Manol
User
User
Posts: 11
Joined: Thu May 05, 2005 1:19 pm
Location: Spain

Post by Manol »

Code: Select all

#Database=0
Name$="You DataBase Name"
InitDatabase()
OpenDatabase(#Database, Name$, User$, Password$)
DatabaseQuery("select COUNT(*) from test;")
If DatabaseError()
Debug "Error"
Else
NextDatabaseRow() 
  Debug GetDatabaseLong(0)
EndIf 
  
:wink:
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

thank you man.
but i need to count lines by myself on some special sql request where COUNT(...) doesn't work as wanted.
:wink:
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Post Reply