FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Number of records in a SQL-table
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Number of records in a SQL-table
Posted: Thu Feb 23, 2012 11:14 AM

Hello,

Does anyone know how to return the number of records in a SQL-table. Something like reccount() in xHarbour.

Thanks,
Marc

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Number of records in a SQL-table
Posted: Thu Feb 23, 2012 11:28 AM
Code (fw): Select all Collapse
SELECT COUNT(*) AS NumberOfRecords FROM <TableName>


Regards
Anser
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Number of records in a SQL-table
Posted: Thu Feb 23, 2012 11:35 AM
Thanks,

But when I do
Code (fw): Select all Collapse
oQry := oSQL:Execute( "select count(*) AS NumberOfRecords from factui" )

it return True.
Where can I find the result?

Marc
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Re: Number of records in a SQL-table
Posted: Thu Feb 23, 2012 12:35 PM
Mark,

Code (fw): Select all Collapse
oQry := oSQL:Query( "select count(*) AS NumberOfRecords from factui" )
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Number of records in a SQL-table
Posted: Thu Feb 23, 2012 12:42 PM
Charles,

If I use
Code (fw): Select all Collapse
oQry := oSQL:Query( "select count(*) AS NumberOfRecords from factui" )


and shows oQry, it is an Object

Regards,

Marc
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Re: Number of records in a SQL-table
Posted: Thu Feb 23, 2012 12:50 PM
Marc,

Try

Code (fw): Select all Collapse
    oRs := oSQL:Query( "select count(*) AS NumberOfRecords from factui" )

    IF oRs:nRecCount > 0
        MsgInfo( oRs:NumberOfRecords )
    ENDIF
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: Number of records in a SQL-table
Posted: Thu Feb 23, 2012 01:23 PM
I do this way:
Code (fw): Select all Collapse
oQry := oSQL:Execute( "select count(*) AS NumberOfRecords from factui" )
msginfo( oQry:NumberOfRecords)

The term AS in the query create an alias for the result. You can write things like this:
Code (fw): Select all Collapse
oQry := oSQL:Execute( "select concat(firstname,lastname ) AS Name from mytable where id=nnn" )
msginfo( oQry:Name)
Regards,



André Dutheil

FWH 13.04 + HB 3.2 + MSVS 10
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Number of records in a SQL-table
Posted: Thu Feb 23, 2012 05:26 PM
Hi,

Thank you for the support.
I'am using the xHarbour and the library http://www2.zzz.com.tw/phpbb2/viewforum ... 99265acf02.
I finaly found how to do it with this library.

I have to use
Code (fw): Select all Collapse
oQry := oSQL:Execute( "select count(*) AS NumberOfRecords from factui" )
msginfo( oQry:data[1,1])


What type of library do you use?

Regards,
Marc
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: Number of records in a SQL-table
Posted: Thu Feb 23, 2012 06:05 PM

I use TDolphin with MySQL.

Regards,



André Dutheil

FWH 13.04 + HB 3.2 + MSVS 10
Posts: 474
Joined: Sun Oct 30, 2005 06:37 AM
Re: Number of records in a SQL-table
Posted: Fri Feb 24, 2012 02:20 AM

(x)Harbour +Fwh+harbour\contrib\Tmysql.prg

oquery:=oserver:query("select ifnull(count(*),0) count from atable ")
? oquery:count
or ? oquery:fieldget(1)

oquery:end()

If you use Mysql server innodb storage engine, you'd better avoid use count(*) function ,that will get slower , for there is no a real count to recoder innodb table ,Mysql must do count every records /rows.

Regards!
Shuming Wang

http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651

Continue the discussion