|
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 $ --> |
2 | 2 |
|
3 | 3 | <chapter id="protocol"> |
4 | 4 | <title>Frontend/Backend Protocol</title> |
5 | 5 |
|
| 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 | + |
6 | 14 | <para> |
7 | 15 | <application>PostgreSQL</application> uses a message-based protocol |
8 | 16 | for communication between frontends and backends (clients and servers). |
|
504 | 512 | </Para> |
505 | 513 |
|
506 | 514 | <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 |
508 | 517 | normally consists of RowDescription, zero or more |
509 | 518 | DataRow or BinaryRow messages, and then CommandComplete. |
510 | 519 | <command>COPY</> to or from the frontend invokes special protocol |
511 | | - as describedbelow. |
| 520 | + as describedin <xref linkend="protocol-copy">. |
512 | 521 | All other query types normally produce only |
513 | 522 | a CommandComplete message. |
514 | 523 | </Para> |
|
524 | 533 | <Para> |
525 | 534 | If a completely empty (no contents other than whitespace) query string |
526 | 535 | is received, the response is EmptyQueryResponse followed by ReadyForQuery. |
527 | | - (The need to specially distinguish this case is historical.) |
528 | 536 | </Para> |
529 | 537 |
|
530 | 538 | <Para> |
|
621 | 629 | The possible |
622 | 630 | responses to Execute are the same as those described above for queries |
623 | 631 | 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. |
625 | 636 | </para> |
626 | 637 |
|
627 | 638 | <para> |
|
630 | 641 | PortalSuspended message; the appearance of this message tells the frontend |
631 | 642 | that another Execute should be issued against the same portal to |
632 | 643 | 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. |
635 | 649 | </para> |
636 | 650 |
|
637 | 651 | <para> |
|
715 | 729 | <Sect2> |
716 | 730 | <Title>Function Call</Title> |
717 | 731 |
|
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> |
719 | 742 | A Function Call cycle is initiated by the frontend sending a |
720 | 743 | FunctionCall message to the backend. The backend then sends one |
721 | 744 | or more response messages depending on the results of the function |
|
724 | 747 | function call. |
725 | 748 | </para> |
726 | 749 |
|
727 | | - <Para> |
| 750 | + <para> |
728 | 751 | The possible response messages from the backend are: |
729 | 752 |
|
730 | 753 | <VariableList> |
|
741 | 764 | <Term>FunctionResultResponse</Term> |
742 | 765 | <ListItem> |
743 | 766 | <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.) |
745 | 770 | </Para> |
746 | 771 | </ListItem> |
747 | 772 | </VarListEntry> |
|
750 | 775 | <Term>FunctionVoidResponse</Term> |
751 | 776 | <ListItem> |
752 | 777 | <Para> |
753 | | - The function call was executed and returnedno result. |
| 778 | + The function call was executed and returneda NULL value. |
754 | 779 | </Para> |
755 | 780 | </ListItem> |
756 | 781 | </VarListEntry> |
|
800 | 825 | message (allowing successful termination) or a CopyFail message (which |
801 | 826 | will cause the <command>COPY</> SQL statement to fail with an |
802 | 827 | 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). |
805 | 831 | </para> |
806 | 832 |
|
807 | 833 | <para> |
|
826 | 852 | zero or more CopyDataRow messages, one per row, followed by CopyDone. |
827 | 853 | (For <command>COPY BINARY</>, CopyBinaryRow messages are sent instead.) |
828 | 854 | 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 |
830 | 857 | the transfer (short of closing the connection), but it can discard |
831 | 858 | unwanted CopyDataRow, CopyBinaryRow, and CopyDone messages. |
832 | 859 | </para> |
@@ -1668,7 +1695,7 @@ Bind (F) |
1668 | 1695 | </VarListEntry> |
1669 | 1696 | <VarListEntry> |
1670 | 1697 | <Term> |
1671 | | -Int16 |
| 1698 | +Int32 |
1672 | 1699 | </Term> |
1673 | 1700 | <ListItem> |
1674 | 1701 | <Para> |
@@ -2195,14 +2222,25 @@ CopyInResponse (B) |
2195 | 2222 | </VarListEntry> |
2196 | 2223 | <VarListEntry> |
2197 | 2224 | <Term> |
2198 | | - Int32(4) |
| 2225 | + Int32(5) |
2199 | 2226 | </Term> |
2200 | 2227 | <ListItem> |
2201 | 2228 | <Para> |
2202 | 2229 | Length of message contents in bytes, including self. |
2203 | 2230 | </Para> |
2204 | 2231 | </ListItem> |
2205 | 2232 | </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> |
2206 | 2244 | </VariableList> |
2207 | 2245 |
|
2208 | 2246 | </Para> |
@@ -2231,14 +2269,25 @@ CopyOutResponse (B) |
2231 | 2269 | </VarListEntry> |
2232 | 2270 | <VarListEntry> |
2233 | 2271 | <Term> |
2234 | | - Int32(4) |
| 2272 | + Int32(5) |
2235 | 2273 | </Term> |
2236 | 2274 | <ListItem> |
2237 | 2275 | <Para> |
2238 | 2276 | Length of message contents in bytes, including self. |
2239 | 2277 | </Para> |
2240 | 2278 | </ListItem> |
2241 | 2279 | </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> |
2242 | 2291 | </VariableList> |
2243 | 2292 |
|
2244 | 2293 | </Para> |
@@ -2402,29 +2451,20 @@ EmptyQueryResponse (B) |
2402 | 2451 | <ListItem> |
2403 | 2452 | <Para> |
2404 | 2453 | Identifies the message as a response to an empty query string. |
| 2454 | +(This substitutes for CommandComplete.) |
2405 | 2455 | </Para> |
2406 | 2456 | </ListItem> |
2407 | 2457 | </VarListEntry> |
2408 | 2458 | <VarListEntry> |
2409 | 2459 | <Term> |
2410 | | - Int32(5) |
| 2460 | + Int32(4) |
2411 | 2461 | </Term> |
2412 | 2462 | <ListItem> |
2413 | 2463 | <Para> |
2414 | 2464 | Length of message contents in bytes, including self. |
2415 | 2465 | </Para> |
2416 | 2466 | </ListItem> |
2417 | 2467 | </VarListEntry> |
2418 | | -<VarListEntry> |
2419 | | -<Term> |
2420 | | - String("") |
2421 | | -</Term> |
2422 | | -<ListItem> |
2423 | | -<Para> |
2424 | | - Unused. |
2425 | | -</Para> |
2426 | | -</ListItem> |
2427 | | -</VarListEntry> |
2428 | 2468 | </VariableList> |
2429 | 2469 |
|
2430 | 2470 | </Para> |
@@ -3014,7 +3054,7 @@ ParameterDescription (B) |
3014 | 3054 | </VarListEntry> |
3015 | 3055 | <VarListEntry> |
3016 | 3056 | <Term> |
3017 | | -Int16 |
| 3057 | +Int32 |
3018 | 3058 | </Term> |
3019 | 3059 | <ListItem> |
3020 | 3060 | <Para> |
@@ -3147,7 +3187,7 @@ Parse (F) |
3147 | 3187 | </VarListEntry> |
3148 | 3188 | <VarListEntry> |
3149 | 3189 | <Term> |
3150 | | -Int16 |
| 3190 | +Int32 |
3151 | 3191 | </Term> |
3152 | 3192 | <ListItem> |
3153 | 3193 | <Para> |
|