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

Commit2e74c53

Browse files
committed
Provide for binary input/output of enums, to fix complaint from Merlin Moncure.
This just provides text values, we're not exposing the underlying Oid representation.Catalog version bumped.
1 parenta6b5765 commit2e74c53

File tree

5 files changed

+81
-8
lines changed

5 files changed

+81
-8
lines changed

‎src/backend/commands/typecmds.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.106 2007/06/20 18:15:49 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.107 2007/09/04 16:41:42 adunstan Exp $
1212
*
1313
* DESCRIPTION
1414
* The "DefineFoo" routines take the parse tree and pick out the
@@ -1039,8 +1039,8 @@ DefineEnum(CreateEnumStmt *stmt)
10391039
DEFAULT_TYPDELIM,/* array element delimiter */
10401040
F_ENUM_IN,/* input procedure */
10411041
F_ENUM_OUT,/* output procedure */
1042-
InvalidOid,/* receive procedure - none */
1043-
InvalidOid,/* send procedure - none */
1042+
F_ENUM_RECV,/* receive procedure */
1043+
F_ENUM_SEND,/* send procedure */
10441044
InvalidOid,/* typmodin procedure - none */
10451045
InvalidOid,/* typmodout procedure - none */
10461046
InvalidOid,/* analyze procedure - default */

‎src/backend/utils/adt/enum.c

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/enum.c,v 1.3 2007/06/05 21:31:06 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/enum.c,v 1.4 2007/09/04 16:41:42 adunstan Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -19,6 +19,8 @@
1919
#include"utils/builtins.h"
2020
#include"utils/lsyscache.h"
2121
#include"utils/syscache.h"
22+
#include"libpq/pqformat.h"
23+
#include"miscadmin.h"
2224

2325

2426
staticArrayType*enum_range_internal(Oidenumtypoid,Oidlower,Oidupper);
@@ -86,6 +88,73 @@ enum_out(PG_FUNCTION_ARGS)
8688
PG_RETURN_CSTRING(result);
8789
}
8890

91+
/* Binary I/O support */
92+
Datum
93+
enum_recv(PG_FUNCTION_ARGS)
94+
{
95+
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
96+
Oidenumtypoid=PG_GETARG_OID(1);
97+
Oidenumoid;
98+
HeapTupletup;
99+
char*name;
100+
intnbytes;
101+
102+
name=pq_getmsgtext(buf,buf->len-buf->cursor,&nbytes);
103+
104+
/* must check length to prevent Assert failure within SearchSysCache */
105+
if (strlen(name) >=NAMEDATALEN)
106+
ereport(ERROR,
107+
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
108+
errmsg("invalid input value for enum %s: \"%s\"",
109+
format_type_be(enumtypoid),
110+
name)));
111+
112+
tup=SearchSysCache(ENUMTYPOIDNAME,
113+
ObjectIdGetDatum(enumtypoid),
114+
CStringGetDatum(name),
115+
0,0);
116+
if (!HeapTupleIsValid(tup))
117+
ereport(ERROR,
118+
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
119+
errmsg("invalid input value for enum %s: \"%s\"",
120+
format_type_be(enumtypoid),
121+
name)));
122+
123+
enumoid=HeapTupleGetOid(tup);
124+
125+
ReleaseSysCache(tup);
126+
127+
pfree(name);
128+
129+
PG_RETURN_OID(enumoid);
130+
}
131+
132+
Datum
133+
enum_send(PG_FUNCTION_ARGS)
134+
{
135+
Oidenumval=PG_GETARG_OID(0);
136+
StringInfoDatabuf;
137+
HeapTupletup;
138+
Form_pg_enumen;
139+
140+
tup=SearchSysCache(ENUMOID,
141+
ObjectIdGetDatum(enumval),
142+
0,0,0);
143+
if (!HeapTupleIsValid(tup))
144+
ereport(ERROR,
145+
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
146+
errmsg("invalid internal value for enum: %u",
147+
enumval)));
148+
en= (Form_pg_enum)GETSTRUCT(tup);
149+
150+
pq_begintypsend(&buf);
151+
pq_sendtext(&buf,NameStr(en->enumlabel),strlen(NameStr(en->enumlabel)));
152+
153+
ReleaseSysCache(tup);
154+
155+
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
156+
}
157+
89158
/* Comparison functions and related */
90159

91160
Datum

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.421 2007/09/03 01:18:33 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.422 2007/09/04 16:41:42 adunstan Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200709021
56+
#defineCATALOG_VERSION_NO200709041
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.467 2007/09/03 02:30:43 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.468 2007/09/04 16:41:42 adunstan Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -4136,6 +4136,8 @@ DATA(insert OID = 3528 ( enum_firstPGNSP PGUID 12 1 0 f f f f s 1 3500 "3500"
41364136
DATA(insertOID=3529 (enum_lastPGNSPPGUID1210ffffs13500"3500"_null__null__null_enum_last-_null__null_ ));
41374137
DATA(insertOID=3530 (enum_rangePGNSPPGUID1210ffffs22277"3500 3500"_null__null__null_enum_range_bounds-_null__null_ ));
41384138
DATA(insertOID=3531 (enum_rangePGNSPPGUID1210ffffs12277"3500"_null__null__null_enum_range_all-_null__null_ ));
4139+
DATA(insertOID=3532 (enum_recvPGNSPPGUID1210fftfs23500"2275 26"_null__null__null_enum_recv-_null__null_ ));
4140+
DATA(insertOID=3533 (enum_sendPGNSPPGUID1210fftfs117"3500"_null__null__null_enum_send-_null__null_ ));
41394141

41404142
/* text search stuff */
41414143
DATA(insertOID=3610 (tsvectorinPGNSPPGUID1210fftfi13614"2275"_null__null__null_tsvectorin-_null__null_ ));

‎src/include/utils/builtins.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.301 2007/08/27 01:39:25 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.302 2007/09/04 16:41:43 adunstan Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -107,6 +107,8 @@ extern Datum domain_recv(PG_FUNCTION_ARGS);
107107
/* enum.c */
108108
externDatumenum_in(PG_FUNCTION_ARGS);
109109
externDatumenum_out(PG_FUNCTION_ARGS);
110+
externDatumenum_recv(PG_FUNCTION_ARGS);
111+
externDatumenum_send(PG_FUNCTION_ARGS);
110112
externDatumenum_lt(PG_FUNCTION_ARGS);
111113
externDatumenum_le(PG_FUNCTION_ARGS);
112114
externDatumenum_eq(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp