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

Commit755d191

Browse files
committed
Add display of eventual result RowDescription (if any) to the output
of Describe on a prepared statement. This was in the original 3.0protocol proposal, but I took it out for reasons that seemed good atthe time. Put it back per yesterday's pghackers discussion.
1 parent8f6a6b7 commit755d191

File tree

7 files changed

+84
-42
lines changed

7 files changed

+84
-42
lines changed

‎doc/src/sgml/protocol.sgml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.34 2003/05/05 00:44:55 tgl Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.35 2003/05/06 21:51:41 tgl Exp $ -->
22

33
<chapter id="protocol">
44
<title>Frontend/Backend Protocol</title>
@@ -149,7 +149,8 @@
149149
<firstterm>bind</> step, which creates a portal given a prepared
150150
statement and values for any needed parameters; and an
151151
<firstterm>execute</> step that runs a portal's query. In the case of
152-
a <command>SELECT</> query, the execute step can be told to fetch only
152+
a query that returns rows (<command>SELECT</>, <command>SHOW</>, etc),
153+
the execute step can be told to fetch only
153154
a limited number of rows, so that multiple execute steps may be needed
154155
to complete the operation.
155156
</para>
@@ -456,7 +457,7 @@
456457
<ListItem>
457458
<Para>
458459
Indicates that rows are about to be returned in response to
459-
a <command>SELECT</command> or<command>FETCH</command> query.
460+
a <command>SELECT</command>,<command>FETCH</command>, etc query.
460461
The message contents describe the layout of the rows. This
461462
will be followed by a DataRow or BinaryRow message (depending on
462463
whether a binary cursor was specified) for each row being returned
@@ -512,8 +513,8 @@
512513
</Para>
513514

514515
<Para>
515-
The response to a <command>SELECT</>, <command>FETCH</>, or
516-
<command>SHOW</>query
516+
The response to a <command>SELECT</> query (or other queries that
517+
return rowsets, such as<command>EXPLAIN</>or <command>SHOW</>)
517518
normally consists of RowDescription, zero or more
518519
DataRow or BinaryRow messages, and then CommandComplete.
519520
<command>COPY</> to or from the frontend invokes special protocol
@@ -632,8 +633,8 @@
632633
unnamed portal), the desired output format (text or binary), and
633634
a maximum result-row count (zero meaning <quote>fetch all rows</>).
634635
The output format and result-row count are only meaningful for portals
635-
containingSELECTcommands; they are ignored for other types of commands.
636-
The possible
636+
containing commands that return rowsets; they are ignored for other types
637+
of commands.The possible
637638
responses to Execute are the same as those described above for queries
638639
issued via simple query protocol, except that Execute doesn't cause
639640
ReadyForQuery to be issued. Also, the choice between text and binary
@@ -689,20 +690,27 @@
689690
portal (or an empty string for the unnamed portal). The response is a
690691
RowDescription message describing the rows that will be returned by
691692
executing the portal; or a NoData message if the portal does not contain a
692-
SELECT-type query; or ErrorResponse if there is no such portal. In most
693-
situations the frontend will want to issue this message before issuing
694-
Execute, to obtain a description of the results it will get back.
693+
query that will return rows; or ErrorResponse if there is no such portal.
695694
</para>
696695

697696
<para>
698697
The Describe message (statement variant) specifies the name of an existing
699698
prepared statement (or an empty string for the unnamed prepared
700699
statement). The response is a ParameterDescription message describing the
701-
parameters needed by the statement. ErrorResponse is issued if there is
702-
no such prepared statement. This message may be useful if the client
703-
library is uncertain about the parameters needed by a prepared statement.
700+
parameters needed by the statement (if any), followed by a RowDescription
701+
message describing the rows that will be returned when the statement is
702+
eventually executed (or NoData if the statement will not return rows).
703+
ErrorResponse is issued if there is no such prepared statement.
704704
</para>
705705

706+
<tip>
707+
<para>
708+
In most scenarios the frontend should issue one or the other variant
709+
of Describe before issuing Execute, to ensure that it knows how to
710+
interpret the results it will get back.
711+
</para>
712+
</tip>
713+
706714
<para>
707715
The Close message closes an existing prepared statement or portal
708716
and releases resources. It is not an error to issue Close against
@@ -2563,7 +2571,7 @@ Execute (F)
25632571
<ListItem>
25642572
<Para>
25652573
Maximum number of rows to return, if portal contains
2566-
aSELECT or FETCH query (ignored otherwise). Zero
2574+
aquery that returns rows (ignored otherwise). Zero
25672575
denotes <quote>no limit</>.
25682576
</Para>
25692577
</ListItem>

‎src/backend/commands/prepare.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 2002-2003, PostgreSQL Global Development Group
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.16 2003/05/0620:26:26 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.17 2003/05/0621:51:41 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -393,6 +393,34 @@ FetchPreparedStatementParams(const char *stmt_name)
393393
returnentry->argtype_list;
394394
}
395395

396+
/*
397+
* Given a prepared statement, determine the result tupledesc it will
398+
* produce. Returns NULL if the execution will not return tuples.
399+
*
400+
* Note: the result is created or copied into current memory context.
401+
*/
402+
TupleDesc
403+
FetchPreparedStatementResultDesc(PreparedStatement*stmt)
404+
{
405+
Query*query;
406+
407+
switch (ChoosePortalStrategy(stmt->query_list))
408+
{
409+
casePORTAL_ONE_SELECT:
410+
query= (Query*)lfirst(stmt->query_list);
411+
returnExecCleanTypeFromTL(query->targetList, false);
412+
413+
casePORTAL_UTIL_SELECT:
414+
query= (Query*)lfirst(stmt->query_list);
415+
returnUtilityTupleDescriptor(query->utilityStmt);
416+
417+
casePORTAL_MULTI_QUERY:
418+
/* will not return tuples */
419+
break;
420+
}
421+
returnNULL;
422+
}
423+
396424
/*
397425
* Implements the 'DEALLOCATE' utility statement: deletes the
398426
* specified plan from storage.

‎src/backend/tcop/postgres.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.336 2003/05/0620:26:27 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.337 2003/05/0621:51:41 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -1428,6 +1428,7 @@ static void
14281428
exec_describe_statement_message(constchar*stmt_name)
14291429
{
14301430
PreparedStatement*pstmt;
1431+
TupleDesctupdesc;
14311432
List*l;
14321433
StringInfoDatabuf;
14331434

@@ -1445,6 +1446,9 @@ exec_describe_statement_message(const char *stmt_name)
14451446
if (whereToSendOutput!=Remote)
14461447
return;/* can't actually do anything... */
14471448

1449+
/*
1450+
* First describe the parameters...
1451+
*/
14481452
pq_beginmessage(&buf,'t');/* parameter description message type */
14491453
pq_sendint(&buf,length(pstmt->argtype_list),4);
14501454

@@ -1455,6 +1459,24 @@ exec_describe_statement_message(const char *stmt_name)
14551459
pq_sendint(&buf, (int)ptype,4);
14561460
}
14571461
pq_endmessage(&buf);
1462+
1463+
/*
1464+
* Next send RowDescription or NoData to describe the result...
1465+
*/
1466+
tupdesc=FetchPreparedStatementResultDesc(pstmt);
1467+
if (tupdesc)
1468+
{
1469+
List*targetlist;
1470+
1471+
if (ChoosePortalStrategy(pstmt->query_list)==PORTAL_ONE_SELECT)
1472+
targetlist= ((Query*)lfirst(pstmt->query_list))->targetList;
1473+
else
1474+
targetlist=NIL;
1475+
SendRowDescriptionMessage(tupdesc,targetlist);
1476+
}
1477+
else
1478+
pq_putemptymessage('n');/* NoData */
1479+
14581480
}
14591481

14601482
/*
@@ -2359,7 +2381,7 @@ PostgresMain(int argc, char *argv[], const char *username)
23592381
if (!IsUnderPostmaster)
23602382
{
23612383
puts("\nPOSTGRES backend interactive interface ");
2362-
puts("$Revision: 1.336 $ $Date: 2003/05/0620:26:27 $\n");
2384+
puts("$Revision: 1.337 $ $Date: 2003/05/0621:51:41 $\n");
23632385
}
23642386

23652387
/*

‎src/backend/tcop/utility.c

Lines changed: 3 additions & 20 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.199 2003/05/0620:26:27 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.200 2003/05/0621:51:41 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -1052,11 +1052,6 @@ UtilityReturnsTuples(Node *parsetree)
10521052
portal=GetPortalByName(stmt->portalname);
10531053
if (!PortalIsValid(portal))
10541054
return false;/* not our business to raise error */
1055-
/*
1056-
* Note: if portal contains multiple statements then it's
1057-
* possible some of them will return tuples, but we don't
1058-
* handle that case here.
1059-
*/
10601055
returnportal->tupDesc ? true : false;
10611056
}
10621057

@@ -1077,7 +1072,7 @@ UtilityReturnsTuples(Node *parsetree)
10771072
casePORTAL_UTIL_SELECT:
10781073
return true;
10791074
casePORTAL_MULTI_QUERY:
1080-
/*can't figure it out, per note above */
1075+
/*will not return tuples */
10811076
break;
10821077
}
10831078
return false;
@@ -1124,25 +1119,13 @@ UtilityTupleDescriptor(Node *parsetree)
11241119
{
11251120
ExecuteStmt*stmt= (ExecuteStmt*)parsetree;
11261121
PreparedStatement*entry;
1127-
Query*query;
11281122

11291123
if (stmt->into)
11301124
returnNULL;
11311125
entry=FetchPreparedStatement(stmt->name, false);
11321126
if (!entry)
11331127
returnNULL;/* not our business to raise error */
1134-
switch (ChoosePortalStrategy(entry->query_list))
1135-
{
1136-
casePORTAL_ONE_SELECT:
1137-
query= (Query*)lfirst(entry->query_list);
1138-
returnExecCleanTypeFromTL(query->targetList, false);
1139-
casePORTAL_UTIL_SELECT:
1140-
query= (Query*)lfirst(entry->query_list);
1141-
returnUtilityTupleDescriptor(query->utilityStmt);
1142-
casePORTAL_MULTI_QUERY:
1143-
break;
1144-
}
1145-
returnNULL;
1128+
returnFetchPreparedStatementResultDesc(entry);
11461129
}
11471130

11481131
caseT_ExplainStmt:

‎src/include/commands/prepare.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 2002-2003, PostgreSQL Global Development Group
88
*
9-
* $Id: prepare.h,v 1.5 2003/05/0620:26:27 tgl Exp $
9+
* $Id: prepare.h,v 1.6 2003/05/0621:51:42 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -57,5 +57,6 @@ extern PreparedStatement *FetchPreparedStatement(const char *stmt_name,
5757
boolthrowError);
5858
externvoidDropPreparedStatement(constchar*stmt_name,boolshowError);
5959
externList*FetchPreparedStatementParams(constchar*stmt_name);
60+
externTupleDescFetchPreparedStatementResultDesc(PreparedStatement*stmt);
6061

6162
#endif/* PREPARE_H */

‎src/include/libpq/pqcomm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $Id: pqcomm.h,v 1.82 2003/05/05 00:44:56 tgl Exp $
12+
* $Id: pqcomm.h,v 1.83 2003/05/06 21:51:42 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -106,7 +106,7 @@ typedef union SockAddr
106106
/* The earliest and latest frontend/backend protocol version supported. */
107107

108108
#definePG_PROTOCOL_EARLIESTPG_PROTOCOL(1,0)
109-
#definePG_PROTOCOL_LATESTPG_PROTOCOL(3,106)/* XXX temporary value */
109+
#definePG_PROTOCOL_LATESTPG_PROTOCOL(3,107)/* XXX temporary value */
110110

111111
typedefuint32ProtocolVersion;/* FE/BE protocol version number */
112112

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: libpq-int.h,v 1.67 2003/05/05 00:44:56 tgl Exp $
15+
* $Id: libpq-int.h,v 1.68 2003/05/06 21:51:42 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -56,7 +56,7 @@ typedef int ssize_t;/* ssize_t doesn't exist in VC (atleast
5656
* pqcomm.h describe what the backend knows, not what libpq knows.
5757
*/
5858

59-
#definePG_PROTOCOL_LIBPQPG_PROTOCOL(3,106)/* XXX temporary value */
59+
#definePG_PROTOCOL_LIBPQPG_PROTOCOL(3,107)/* XXX temporary value */
6060

6161
/*
6262
* POSTGRES backend dependent Constants.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp