diff options
| author | Tom Lane | 2003-04-26 20:23:00 +0000 |
|---|---|---|
| committer | Tom Lane | 2003-04-26 20:23:00 +0000 |
| commit | 4db9689d1a0a97b8b6060bf8bacac53a0d47825d (patch) | |
| tree | 0e754b59deaba85b54484962131a3b8c658193ed /src/backend | |
| parent | 2b1e36c7c0f294c70595bddaae0caecbcf8b50c6 (diff) | |
Add transaction status field to ReadyForQuery messages, and make room
for tableID/columnID in RowDescription. (The latter isn't really
implemented yet though --- the backend always sends zeroes, and libpq
just throws away the data.)
Diffstat (limited to 'src/backend')
| -rw-r--r-- | src/backend/access/common/printtup.c | 13 | ||||
| -rw-r--r-- | src/backend/access/transam/xact.c | 39 | ||||
| -rw-r--r-- | src/backend/tcop/dest.c | 14 |
3 files changed, 56 insertions, 10 deletions
diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c index c88dedd93fd..160b703223f 100644 --- a/src/backend/access/common/printtup.c +++ b/src/backend/access/common/printtup.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.66 2003/04/22 00:08:06 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.67 2003/04/26 20:22:58 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -98,6 +98,7 @@ printtup_setup(DestReceiver *self, int operation, { Form_pg_attribute *attrs = typeinfo->attrs; int natts = typeinfo->natts; + int proto = PG_PROTOCOL_MAJOR(FrontendProtocol); int i; StringInfoData buf; @@ -107,11 +108,19 @@ printtup_setup(DestReceiver *self, int operation, for (i = 0; i < natts; ++i) { pq_sendstring(&buf, NameStr(attrs[i]->attname)); + /* column ID info appears in protocol 3.0 and up */ + if (proto >= 3) + { + /* XXX not yet implemented, send zeroes */ + pq_sendint(&buf, 0, 4); + pq_sendint(&buf, 0, 2); + } pq_sendint(&buf, (int) attrs[i]->atttypid, sizeof(attrs[i]->atttypid)); pq_sendint(&buf, attrs[i]->attlen, sizeof(attrs[i]->attlen)); - if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 2) + /* typmod appears in protocol 2.0 and up */ + if (proto >= 2) pq_sendint(&buf, attrs[i]->atttypmod, sizeof(attrs[i]->atttypmod)); } diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 598e3c880e5..a15985d3bd7 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.145 2003/03/27 16:51:27 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.146 2003/04/26 20:22:59 tgl Exp $ * * NOTES * Transaction aborts can now occur two ways: @@ -1705,17 +1705,44 @@ AbortOutOfAnyTransaction(void) s->blockState = TBLOCK_DEFAULT; } +/* + * IsTransactionBlock --- are we within a transaction block? + */ bool IsTransactionBlock(void) { TransactionState s = CurrentTransactionState; - if (s->blockState == TBLOCK_INPROGRESS - || s->blockState == TBLOCK_ABORT - || s->blockState == TBLOCK_ENDABORT) - return true; + if (s->blockState == TBLOCK_DEFAULT) + return false; - return false; + return true; +} + +/* + * TransactionBlockStatusCode - return status code to send in ReadyForQuery + */ +char +TransactionBlockStatusCode(void) +{ + TransactionState s = CurrentTransactionState; + + switch (s->blockState) + { + case TBLOCK_DEFAULT: + return 'I'; /* idle --- not in transaction */ + case TBLOCK_BEGIN: + case TBLOCK_INPROGRESS: + case TBLOCK_END: + return 'T'; /* in transaction */ + case TBLOCK_ABORT: + case TBLOCK_ENDABORT: + return 'E'; /* in failed transaction */ + } + + /* should never get here */ + elog(ERROR, "bogus transaction block state"); + return 0; /* keep compiler quiet */ } diff --git a/src/backend/tcop/dest.c b/src/backend/tcop/dest.c index 5ccaa60995c..41906a348a4 100644 --- a/src/backend/tcop/dest.c +++ b/src/backend/tcop/dest.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/tcop/dest.c,v 1.53 2003/04/22 00:08:07 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/tcop/dest.c,v 1.54 2003/04/26 20:22:59 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -29,6 +29,7 @@ #include "postgres.h" #include "access/printtup.h" +#include "access/xact.h" #include "executor/tstoreReceiver.h" #include "libpq/libpq.h" #include "libpq/pqformat.h" @@ -177,6 +178,7 @@ NullCommand(CommandDest dest) * * The ReadyForQuery message is sent in protocol versions 2.0 and up * so that the FE can tell when we are done processing a query string. + * In versions 3.0 and up, it also carries a transaction state indicator. * * Note that by flushing the stdio buffer here, we can avoid doing it * most other places and thus reduce the number of separate packets sent. @@ -189,7 +191,15 @@ ReadyForQuery(CommandDest dest) { case RemoteInternal: case Remote: - if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 2) + if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 3) + { + StringInfoData buf; + + pq_beginmessage(&buf, 'Z'); + pq_sendbyte(&buf, TransactionBlockStatusCode()); + pq_endmessage(&buf); + } + else if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 2) pq_putemptymessage('Z'); /* Flush output at end of cycle in any case. */ pq_flush(); |
