Return value of function

From: Masakazu Ichimura <m(dot)ichimura(at)nihontechno(dot)co(dot)jp>
To: pgsql-novice(at)postgresql(dot)org
Subject: Return value of function
Date: 2002-03-26 01:15:10
Message-ID: 20020326095323.51CC.M.ICHIMURA@nihontechno.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi

I'm using PostgreSQL7.1.3.
I want to compare speed of calling function and direct access.

Direct access I write is below
----------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include "libpq-fe.h"

void exit_nicely(PGconn *conn)
{
PQfinish(conn);
exit(1);
}

int main()
{
char *pghost;
char *pgport;
char *pgoptions;
char *pgtty;
char *dbName;

PGconn *conn;
PGresult *res;
/* Set Parameter */
pghost = NULL;
pgport = NULL;
pgoptions = NULL;
pgtty = NULL;
dbname = "imr";
/* Connect to DB */
conn = PGsetdb(pghost, pgport, pgoptions, pgtty, dbName);

if(PQstatus(conn) == CONNECTION_BAD)
{
fprintf(stderr, "Connection database '%s' failed.\n", dbName);
fprintf(stderr, "%s", PQerrorMessage(conn));
exit_nicely(conn);
}
/* Begining transaction */
res = PQexec(conn, "BEGIN");
if( !res || PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "BEGIN command failed\n");
PQclear(res);
exit_nicely(conn);
}
PQclear(res);
/* Declare a cursor */
res = PQexec(conn, "DECLARE mycursor CURSOR FOR select * FROM test1");
if( !res || PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "DECLARE CURSOR command failed\n");
PQclear(res);
return(-1);
}
PQclear(res);
/* Fetch */
res = PQexec(conn, "FETCH ALL in mycursor");
if( !res || PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "FETCH ALL command didn't return tuples properly\n");
PQclear(res);
return(-1);
}
/* Commit transaction */
res = PQexec(conn, "COMMIT");
PQclear(res);

PQfinish(conn);
return 0;
}
----------------------------------------------------------------

I want to rewrite 'DECLERE' and 'FETCH' part of this program
with function,like 'res = PQexec(conn, function_name);'.

But What RETURN value I should use in function?
Can function return multi rows?

Thank you.

Browse pgsql-novice by date

  From Date Subject
Next Message Richard Ray 2002-03-26 14:18:01 Retrieving archives
Previous Message Jason Earl 2002-03-25 21:37:08 Re: Searching for all records but integer field is causing