88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.249 2003/06/20 04:09:12 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.250 2003/06/21 21:51:33 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -176,6 +176,7 @@ static PQconninfoOption *conninfo_parse(const char *conninfo,
176176PQExpBuffer errorMessage );
177177static char * conninfo_getval (PQconninfoOption * connOptions ,
178178const char * keyword );
179+ static void defaultNoticeReceiver (void * arg ,const PGresult * res );
179180static void defaultNoticeProcessor (void * arg ,const char * message );
180181static int parseServiceInfo (PQconninfoOption * options ,
181182PQExpBuffer errorMessage );
@@ -1804,11 +1805,14 @@ makeEmptyPGconn(void)
18041805/* Zero all pointers and booleans */
18051806MemSet ((char * )conn ,0 ,sizeof (PGconn ));
18061807
1807- conn -> noticeHook = defaultNoticeProcessor ;
1808+ conn -> noticeHooks .noticeRec = defaultNoticeReceiver ;
1809+ conn -> noticeHooks .noticeProc = defaultNoticeProcessor ;
18081810conn -> status = CONNECTION_BAD ;
18091811conn -> asyncStatus = PGASYNC_IDLE ;
1812+ conn -> xactStatus = PQTRANS_IDLE ;
18101813conn -> setenv_state = SETENV_STATE_IDLE ;
18111814conn -> client_encoding = PG_SQL_ASCII ;
1815+ conn -> verbosity = PQERRORS_DEFAULT ;
18121816conn -> notifyList = DLNewList ();
18131817conn -> sock = -1 ;
18141818#ifdef USE_SSL
@@ -1850,7 +1854,6 @@ makeEmptyPGconn(void)
18501854/*
18511855 * freePGconn
18521856 * - free the PGconn data structure
1853- *
18541857 */
18551858static void
18561859freePGconn (PGconn * conn )
@@ -1899,9 +1902,9 @@ freePGconn(PGconn *conn)
18991902}
19001903
19011904/*
1902- closePGconn
1903- - properly close a connection to the backend
1904- */
1905+ * closePGconn
1906+ * - properly close a connection to the backend
1907+ */
19051908static void
19061909closePGconn (PGconn * conn )
19071910{
@@ -2662,6 +2665,41 @@ PQstatus(const PGconn *conn)
26622665return conn -> status ;
26632666}
26642667
2668+ PGTransactionStatusType
2669+ PQtransactionStatus (const PGconn * conn )
2670+ {
2671+ if (!conn || conn -> status != CONNECTION_OK )
2672+ return PQTRANS_UNKNOWN ;
2673+ if (conn -> asyncStatus != PGASYNC_IDLE )
2674+ return PQTRANS_ACTIVE ;
2675+ return conn -> xactStatus ;
2676+ }
2677+
2678+ const char *
2679+ PQparameterStatus (const PGconn * conn ,const char * paramName )
2680+ {
2681+ const pgParameterStatus * pstatus ;
2682+
2683+ if (!conn || !paramName )
2684+ return NULL ;
2685+ for (pstatus = conn -> pstatus ;pstatus != NULL ;pstatus = pstatus -> next )
2686+ {
2687+ if (strcmp (pstatus -> name ,paramName )== 0 )
2688+ return pstatus -> value ;
2689+ }
2690+ return NULL ;
2691+ }
2692+
2693+ int
2694+ PQprotocolVersion (const PGconn * conn )
2695+ {
2696+ if (!conn )
2697+ return 0 ;
2698+ if (conn -> status == CONNECTION_BAD )
2699+ return 0 ;
2700+ return PG_PROTOCOL_MAJOR (conn -> pversion );
2701+ }
2702+
26652703char *
26662704PQerrorMessage (const PGconn * conn )
26672705{
@@ -2731,11 +2769,22 @@ PQsetClientEncoding(PGconn *conn, const char *encoding)
27312769return (status );
27322770}
27332771
2772+ PGVerbosity
2773+ PQsetErrorVerbosity (PGconn * conn ,PGVerbosity verbosity )
2774+ {
2775+ PGVerbosity old ;
2776+
2777+ if (!conn )
2778+ return PQERRORS_DEFAULT ;
2779+ old = conn -> verbosity ;
2780+ conn -> verbosity = verbosity ;
2781+ return old ;
2782+ }
2783+
27342784void
27352785PQtrace (PGconn * conn ,FILE * debug_port )
27362786{
2737- if (conn == NULL ||
2738- conn -> status == CONNECTION_BAD )
2787+ if (conn == NULL )
27392788return ;
27402789PQuntrace (conn );
27412790conn -> Pfdebug = debug_port ;
@@ -2744,7 +2793,6 @@ PQtrace(PGconn *conn, FILE *debug_port)
27442793void
27452794PQuntrace (PGconn * conn )
27462795{
2747- /* note: better allow untrace even when connection bad */
27482796if (conn == NULL )
27492797return ;
27502798if (conn -> Pfdebug )
@@ -2754,6 +2802,23 @@ PQuntrace(PGconn *conn)
27542802}
27552803}
27562804
2805+ PQnoticeReceiver
2806+ PQsetNoticeReceiver (PGconn * conn ,PQnoticeReceiver proc ,void * arg )
2807+ {
2808+ PQnoticeReceiver old ;
2809+
2810+ if (conn == NULL )
2811+ return NULL ;
2812+
2813+ old = conn -> noticeHooks .noticeRec ;
2814+ if (proc )
2815+ {
2816+ conn -> noticeHooks .noticeRec = proc ;
2817+ conn -> noticeHooks .noticeRecArg = arg ;
2818+ }
2819+ return old ;
2820+ }
2821+
27572822PQnoticeProcessor
27582823PQsetNoticeProcessor (PGconn * conn ,PQnoticeProcessor proc ,void * arg )
27592824{
@@ -2762,22 +2827,35 @@ PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
27622827if (conn == NULL )
27632828return NULL ;
27642829
2765- old = conn -> noticeHook ;
2830+ old = conn -> noticeHooks . noticeProc ;
27662831if (proc )
27672832{
2768- conn -> noticeHook = proc ;
2769- conn -> noticeArg = arg ;
2833+ conn -> noticeHooks . noticeProc = proc ;
2834+ conn -> noticeHooks . noticeProcArg = arg ;
27702835}
27712836return old ;
27722837}
27732838
27742839/*
2775- * The default notice/error message processor just prints the
2840+ * The default notice message receiver just gets the standard notice text
2841+ * and sends it to the notice processor. This two-level setup exists
2842+ * mostly for backwards compatibility; perhaps we should deprecate use of
2843+ * PQsetNoticeProcessor?
2844+ */
2845+ static void
2846+ defaultNoticeReceiver (void * arg ,const PGresult * res )
2847+ {
2848+ (void )arg ;/* not used */
2849+ (* res -> noticeHooks .noticeProc ) (res -> noticeHooks .noticeProcArg ,
2850+ PQresultErrorMessage (res ));
2851+ }
2852+
2853+ /*
2854+ * The default notice message processor just prints the
27762855 * message on stderr. Applications can override this if they
27772856 * want the messages to go elsewhere (a window, for example).
27782857 * Note that simply discarding notices is probably a bad idea.
27792858 */
2780-
27812859static void
27822860defaultNoticeProcessor (void * arg ,const char * message )
27832861{