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
CountDatabaseRows?
-
- Enthusiast
- Posts: 537
- Joined: Wed Oct 29, 2003 10:35 am
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
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
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
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

-
- Enthusiast
- Posts: 537
- Joined: Wed Oct 29, 2003 10:35 am