Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3290e61

Browse files
committed
Add a PQfireResultCreateEvents function to allow applications to mimic the
sequence of operations that libpq goes through while creating a PGresult.Also, remove ill-considered "const" decoration on parameters passed toevent procedures.
1 parent4e57668 commit3290e61

File tree

4 files changed

+94
-17
lines changed

4 files changed

+94
-17
lines changed

‎doc/src/sgml/libpq.sgml

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.262 2008/09/1916:40:40 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.263 2008/09/1920:06:13 tgl Exp $ -->
22

33
<chapter id="libpq">
44
<title><application>libpq</application> - C Library</title>
@@ -4592,17 +4592,58 @@ char *pg_encoding_to_char(int <replaceable>encoding_id</replaceable>);
45924592
<parameter>conn</parameter> is not null and <parameter>status</>
45934593
indicates an error, the current error message of the specified
45944594
connection is copied into the <structname>PGresult</structname>.
4595-
Also, if <parameter>conn</parameter> is not null, any eventhandlers
4595+
Also, if <parameter>conn</parameter> is not null, any eventprocedures
45964596
registered in the connection are copied into the
4597-
<structname>PGresult</structname> (but they don't get
4598-
<literal>PGEVT_RESULTCREATE</> calls).
4597+
<structname>PGresult</structname>. (They do not get
4598+
<literal>PGEVT_RESULTCREATE</> calls, but see
4599+
<function>PQfireResultCreateEvents</function>.)
45994600
Note that <function>PQclear</function> should eventually be called
46004601
on the object, just as with a <structname>PGresult</structname>
46014602
returned by <application>libpq</application> itself.
46024603
</para>
46034604
</listitem>
46044605
</varlistentry>
46054606

4607+
<varlistentry>
4608+
<term>
4609+
<function>PQfireResultCreateEvents</function>
4610+
<indexterm>
4611+
<primary>PQfireResultCreateEvents</primary>
4612+
</indexterm>
4613+
</term>
4614+
<listitem>
4615+
<para>
4616+
Fires a <literal>PGEVT_RESULTCREATE</literal> event (see <xref
4617+
linkend="libpq-events">) for each event procedure registered in the
4618+
<structname>PGresult</structname> object. Returns non-zero for success,
4619+
zero if any event procedure fails.
4620+
4621+
<synopsis>
4622+
int PQfireResultCreateEvents(PGconn *conn, PGresult *res);
4623+
</synopsis>
4624+
</para>
4625+
4626+
<para>
4627+
The <literal>conn</> argument is passed through to event procedures
4628+
but not used directly. It can be <literal>NULL</> if the event
4629+
procedures won't use it.
4630+
</para>
4631+
4632+
<para>
4633+
Event procedures that have already received a
4634+
<literal>PGEVT_RESULTCREATE</> or <literal>PGEVT_RESULTCOPY</> event
4635+
for this object are not fired again.
4636+
</para>
4637+
4638+
<para>
4639+
The main reason that this function is separate from
4640+
<function>PQmakeEmptyPGResult</function> is that it is often appropriate
4641+
to create a <structname>PGresult</structname> and fill it with data
4642+
before invoking the event procedures.
4643+
</para>
4644+
</listitem>
4645+
</varlistentry>
4646+
46064647
<varlistentry>
46074648
<term>
46084649
<function>PQcopyResult</function>
@@ -4904,7 +4945,7 @@ defaultNoticeProcessor(void *arg, const char *message)
49044945
<synopsis>
49054946
typedef struct
49064947
{
4907-
constPGconn *conn;
4948+
PGconn *conn;
49084949
} PGEventRegister;
49094950
</synopsis>
49104951

@@ -4937,7 +4978,7 @@ typedef struct
49374978
<synopsis>
49384979
typedef struct
49394980
{
4940-
constPGconn *conn;
4981+
PGconn *conn;
49414982
} PGEventConnReset;
49424983
</synopsis>
49434984

@@ -4967,7 +5008,7 @@ typedef struct
49675008
<synopsis>
49685009
typedef struct
49695010
{
4970-
constPGconn *conn;
5011+
PGconn *conn;
49715012
} PGEventConnDestroy;
49725013
</synopsis>
49735014

@@ -4995,7 +5036,7 @@ typedef struct
49955036
<synopsis>
49965037
typedef struct
49975038
{
4998-
constPGconn *conn;
5039+
PGconn *conn;
49995040
PGresult *result;
50005041
} PGEventResultCreate;
50015042
</synopsis>
@@ -5063,7 +5104,7 @@ typedef struct
50635104
<synopsis>
50645105
typedef struct
50655106
{
5066-
constPGresult *result;
5107+
PGresult *result;
50675108
} PGEventResultDestroy;
50685109
</synopsis>
50695110

‎src/interfaces/libpq/exports.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/src/interfaces/libpq/exports.txt,v 1.20 2008/09/17 04:31:08 tgl Exp $
1+
# $PostgreSQL: pgsql/src/interfaces/libpq/exports.txt,v 1.21 2008/09/19 20:06:13 tgl Exp $
22
# Functions to be exported by libpq DLLs
33
PQconnectdb 1
44
PQsetdbLogin 2
@@ -150,3 +150,4 @@ PQinstanceData 147
150150
PQsetInstanceData 148
151151
PQresultInstanceData 149
152152
PQresultSetInstanceData 150
153+
PQfireResultCreateEvents 151

‎src/interfaces/libpq/libpq-events.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-events.c,v 1.2 2008/09/1916:40:40 tgl Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-events.c,v 1.3 2008/09/1920:06:13 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -175,3 +175,35 @@ PQresultInstanceData(const PGresult *result, PGEventProc proc)
175175

176176
returnNULL;
177177
}
178+
179+
/*
180+
* Fire RESULTCREATE events for an application-created PGresult.
181+
*
182+
* The conn argument can be NULL if event procedures won't use it.
183+
*/
184+
int
185+
PQfireResultCreateEvents(PGconn*conn,PGresult*res)
186+
{
187+
inti;
188+
189+
if (!res)
190+
return FALSE;
191+
192+
for (i=0;i<res->nEvents;i++)
193+
{
194+
if (!res->events[i].resultInitialized)
195+
{
196+
PGEventResultCreateevt;
197+
198+
evt.conn=conn;
199+
evt.result=res;
200+
if (!res->events[i].proc(PGEVT_RESULTCREATE,&evt,
201+
res->events[i].passThrough))
202+
return FALSE;
203+
204+
res->events[i].resultInitialized= TRUE;
205+
}
206+
}
207+
208+
return TRUE;
209+
}

‎src/interfaces/libpq/libpq-events.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-events.h,v 1.1 2008/09/17 04:31:08 tgl Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-events.h,v 1.2 2008/09/19 20:06:13 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -36,22 +36,22 @@ typedef enum
3636

3737
typedefstruct
3838
{
39-
constPGconn*conn;
39+
PGconn*conn;
4040
}PGEventRegister;
4141

4242
typedefstruct
4343
{
44-
constPGconn*conn;
44+
PGconn*conn;
4545
}PGEventConnReset;
4646

4747
typedefstruct
4848
{
49-
constPGconn*conn;
49+
PGconn*conn;
5050
}PGEventConnDestroy;
5151

5252
typedefstruct
5353
{
54-
constPGconn*conn;
54+
PGconn*conn;
5555
PGresult*result;
5656
}PGEventResultCreate;
5757

@@ -63,7 +63,7 @@ typedef struct
6363

6464
typedefstruct
6565
{
66-
constPGresult*result;
66+
PGresult*result;
6767
}PGEventResultDestroy;
6868

6969
typedefint (*PGEventProc) (PGEventIdevtId,void*evtInfo,void*passThrough);
@@ -84,6 +84,9 @@ extern intPQresultSetInstanceData(PGresult *result, PGEventProc proc, void *dat
8484
/* Gets the PGresult instance data for the provided proc. */
8585
externvoid*PQresultInstanceData(constPGresult*result,PGEventProcproc);
8686

87+
/* Fires RESULTCREATE events for an application-created PGresult. */
88+
externintPQfireResultCreateEvents(PGconn*conn,PGresult*res);
89+
8790
#ifdef__cplusplus
8891
}
8992
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp