PQconnectdb() style connections.
char attname[256];
char typname[256];
int count;
+ char optstr[256];
if (argc != 2)
halt("Usage: %s database\n", argv[0]);
- connectdb(NULL, NULL, NULL, NULL, argv[1]);
+ snprintf(optstr, 256, "dbname=%s", argv[1]);
+ connectdb(optstr);
+
on_error_continue();
on_error_stop();
-PGconn *connectdb();
+PGconn *connectdb(char *options);
- For select queries, fetch
+ For SELECT queries, fetch
allows you to pass pointers as parameters, and on return the variables
are filled with data from the binary cursor you opened. These binary
cursors can not be used if you are running the
elog level msg
- Fire a log message. Possible levels are NOTICE, WARN, ERROR,
+ Fire a log message. Possible levels are NOTICE, ERROR,
FATAL, DEBUG and NOIND
like for the elog C function.
-WARN RemoveAggregate: aggregate 'agg' for 'type' does not exist
+NOTICE RemoveAggregate: aggregate 'agg' for 'type' does not exist
-WARN RemoveFunction: Function "name" ("types") does not exist
+NOTICE RemoveFunction: Function "name" ("types") does not exist
-WARN: Relation "name" does not exist.
+NOTICE: Relation "name" does not exist.
-WARN: Bad value for variable (value)
+NOTICE: Bad value for variable (value)
the following:
% createdb mydb
-WARN:user "your username" is not allowed to create/destroy databases
+NOTICE:user "your username" is not allowed to create/destroy databases
createdb: database creation failed on mydb.
int ret, i;
if (!CurrentTriggerData)
- elog(WARN, "trigf: triggers are not initialized");
+ elog(NOTICE, "trigf: triggers are not initialized");
/* tuple to return to Executor */
if (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event))
/* Connect to SPI manager */
if ((ret = SPI_connect()) < 0)
- elog(WARN, "trigf (fired %s): SPI_connect returned %d", when, ret);
+ elog(NOTICE, "trigf (fired %s): SPI_connect returned %d", when, ret);
/* Get number of tuples in relation */
ret = SPI_exec("select count(*) from ttest", 0);
if (ret < 0)
- elog(WARN, "trigf (fired %s): SPI_exec returned %d", when, ret);
+ elog(NOTICE, "trigf (fired %s): SPI_exec returned %d", when, ret);
i = SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull);
-WARN::function declared to return type EMP does not retrieve (EMP.*)
+NOTICE::function declared to return type EMP does not retrieve (EMP.*)
SELECT new_emp().name AS nobody;
-WARN:parser: syntax error at or near "."
+NOTICE:parser: syntax error at or near "."
double x, y;
Complex *result;
if (sscanf(str, " ( %lf , %lf )", &x, &y) != 2) {
- elog(WARN, "complex_in: error in parsing
+ elog(NOTICE, "complex_in: error in parsing
return NULL;
}
result = (Complex *)palloc(sizeof(Complex));
# Makefile for pgeasy examples
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/interfaces/libpgeasy/examples/Attic/Makefile,v 1.1 1999/10/11 18:03:01 momjian Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/libpgeasy/examples/Attic/Makefile,v 1.2 2000/05/18 14:24:37 momjian Exp $
#
#-------------------------------------------------------------------------
+CFLAGS=-I/usr/local/pgsql/include
TARGET = pginsert pgwordcount pgnulltest
-LDFLAGS = -lpgeasy
+LDFLAGS = -L/usr/local/pgsql/lib -lpgeasy
all : $(TARGET)
avarchar[51],
atext[51];
time_t aabstime;
+ char optstr[256];
if (argc != 2)
halt("Usage: %s database\n", argv[0]);
- connectdb(NULL, NULL, NULL, NULL, argv[1]);
+ snprintf(optstr, 256, "dbname=%s", argv[1]);
+ connectdb(optstr);
on_error_continue();
doquery("DROP TABLE testfetch");
avarchar_null,
atext_null,
aabstime_null;
+ char optstr[256];
if (argc != 2)
halt("Usage: %s database\n", argv[0]);
- connectdb(NULL, NULL, NULL, NULL, argv[1]);
+ snprintf(optstr, 256, "dbname=%s", argv[1]);
+ connectdb(optstr);
on_error_continue();
doquery("DROP TABLE testfetch");
int row = 0;
int count;
char line[4000];
+ char optstr[256];
if (argc != 2)
halt("Usage: %s database\n", argv[0]);
- connectdb(NULL, NULL, NULL, NULL, argv[1]);
+ snprintf(optstr, 256, "dbname=%s", argv[1]);
+ connectdb(optstr);
+
on_error_continue();
doquery("DROP TABLE words");
on_error_stop();
+++ /dev/null
-.\" This is -*-nroff-*-
-.\" XXX standard disclaimer belongs here....
-.\" $Header: /cvsroot/pgsql/src/interfaces/libpgeasy/Attic/libpgeasy.3,v 1.1 1999/10/12 14:06:49 momjian Exp $
-.TH PGEASY INTRO 08/08/98 PostgreSQL PostgreSQL
-.SH DESCRIPTION
-Pgeasy allows you to cleanly interface to the libpq library,
-more like a 4gl SQL interface.
-.PP
-It consists of set of simplified C functions that encapsulate the
-functionality of libpq.
-The functions are:
-
-.nf
-PGresult *doquery(char *query);
-PGconn *connectdb();
-void disconnectdb();
-
-int fetch(void *param,...);
-int fetchwithnulls(void *param,...);
-void reset_fetch();
-
-void on_error_continue();
-void on_error_stop();
-
-PGresult *get_result();
-void set_result(PGresult *newres);
-void unset_result(PGresult *oldres);
-.fi
-.PP
-Many functions return a structure or value, so you can do more work
-with the result if required.
-.PP
-You basically connect to the database with
-.BR connectdb ,
-issue your query with
-.BR doquery ,
-fetch the results with
-.BR fetch ,
-and finish with
-.BR disconnectdb .
-.PP
-For
-.IR select
-queries,
-.BR fetch
-allows you to pass pointers as parameters, and on return the variables
-are filled with data from the binary cursor you opened. These binary
-cursors can not be used if you are running the
-.BR pgeasy
-client on a system with a different architecture than the database
-server. If you pass a NULL pointer parameter, the column is skipped.
-.BR fetchwithnulls
-allows you to retieve the
-.IR null
-status of the field by passing an
-.IR int*
-after each result pointer, which returns true or false if the field is null.
-You can always use libpq functions on the PGresult pointer returned by
-.BR doquery .
-.BR reset_fetch
-starts the fetch back at the beginning.
-.PP
-.BR get_result ,
-.BR set_result ,
-and
-.BR unset_result
-allow you to handle multiple result sets at the same time.
-.PP
-There are a variety of demonstration programs in the
-.BR pgeasy
-source directory.
**
*/
PGconn *
-connectdb(char *pghost,
- char *pgport,
- char *pgoptions,
- char *pgtty,
- char *dbName)
+connectdb(char *options)
{
/* make a connection to the database */
- conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName);
+ conn = PQconnectdb(options);
if (PQstatus(conn) == CONNECTION_BAD)
- halt("Connection to database '%s' failed.\n%s\n", dbName,
+ halt("Connection to database using '%s' failed.\n%s\n", options,
PQerrorMessage(conn));
return conn;
}
*/
PGresult *doquery(char *query);
-PGconn *connectdb(char *pghost,
- char *pgport,
- char *pgoptions,
- char *pgtty,
- char *dbName);
+PGconn *connectdb(char *options);
void disconnectdb(void);
int fetch(void *param,...);
int fetchwithnulls(void *param,...);