Skip to content

Commit 26b237f

Browse files
committed
Various clarifications; add a clear DRAFT marker; minor adjustments in
some message types. In particular add text/binary flag to StartCopyIn and StartCopyOut, so that client library can know what is expected or forthcoming.
1 parent e8ee547 commit 26b237f

File tree

1 file changed

+70
-30
lines changed

1 file changed

+70
-30
lines changed

doc/src/sgml/protocol.sgml

Lines changed: 70 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.26 2003/04/15 22:51:18 tgl Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.27 2003/04/16 20:53:38 tgl Exp $ -->
22

33
<chapter id="protocol">
44
<title>Frontend/Backend Protocol</title>
55

6+
<caution>
7+
<para>
8+
This is currently a <emphasis>DRAFT</> description of FE/BE protocol
9+
version 3.0. Details are still subject to change.
10+
In particular, the representation of binary data is still under debate.
11+
</para>
12+
</caution>
13+
614
<para>
715
<application>PostgreSQL</application> uses a message-based protocol
816
for communication between frontends and backends (clients and servers).
@@ -504,11 +512,12 @@
504512
</Para>
505513

506514
<Para>
507-
The response to a <command>SELECT</> or <command>FETCH</> query
515+
The response to a <command>SELECT</>, <command>FETCH</>, or
516+
<command>SHOW</> query
508517
normally consists of RowDescription, zero or more
509518
DataRow or BinaryRow messages, and then CommandComplete.
510519
<command>COPY</> to or from the frontend invokes special protocol
511-
as described below.
520+
as described in <xref linkend="protocol-copy">.
512521
All other query types normally produce only
513522
a CommandComplete message.
514523
</Para>
@@ -524,7 +533,6 @@
524533
<Para>
525534
If a completely empty (no contents other than whitespace) query string
526535
is received, the response is EmptyQueryResponse followed by ReadyForQuery.
527-
(The need to specially distinguish this case is historical.)
528536
</Para>
529537

530538
<Para>
@@ -621,7 +629,10 @@
621629
The possible
622630
responses to Execute are the same as those described above for queries
623631
issued via simple query protocol, except that Execute doesn't cause
624-
ReadyForQuery to be issued.
632+
ReadyForQuery to be issued. Also, the choice between text and binary
633+
output (DataRow or BinaryRow messages) is determined by Execute's
634+
format field, regardless of the command; the <literal>BINARY</> attribute
635+
in cursor declarations is irrelevant when using this protocol.
625636
</para>
626637

627638
<para>
@@ -630,8 +641,11 @@
630641
PortalSuspended message; the appearance of this message tells the frontend
631642
that another Execute should be issued against the same portal to
632643
complete the operation. The CommandComplete message indicating
633-
completion of the source SELECT or FETCH command is not sent until
634-
the command is completed.
644+
completion of the source SQL command is not sent until
645+
the portal's execution is completed. Therefore, an Execute phase is
646+
always terminated by the appearance of exactly one of these messages:
647+
CommandComplete, EmptyQueryResponse (if the portal was created from
648+
an empty query string), ErrorResponse, or PortalSuspended.
635649
</para>
636650

637651
<para>
@@ -715,7 +729,16 @@
715729
<Sect2>
716730
<Title>Function Call</Title>
717731

718-
<Para>
732+
<note>
733+
<para>
734+
The Function Call sub-protocol is a legacy feature that is probably best
735+
avoided in new code. Similar results can be accomplished by setting up
736+
a prepared statement that does <literal>SELECT function($1, ...)</>.
737+
The Function Call cycle can then be replaced with Bind/Execute.
738+
</para>
739+
</note>
740+
741+
<para>
719742
A Function Call cycle is initiated by the frontend sending a
720743
FunctionCall message to the backend. The backend then sends one
721744
or more response messages depending on the results of the function
@@ -724,7 +747,7 @@
724747
function call.
725748
</para>
726749

727-
<Para>
750+
<para>
728751
The possible response messages from the backend are:
729752

730753
<VariableList>
@@ -741,7 +764,9 @@
741764
<Term>FunctionResultResponse</Term>
742765
<ListItem>
743766
<Para>
744-
The function call was executed and returned a result.
767+
The function call was executed and returned a non-null result.
768+
(Note that the Function Call protocol can only handle a single
769+
scalar result, not a rowtype or set of results.)
745770
</Para>
746771
</ListItem>
747772
</VarListEntry>
@@ -750,7 +775,7 @@
750775
<Term>FunctionVoidResponse</Term>
751776
<ListItem>
752777
<Para>
753-
The function call was executed and returned no result.
778+
The function call was executed and returned a NULL value.
754779
</Para>
755780
</ListItem>
756781
</VarListEntry>
@@ -800,8 +825,9 @@
800825
message (allowing successful termination) or a CopyFail message (which
801826
will cause the <command>COPY</> SQL statement to fail with an
802827
error). The backend then reverts to the command-processing mode it was
803-
in before the <command>COPY</> started (which will be either simple or
804-
extended query protocol).
828+
in before the <command>COPY</> started, which will be either simple or
829+
extended query protocol. It will next send either CommandComplete
830+
(if successful) or ErrorResponse (if not).
805831
</para>
806832

807833
<para>
@@ -826,7 +852,8 @@
826852
zero or more CopyDataRow messages, one per row, followed by CopyDone.
827853
(For <command>COPY BINARY</>, CopyBinaryRow messages are sent instead.)
828854
The backend then reverts to the command-processing mode it was
829-
in before the <command>COPY</> started. The frontend cannot abort
855+
in before the <command>COPY</> started, and sends CommandComplete.
856+
The frontend cannot abort
830857
the transfer (short of closing the connection), but it can discard
831858
unwanted CopyDataRow, CopyBinaryRow, and CopyDone messages.
832859
</para>
@@ -1668,7 +1695,7 @@ Bind (F)
16681695
</VarListEntry>
16691696
<VarListEntry>
16701697
<Term>
1671-
Int16
1698+
Int32
16721699
</Term>
16731700
<ListItem>
16741701
<Para>
@@ -2195,14 +2222,25 @@ CopyInResponse (B)
21952222
</VarListEntry>
21962223
<VarListEntry>
21972224
<Term>
2198-
Int32(4)
2225+
Int32(5)
21992226
</Term>
22002227
<ListItem>
22012228
<Para>
22022229
Length of message contents in bytes, including self.
22032230
</Para>
22042231
</ListItem>
22052232
</VarListEntry>
2233+
<VarListEntry>
2234+
<Term>
2235+
Int8
2236+
</Term>
2237+
<ListItem>
2238+
<Para>
2239+
0 for textual copy (CopyDataRow is expected), 1 for
2240+
binary copy (CopyBinaryRow is expected).
2241+
</Para>
2242+
</ListItem>
2243+
</VarListEntry>
22062244
</VariableList>
22072245

22082246
</Para>
@@ -2231,14 +2269,25 @@ CopyOutResponse (B)
22312269
</VarListEntry>
22322270
<VarListEntry>
22332271
<Term>
2234-
Int32(4)
2272+
Int32(5)
22352273
</Term>
22362274
<ListItem>
22372275
<Para>
22382276
Length of message contents in bytes, including self.
22392277
</Para>
22402278
</ListItem>
22412279
</VarListEntry>
2280+
<VarListEntry>
2281+
<Term>
2282+
Int8
2283+
</Term>
2284+
<ListItem>
2285+
<Para>
2286+
0 for textual copy (CopyDataRow will follow), 1 for
2287+
binary copy (CopyBinaryRow will follow).
2288+
</Para>
2289+
</ListItem>
2290+
</VarListEntry>
22422291
</VariableList>
22432292

22442293
</Para>
@@ -2402,29 +2451,20 @@ EmptyQueryResponse (B)
24022451
<ListItem>
24032452
<Para>
24042453
Identifies the message as a response to an empty query string.
2454+
(This substitutes for CommandComplete.)
24052455
</Para>
24062456
</ListItem>
24072457
</VarListEntry>
24082458
<VarListEntry>
24092459
<Term>
2410-
Int32(5)
2460+
Int32(4)
24112461
</Term>
24122462
<ListItem>
24132463
<Para>
24142464
Length of message contents in bytes, including self.
24152465
</Para>
24162466
</ListItem>
24172467
</VarListEntry>
2418-
<VarListEntry>
2419-
<Term>
2420-
String("")
2421-
</Term>
2422-
<ListItem>
2423-
<Para>
2424-
Unused.
2425-
</Para>
2426-
</ListItem>
2427-
</VarListEntry>
24282468
</VariableList>
24292469

24302470
</Para>
@@ -3014,7 +3054,7 @@ ParameterDescription (B)
30143054
</VarListEntry>
30153055
<VarListEntry>
30163056
<Term>
3017-
Int16
3057+
Int32
30183058
</Term>
30193059
<ListItem>
30203060
<Para>
@@ -3147,7 +3187,7 @@ Parse (F)
31473187
</VarListEntry>
31483188
<VarListEntry>
31493189
<Term>
3150-
Int16
3190+
Int32
31513191
</Term>
31523192
<ListItem>
31533193
<Para>

0 commit comments

Comments
 (0)