8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -176,6 +176,7 @@ static PQconninfoOption *conninfo_parse(const char *conninfo,
176
176
PQExpBuffer errorMessage );
177
177
static char * conninfo_getval (PQconninfoOption * connOptions ,
178
178
const char * keyword );
179
+ static void defaultNoticeReceiver (void * arg , const PGresult * res );
179
180
static void defaultNoticeProcessor (void * arg , const char * message );
180
181
static int parseServiceInfo (PQconninfoOption * options ,
181
182
PQExpBuffer errorMessage );
@@ -1804,11 +1805,14 @@ makeEmptyPGconn(void)
1804
1805
/* Zero all pointers and booleans */
1805
1806
MemSet ((char * ) conn , 0 , sizeof (PGconn ));
1806
1807
1807
- conn -> noticeHook = defaultNoticeProcessor ;
1808
+ conn -> noticeHooks .noticeRec = defaultNoticeReceiver ;
1809
+ conn -> noticeHooks .noticeProc = defaultNoticeProcessor ;
1808
1810
conn -> status = CONNECTION_BAD ;
1809
1811
conn -> asyncStatus = PGASYNC_IDLE ;
1812
+ conn -> xactStatus = PQTRANS_IDLE ;
1810
1813
conn -> setenv_state = SETENV_STATE_IDLE ;
1811
1814
conn -> client_encoding = PG_SQL_ASCII ;
1815
+ conn -> verbosity = PQERRORS_DEFAULT ;
1812
1816
conn -> notifyList = DLNewList ();
1813
1817
conn -> sock = -1 ;
1814
1818
#ifdef USE_SSL
@@ -1850,7 +1854,6 @@ makeEmptyPGconn(void)
1850
1854
/*
1851
1855
* freePGconn
1852
1856
* - free the PGconn data structure
1853
- *
1854
1857
*/
1855
1858
static void
1856
1859
freePGconn (PGconn * conn )
@@ -1899,9 +1902,9 @@ freePGconn(PGconn *conn)
1899
1902
}
1900
1903
1901
1904
/*
1902
- closePGconn
1903
- - properly close a connection to the backend
1904
- */
1905
+ * closePGconn
1906
+ * - properly close a connection to the backend
1907
+ */
1905
1908
static void
1906
1909
closePGconn (PGconn * conn )
1907
1910
{
@@ -2662,6 +2665,41 @@ PQstatus(const PGconn *conn)
2662
2665
return conn -> status ;
2663
2666
}
2664
2667
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
+
2665
2703
char *
2666
2704
PQerrorMessage (const PGconn * conn )
2667
2705
{
@@ -2731,11 +2769,22 @@ PQsetClientEncoding(PGconn *conn, const char *encoding)
2731
2769
return (status );
2732
2770
}
2733
2771
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
+
2734
2784
void
2735
2785
PQtrace (PGconn * conn , FILE * debug_port )
2736
2786
{
2737
- if (conn == NULL ||
2738
- conn -> status == CONNECTION_BAD )
2787
+ if (conn == NULL )
2739
2788
return ;
2740
2789
PQuntrace (conn );
2741
2790
conn -> Pfdebug = debug_port ;
@@ -2744,7 +2793,6 @@ PQtrace(PGconn *conn, FILE *debug_port)
2744
2793
void
2745
2794
PQuntrace (PGconn * conn )
2746
2795
{
2747
- /* note: better allow untrace even when connection bad */
2748
2796
if (conn == NULL )
2749
2797
return ;
2750
2798
if (conn -> Pfdebug )
@@ -2754,6 +2802,23 @@ PQuntrace(PGconn *conn)
2754
2802
}
2755
2803
}
2756
2804
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
+
2757
2822
PQnoticeProcessor
2758
2823
PQsetNoticeProcessor (PGconn * conn , PQnoticeProcessor proc , void * arg )
2759
2824
{
@@ -2762,22 +2827,35 @@ PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
2762
2827
if (conn == NULL )
2763
2828
return NULL ;
2764
2829
2765
- old = conn -> noticeHook ;
2830
+ old = conn -> noticeHooks . noticeProc ;
2766
2831
if (proc )
2767
2832
{
2768
- conn -> noticeHook = proc ;
2769
- conn -> noticeArg = arg ;
2833
+ conn -> noticeHooks . noticeProc = proc ;
2834
+ conn -> noticeHooks . noticeProcArg = arg ;
2770
2835
}
2771
2836
return old ;
2772
2837
}
2773
2838
2774
2839
/*
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
2776
2855
* message on stderr. Applications can override this if they
2777
2856
* want the messages to go elsewhere (a window, for example).
2778
2857
* Note that simply discarding notices is probably a bad idea.
2779
2858
*/
2780
-
2781
2859
static void
2782
2860
defaultNoticeProcessor (void * arg , const char * message )
2783
2861
{
0 commit comments