Page 1 of 1
CountDatabaseRows?
Posted: Tue Apr 13, 2004 1:53 pm
by Alberto
Dear PureBasic developers,
this is not an indispensable feature request, but it's easy to implement and I think it will make PureBasic more complete.
I'd like the command CountDataBaseRows that return the number of rows of a DatabaseQuery().
In alternative is possible to change the function DatabaseQuery() so that it returns the number of rows got from the query.
I think that this command is useful if you want to put a query into memory and want to know how many bytes do you need to allocate.
Ciao to everybody and many thanks for your great work.
Alberto
Posted: Tue Apr 13, 2004 4:10 pm
by dontmailme
Which DB are you using ?
Can't you just use something like....
numrows=DatabaseQuery("SELECT COUNT * FROM employee")

Posted: Wed Apr 14, 2004 7:41 am
by Alberto
I'm using an Access 97 database that is not full SQL language compatible.
I've tried to do your query in Access 97 and my database recognise this format:
SELECT Count('name') AS Espr1 FROM employee;
This work good.
Unfortunately your suggestion work good only with tables and not with query.
I want to know the number of rows of a query and not of a table.
Now I'm using this system to allocate the exact quantity of RAM before to store the query into memory:
Query ="SELECT PRODOTTI.IDProdotto, PRODOTTI.[Codice Interno], PRODOTTI.NomeProdotto, PRODOTTI.NomeInglese, PRODOTTI.Giacenza, PRODOTTI.Listino1, PRODOTTI.Listino2, PRODOTTI.Listino3 FROM PRODOTTI WHERE (((PRODOTTI.Listino1) Is Not Null)) Or (((PRODOTTI.Listino2) Is Not Null)) Or (((PRODOTTI.Listino3) Is Not Null)) ORDER BY PRODOTTI.[Codice Interno]"
If DatabaseQuery(Query)
prodotti_riga = 0
prodotti_riga_max = 1000
*Prodotti = AllocateMemory((4+20+100+100+4)*prodotti_riga_max)
While NextDatabaseRow()
If prodotti_riga >= prodotti_riga_max
prodotti_riga_max = prodotti_riga_max + 1000
*Prodotti = ReAllocateMemory(*Prodotti, (4+20+100+100+4)*prodotti_riga_max)
EndIf
;ID
PokeL(*Prodotti+prodotti_riga*228,GetDatabaseLong(0))
;Codice Prodotto
PokeS(*Prodotti+4+prodotti_riga*228,Left(GetDatabaseString(1)+Space(20),20))
;Descrizione Italiano
PokeS(*Prodotti+24+prodotti_riga*228,Left(GetDatabaseString(2)+Space(100),100))
;Descrizione Inglese
PokeS(*Prodotti+124+prodotti_riga*228,Left(GetDatabaseString(3)+Space(100),100))
;Giacenza di fine anno
PokeF(*Prodotti+224+prodotti_riga*228,GetDatabaseFloat(4))
prodotti_riga = prodotti_riga + 1
Wend
Else
MessageRequester("Errore","Eseguita query non valida sul database:" + Chr(13) + DatabaseError(),#MB_ICONERROR)
EndIf
However many thanks for your suggestion.
Alberto
Posted: Wed Apr 14, 2004 7:49 am
by Alberto
I'm stupid...and I write too fast without thinking.
Your suggestion is good DontMailMe and to know the number of rows of a query I've to do this:
SELECT Count('IDPRODOTTO') AS Espr1
FROM PRODOTTI WHERE (((PRODOTTI.Listino1) Is Not Null)) Or (((PRODOTTI.Listino2) Is Not Null)) Or (((PRODOTTI.Listino3) Is Not Null))
Thank you very much.
Alberto

Posted: Wed Apr 14, 2004 12:19 pm
by dontmailme
Sometimes I write too fast too
Glad to be of help
