Database Reference
In-Depth Information
Datum
count_returned_rows(PG_FUNCTION_ARGS)
{
char *command;
int cnt;
int ret;
int proc;
/* get arguments, convert command to C
string */
command =
text_to_cstring(PG_GETARG_TEXT_P(0));
cnt = PG_GETARG_INT32(1);
/* open internal connection */
SPI_connect();
/* run the SQL command */
ret = SPI_exec(command, cnt);
/* save the number of rows */
proc = SPI_processed;
/* If some rows were fetched, print them
via elog(INFO). */
if (ret > 0 && SPI_tuptable != NULL)
{
TupleDesc tupdesc =
SPI_tuptable->tupdesc;
SPITupleTable *tuptable = SPI_tuptable;
char buf[8192];
int i, j;
for (j = 0; j < proc; j++)
{
HeapTuple tuple =
tuptable->vals[j];
// construct a string representing
the tuple
for (i = 1, buf[0] = 0; i <=
tupdesc->natts; i++)
Search WWH ::




Custom Search