Number of records in a SQL-table

Number of records in a SQL-table

Postby Marc Vanzegbroeck » 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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Number of records in a SQL-table

Postby anserkk » Thu Feb 23, 2012 11:28 am

Code: Select all  Expand view
SELECT COUNT(*) AS NumberOfRecords FROM <TableName>


Regards
Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Number of records in a SQL-table

Postby Marc Vanzegbroeck » Thu Feb 23, 2012 11:35 am

Thanks,

But when I do
Code: Select all  Expand view
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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Number of records in a SQL-table

Postby Carles » Thu Feb 23, 2012 12:35 pm

Mark,

Code: Select all  Expand view
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
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Carles
 
Posts: 1134
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona

Re: Number of records in a SQL-table

Postby Marc Vanzegbroeck » Thu Feb 23, 2012 12:42 pm

Charles,

If I use
Code: Select all  Expand view
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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Number of records in a SQL-table

Postby Carles » Thu Feb 23, 2012 12:50 pm

Marc,

Try

Code: Select all  Expand view

    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
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Carles
 
Posts: 1134
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona

Re: Number of records in a SQL-table

Postby ADutheil » Thu Feb 23, 2012 1:23 pm

I do this way:
Code: Select all  Expand view
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: Select all  Expand view
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
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: Number of records in a SQL-table

Postby Marc Vanzegbroeck » Thu Feb 23, 2012 5: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: Select all  Expand view
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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Number of records in a SQL-table

Postby ADutheil » Thu Feb 23, 2012 6:05 pm

I use TDolphin with MySQL.
Regards,

André Dutheil
FWH 13.04 + HB 3.2 + MSVS 10
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: Number of records in a SQL-table

Postby ShumingWang » Fri Feb 24, 2012 2: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
ShumingWang
 
Posts: 465
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 33 guests