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

Commit81f6db4

Browse files
committed
Allow PQcmdTuples to return row counts for MOVE and FETCH.
Neil Conway
1 parent1eb9fd4 commit81f6db4

File tree

4 files changed

+90
-69
lines changed

4 files changed

+90
-69
lines changed

‎doc/src/sgml/libpq.sgml

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.110 2003/02/14 02:21:25 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.111 2003/02/19 03:59:02 momjian Exp $
33
-->
44

55
<chapter id="libpq">
@@ -702,12 +702,11 @@ char *PQerrorMessage(const PGconn* conn);
702702
int PQbackendPID(const PGconn *conn);
703703
</synopsis>
704704
The backend <acronym>PID</acronym> is useful for debugging
705-
purposes and for comparison
706-
to NOTIFY messages (which include the <acronym>PID</acronym> of
707-
the notifying backend).
708-
Note that the <acronym>PID</acronym> belongs to a process
709-
executing on the database
710-
server host, not the local host!
705+
purposes and for comparison to <command>NOTIFY</command>
706+
messages (which include the <acronym>PID</acronym> of the
707+
notifying backend). Note that the <acronym>PID</acronym>
708+
belongs to a process executing on the database server host, not
709+
the local host!
711710
</para>
712711
</listitem>
713712

@@ -818,13 +817,14 @@ ExecStatusType PQresultStatus(const PGresult *res)
818817
</listitem>
819818
</itemizedlist>
820819

821-
If the result status is <literal>PGRES_TUPLES_OK</literal>, then the
822-
routines described below can be used to retrieve the
823-
rows returned by the query. Note that a SELECT command that
824-
happens to retrieve zero rows still shows <literal>PGRES_TUPLES_OK</literal>.
825-
<literal>PGRES_COMMAND_OK</literal> is for commands that can never return rows
826-
(INSERT, UPDATE, etc.). A response of <literal>PGRES_EMPTY_QUERY</literal> often
827-
exposes a bug in the client software.
820+
If the result status is <literal>PGRES_TUPLES_OK</literal>, then the
821+
routines described below can be used to retrieve the rows returned by
822+
the query. Note that a <command>SELECT</command> command that happens
823+
to retrieve zero rows still shows <literal>PGRES_TUPLES_OK</literal>.
824+
<literal>PGRES_COMMAND_OK</literal> is for commands that can never
825+
return rows (<command>INSERT</command>, <command>UPDATE</command>,
826+
etc.). A response of <literal>PGRES_EMPTY_QUERY</literal> often
827+
indicates a bug in the client software.
828828
</para>
829829
</listitem>
830830

@@ -1243,36 +1243,41 @@ char * PQcmdStatus(PGresult *res);
12431243
char * PQcmdTuples(PGresult *res);
12441244
</synopsis>
12451245
If the <acronym>SQL</acronym> command that generated the
1246-
<structname>PGresult</structname> was INSERT, UPDATE or DELETE, this returns a
1247-
string containing the number of rows affected. If the
1248-
command was anything else, it returns the empty string.
1246+
<structname>PGresult</structname> was <command>INSERT</command>,
1247+
<command>UPDATE</command>, <command>DELETE</command>,
1248+
<command>MOVE</command>, or <command>FETCH</command> this
1249+
returns a string containing the number of rows affected. If the
1250+
command was anything else, it returns the empty string.
12491251
</para>
12501252
</listitem>
12511253

12521254
<listitem>
12531255
<para>
12541256
<function>PQoidValue</function>
1255-
Returns the object ID of the inserted row, if the
1256-
<acronym>SQL</acronym> command was an INSERT
1257-
that inserted exactly one row into a table that has OIDs.
1258-
Otherwise, returns <literal>InvalidOid</literal>.
1257+
Returns the object ID of the inserted row, if the
1258+
<acronym>SQL</acronym> command was an<command>INSERT</command>
1259+
that inserted exactly one row into a table that has OIDs.
1260+
Otherwise, returns <literal>InvalidOid</literal>.
12591261
<synopsis>
12601262
Oid PQoidValue(const PGresult *res);
12611263
</synopsis>
1262-
The type <type>Oid</type> and the constant <literal>InvalidOid</literal>
1263-
will be defined if you include the <application>libpq</application>
1264-
header file. They will both be some integer type.
1264+
The type <type>Oid</type> and the constant
1265+
<literal>InvalidOid</literal> will be defined if you include the
1266+
<application>libpq</application> header file. They will both be
1267+
some integer type.
12651268
</para>
12661269
</listitem>
12671270

12681271
<listitem>
12691272
<para>
12701273
<function>PQoidStatus</function>
1271-
Returns a string with the object ID of the inserted row, if the
1272-
<acronym>SQL</acronym> command was an INSERT.
1273-
(The string will be <literal>0</> if the INSERT did not insert exactly one
1274-
row, or if the target table does not have OIDs.) If the command
1275-
was not an INSERT, returns an empty string.
1274+
Returns a string with the object ID
1275+
of the inserted row, if the <acronym>SQL</acronym> command
1276+
was an <command>INSERT</command>. (The string will be
1277+
<literal>0</> if the <command>INSERT</command> did not
1278+
insert exactly one row, or if the target table does not have
1279+
OIDs.) If the command was not an <command>INSERT</command>,
1280+
returns an empty string.
12761281
<synopsis>
12771282
char * PQoidStatus(const PGresult *res);
12781283
</synopsis>
@@ -1530,7 +1535,8 @@ When the main loop detects input ready, it should call
15301535
<function>PQconsumeInput</function> to read the input. It can then call
15311536
<function>PQisBusy</function>, followed by <function>PQgetResult</function>
15321537
if <function>PQisBusy</function> returns false (0). It can also call
1533-
<function>PQnotifies</function> to detect NOTIFY messages (see <xref linkend="libpq-notify">).
1538+
<function>PQnotifies</function> to detect <command>NOTIFY</command>
1539+
messages (see <xref linkend="libpq-notify">).
15341540
</para>
15351541

15361542
<para>
@@ -1700,13 +1706,13 @@ of asynchronous notification.
17001706
<function>PQnotifies()</function> does not actually read backend data; it just
17011707
returns messages previously absorbed by another <application>libpq</application>
17021708
function. In prior releases of <application>libpq</application>, the only way
1703-
to ensure timely receipt of NOTIFY messages was to constantly submit queries,
1709+
to ensure timely receipt of<command>NOTIFY</command> messages was to constantly submit queries,
17041710
even empty ones, and then check <function>PQnotifies()</function> after each
17051711
<function>PQexec()</function>. While this still works, it is
17061712
deprecated as a waste of processing power.
17071713
</para>
17081714
<para>
1709-
A better way to check for NOTIFY
1715+
A better way to check for<command>NOTIFY</command>
17101716
messages when you have no useful queries to make is to call
17111717
<function>PQconsumeInput()</function>, then check
17121718
<function>PQnotifies()</function>.

‎doc/src/sgml/protocol.sgml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.24 2002/03/22 19:20:21 petere Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.25 2003/02/19 03:59:02 momjian Exp $ -->
22

33
<chapter id="protocol">
44
<title>Frontend/Backend Protocol</title>
@@ -1335,6 +1335,20 @@ CompletedResponse (B)
13351335
<literal>UPDATE <Replaceable>rows</Replaceable></literal> where
13361336
<Replaceable>rows</Replaceable> is the number of rows updated.
13371337
</Para>
1338+
1339+
<para>
1340+
For a <command>MOVE</command> command, the tag is
1341+
<literal>MOVE <replaceable>rows</replaceable></literal> where
1342+
<replaceable>rows</replaceable> is the number of rows the
1343+
cursor's position has been changed by.
1344+
</para>
1345+
1346+
<para>
1347+
For a <command>FETCH</command> command, the tag is
1348+
<literal>FETCH <replaceable>rows</replaceable></literal> where
1349+
<replaceable>rows</replaceable> is the number of rows that
1350+
have been retrieved from the cursor.
1351+
</para>
13381352
</ListItem>
13391353
</VarListEntry>
13401354
</VariableList>

‎src/backend/tcop/utility.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.192 2003/02/13 05:20:01 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.193 2003/02/19 03:59:02 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -254,7 +254,7 @@ ProcessUtility(Node *parsetree,
254254
switch (nodeTag(parsetree))
255255
{
256256
/*
257-
* ******************************** transactions********************************
257+
* ******************** transactions ********************
258258
*/
259259
caseT_TransactionStmt:
260260
{

‎src/interfaces/libpq/fe-exec.c

Lines changed: 35 additions & 34 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-exec.c,v 1.124 2003/01/07 22:23:17 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.125 2003/02/19 03:59:02 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2272,7 +2272,7 @@ PQoidStatus(const PGresult *res)
22722272

22732273
/*
22742274
PQoidValue -
2275-
a perhaps preferable form of the above which just returns
2275+
a perhaps preferable form of the above which just returns
22762276
an Oid type
22772277
*/
22782278
Oid
@@ -2300,53 +2300,54 @@ PQoidValue(const PGresult *res)
23002300

23012301
/*
23022302
PQcmdTuples -
2303-
if the last command was an INSERT/UPDATE/DELETE, return number
2304-
of inserted/affected tuples, if not, return ""
2303+
If the last command was an INSERT/UPDATE/DELETE/MOVE/FETCH, return a
2304+
string containing the number of inserted/affected tuples. If not,
2305+
return "".
2306+
2307+
XXX: this should probably return an int
23052308
*/
23062309
char*
23072310
PQcmdTuples(PGresult*res)
23082311
{
23092312
charnoticeBuf[128];
2313+
char*p;
23102314

23112315
if (!res)
23122316
return"";
23132317

2314-
if (strncmp(res->cmdStatus,"INSERT",6)==0||
2315-
strncmp(res->cmdStatus,"DELETE",6)==0||
2316-
strncmp(res->cmdStatus,"UPDATE",6)==0)
2318+
if (strncmp(res->cmdStatus,"INSERT ",7)==0)
23172319
{
2318-
char*p=res->cmdStatus+6;
2319-
2320-
if (*p==0)
2321-
{
2322-
if (res->noticeHook)
2323-
{
2324-
snprintf(noticeBuf,sizeof(noticeBuf),
2325-
libpq_gettext("could not interpret result from server: %s\n"),
2326-
res->cmdStatus);
2327-
DONOTICE(res,noticeBuf);
2328-
}
2329-
return"";
2330-
}
2320+
p=res->cmdStatus+6;
23312321
p++;
2332-
if (*(res->cmdStatus)!='I')/* UPDATE/DELETE */
2333-
returnp;
2322+
/* INSERT: skip oid */
23342323
while (*p!=' '&&*p)
2335-
p++;/* INSERT: skip oid */
2336-
if (*p==0)
2324+
p++;
2325+
}
2326+
elseif (strncmp(res->cmdStatus,"DELETE ",7)==0||
2327+
strncmp(res->cmdStatus,"UPDATE ",7)==0)
2328+
p=res->cmdStatus+6;
2329+
elseif (strncmp(res->cmdStatus,"FETCH ",6)==0)
2330+
p=res->cmdStatus+5;
2331+
elseif (strncmp(res->cmdStatus,"MOVE ",5)==0)
2332+
p=res->cmdStatus+4;
2333+
else
2334+
return"";
2335+
2336+
p++;
2337+
2338+
if (*p==0)
2339+
{
2340+
if (res->noticeHook)
23372341
{
2338-
if (res->noticeHook)
2339-
{
2340-
snprintf(noticeBuf,sizeof(noticeBuf),
2341-
libpq_gettext("no row count available\n"));
2342-
DONOTICE(res,noticeBuf);
2343-
}
2344-
return"";
2342+
snprintf(noticeBuf,sizeof(noticeBuf),
2343+
libpq_gettext("could not interpret result from server: %s\n"),
2344+
res->cmdStatus);
2345+
DONOTICE(res,noticeBuf);
23452346
}
2346-
p++;
2347-
returnp;
2347+
return"";
23482348
}
2349-
return"";
2349+
2350+
returnp;
23502351
}
23512352

23522353
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp