[Gambas-user] ExecuteScalar
bb
adamnt42 at gmail.com
Fri Jun 25 03:42:53 CEST 2021
On Thu, 2021-06-24 at 20:23 -0500, John Dovey wrote:
> This is not a terribly important question, because there are obvious
> ways to do it, but is there a Gambas equivalent for " ExecuteScalar"?
>
> For example if I have the SQL "Select COUNT(*) from 'SomeTable';"
> I can of course do
>
> <snip open database code>
> Dim RS As Result
> Try RS = $con.Exec( "SELECT COUNT(*) as NoOfRecords from
> 'echodist' " )
> doCountEchos = RS!NoOfRecords
> Try $con.Close
>
> but I'm wondering if there is a better way?
Not that I can think of.
But I will point out that count(*) is teribly inefficient as the engine
has to evaluate every column in the table to get an answer. It is much
better to count a specific column (except the OID column if it exists).
I generally use count(1) which works for me as the way I design
database tables is always with the primary key columns at the top of
the colummn list.
regards
bruce
More information about the User
mailing list