Skip to content

Commit efc3a25

Browse files
committed
Update libpq to make new features of FE/BE protocol available to
client applications. Some editorial work on libpq.sgml, too.
1 parent b8d601e commit efc3a25

File tree

11 files changed

+2524
-832
lines changed

11 files changed

+2524
-832
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 1184 additions & 462 deletions
Large diffs are not rendered by default.

doc/src/sgml/lobj.sgml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/lobj.sgml,v 1.28 2003/03/13 01:30:28 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/lobj.sgml,v 1.29 2003/06/21 21:51:33 tgl Exp $
33
-->
44

55
<chapter id="largeObjects">
@@ -181,7 +181,8 @@ int lo_open(PGconn *conn, Oid lobjId, int mode);
181181
<function>lo_open</function> returns a large object descriptor
182182
for later use in <function>lo_read</function>, <function>lo_write</function>,
183183
<function>lo_lseek</function>, <function>lo_tell</function>, and
184-
<function>lo_close</function>.
184+
<function>lo_close</function>. The descriptor is only valid for
185+
the duration of the current transaction.
185186
</para>
186187
</sect2>
187188

@@ -256,6 +257,11 @@ int lo_close(PGconn *conn, int fd);
256257
<function>lo_open</function>. On success, <function>lo_close</function>
257258
returns zero. On error, the return value is negative.
258259
</para>
260+
261+
<para>
262+
Any large object descriptors that remain open at the end of a
263+
transaction will be closed automatically.
264+
</para>
259265
</sect2>
260266

261267
<sect2>
@@ -296,6 +302,14 @@ SELECT lo_export(image.raster, '/tmp/motd') FROM image
296302
WHERE name = 'beautiful image';
297303
</programlisting>
298304
</para>
305+
306+
<para>
307+
These functions read and write files in the server's filesystem, using the
308+
permissions of the database's owning user. Therefore, their use is restricted
309+
to superusers. (In contrast, the client-side import and export functions
310+
read and write files in the client's filesystem, using the permissions of
311+
the client program. Their use is not restricted.)
312+
</para>
299313
</sect1>
300314

301315
<sect1 id="lo-examplesect">

src/interfaces/libpq/blibpqdll.def

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ EXPORTS
9797
_pg_utf_mblen @ 93
9898
_PQunescapeBytea @ 94
9999
_PQfreemem @ 95
100+
_PQtransactionStatus @ 96
101+
_PQparameterStatus @ 97
102+
_PQprotocolVersion @ 98
103+
_PQsetErrorVerbosity @ 99
104+
_PQsetNoticeReceiver @ 100
105+
_PQexecParams @ 101
106+
_PQsendQueryParams @ 102
107+
_PQputCopyData @ 103
108+
_PQputCopyEnd @ 104
109+
_PQgetCopyData @ 105
110+
_PQresultErrorField @ 106
111+
_PQftable @ 107
112+
_PQftablecol @ 108
113+
_PQfformat @ 109
100114

101115
; Aliases for MS compatible names
102116
PQconnectdb = _PQconnectdb
@@ -194,4 +208,17 @@ EXPORTS
194208
pg_utf_mblen = _pg_utf_mblen
195209
PQunescapeBytea = _PQunescapeBytea
196210
PQfreemem = _PQfreemem
197-
211+
PQtransactionStatus = _PQtransactionStatus
212+
PQparameterStatus = _PQparameterStatus
213+
PQprotocolVersion = _PQprotocolVersion
214+
PQsetErrorVerbosity = _PQsetErrorVerbosity
215+
PQsetNoticeReceiver = _PQsetNoticeReceiver
216+
PQexecParams = _PQexecParams
217+
PQsendQueryParams = _PQsendQueryParams
218+
PQputCopyData = _PQputCopyData
219+
PQputCopyEnd = _PQputCopyEnd
220+
PQgetCopyData = _PQgetCopyData
221+
PQresultErrorField = _PQresultErrorField
222+
PQftable = _PQftable
223+
PQftablecol = _PQftablecol
224+
PQfformat = _PQfformat

src/interfaces/libpq/fe-connect.c

Lines changed: 92 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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,
176176
PQExpBuffer errorMessage);
177177
static char *conninfo_getval(PQconninfoOption *connOptions,
178178
const char *keyword);
179+
static void defaultNoticeReceiver(void *arg, const PGresult *res);
179180
static void defaultNoticeProcessor(void *arg, const char *message);
180181
static int parseServiceInfo(PQconninfoOption *options,
181182
PQExpBuffer errorMessage);
@@ -1804,11 +1805,14 @@ makeEmptyPGconn(void)
18041805
/* Zero all pointers and booleans */
18051806
MemSet((char *) conn, 0, sizeof(PGconn));
18061807

1807-
conn->noticeHook = defaultNoticeProcessor;
1808+
conn->noticeHooks.noticeRec = defaultNoticeReceiver;
1809+
conn->noticeHooks.noticeProc = defaultNoticeProcessor;
18081810
conn->status = CONNECTION_BAD;
18091811
conn->asyncStatus = PGASYNC_IDLE;
1812+
conn->xactStatus = PQTRANS_IDLE;
18101813
conn->setenv_state = SETENV_STATE_IDLE;
18111814
conn->client_encoding = PG_SQL_ASCII;
1815+
conn->verbosity = PQERRORS_DEFAULT;
18121816
conn->notifyList = DLNewList();
18131817
conn->sock = -1;
18141818
#ifdef USE_SSL
@@ -1850,7 +1854,6 @@ makeEmptyPGconn(void)
18501854
/*
18511855
* freePGconn
18521856
* - free the PGconn data structure
1853-
*
18541857
*/
18551858
static void
18561859
freePGconn(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+
*/
19051908
static void
19061909
closePGconn(PGconn *conn)
19071910
{
@@ -2662,6 +2665,41 @@ PQstatus(const PGconn *conn)
26622665
return 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+
26652703
char *
26662704
PQerrorMessage(const PGconn *conn)
26672705
{
@@ -2731,11 +2769,22 @@ PQsetClientEncoding(PGconn *conn, const char *encoding)
27312769
return (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+
27342784
void
27352785
PQtrace(PGconn *conn, FILE *debug_port)
27362786
{
2737-
if (conn == NULL ||
2738-
conn->status == CONNECTION_BAD)
2787+
if (conn == NULL)
27392788
return;
27402789
PQuntrace(conn);
27412790
conn->Pfdebug = debug_port;
@@ -2744,7 +2793,6 @@ PQtrace(PGconn *conn, FILE *debug_port)
27442793
void
27452794
PQuntrace(PGconn *conn)
27462795
{
2747-
/* note: better allow untrace even when connection bad */
27482796
if (conn == NULL)
27492797
return;
27502798
if (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+
27572822
PQnoticeProcessor
27582823
PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
27592824
{
@@ -2762,22 +2827,35 @@ PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
27622827
if (conn == NULL)
27632828
return NULL;
27642829

2765-
old = conn->noticeHook;
2830+
old = conn->noticeHooks.noticeProc;
27662831
if (proc)
27672832
{
2768-
conn->noticeHook = proc;
2769-
conn->noticeArg = arg;
2833+
conn->noticeHooks.noticeProc = proc;
2834+
conn->noticeHooks.noticeProcArg = arg;
27702835
}
27712836
return 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-
27812859
static void
27822860
defaultNoticeProcessor(void *arg, const char *message)
27832861
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy