Skip Headers
Oracle® Objects for OLE C++ Class Library Developer's Guide
10g Release 2 (10.2)

Part Number B14308-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

GetRecordCount Method

Applies To

ODynaset

OSqlStmt

Description

For ODynasets, this method returns the total number of records in the dynaset's result set.

For OSqlStmts, this method returns the total number of records processed.

Usage

long GetRecordCount(void) const

Remarks

This method returns the total number of records that the ODynaset's query returns. On error, this method returns 0 (zero).

Attention: When working with a relational database, the only way to determine the total number of records returned by a query is to actually fetch them from the server. Therefore, this method fetches the entire query result set to the local cache. If the result set is large, this takes a long time and uses a large amount of disk space. It is rare that you really need to know the number of records in a dynaset.

Executing this method with an ODynaset that was opened with the ODYNASET_NOCACHE option will cause an implicit MoveLast and will make the current record the last record in the dynaset.

GetRecordCount() for OSqlStmt supports only DML statements.

Return Value

The total number of records in the result set for ODynaset; 0 on error.

The total number of records processed for OSQLStmt; 0 on error.

Example

An example of using GetRecordCount with ODynaset:

// open the employee database

ODatabase odb("p:us-postoffice", "sam", "uncle");

// get records on all the postal workers in the united states

ODynaset dyn(odb, "select * from employees");

// how many employees are there?

// DON'T DO THIS!!

dyn.GetRecordCount();

// that's just used up all your free disk space, and a lot of time

// do this instead:

ODynaset tempdyn(odb, "select count(*) from employees");

long nemployees;

tempdyn.GetFieldValue(0, &nemployees);

// now the number of records is in nemployees

// we can use the server program to do calculations for us.

// we don't always have to download the records to the client

// machine to calculate something

An Example of using GetRecordCount with OSQLStmt:

OSession ses;

ODatabase odb;

long grc=0;

long dbopt = 0; //the default is either no option, or the default set

long dynopt = 0; //ditto

long sqlstmt_opt = 0; //ditto

char MsgBuff[255];

if (ses.Open() != OSUCCESS)

{

AfxMessageBox("session failed to open");

return;

}

odb.Open(ses, "ExampleDb", "scott", "tiger");

if(odb.IsOpen() != TRUE)

{

AfxMessageBox("database failed to open");

return;

}

else

AfxMessageBox("database open succeeded");

int limit = 25;

char mybuf[20];

for (int count=0;count<limit;count++){

description[count] = (char *)malloc(40);

sprintf(description[count],"Mahadevan%d",count);

partno[count] = 10000+count;

}

OParameterCollection pc = odb.GetParameters();

pc.Add("DESCRIPTION", description, limit,OPARAMETER_INVAR, OTYPE_VARCHAR2);

pc.Add("PARTNO",partno,limit,OPARAMETER_INVAR, OTYPE_NUMBER);

OSqlStmt sqlobj(odb, "insert into part_nos (DESCRIPTION,PARTNO) values

(:DESCRIPTION,:PARTNO)", sqlstmt_opt);

grc = sqlobj.GetRecordCount();

sprintf(MsgBuff,"# of records processed : %d",grc);

AfxMessageBox(MsgBuff);