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

Commitd78397d

Browse files
committed
Change typreceive function API so that receive functions get the same
optional arguments as text input functions, ie, typioparam OID andatttypmod. Make all the datatypes that use typmod enforce it the sameway in typreceive as they do in typinput. This fixes a problem withfailure to enforce length restrictions during COPY FROM BINARY.
1 parent2e33069 commitd78397d

File tree

18 files changed

+333
-144
lines changed

18 files changed

+333
-144
lines changed

‎doc/src/sgml/ref/create_type.sgml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.55 2005/05/01 18:56:17 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.56 2005/07/10 21:13:57 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -125,12 +125,13 @@ CREATE TYPE <replaceable class="parameter">name</replaceable> (
125125
function should perform adequate checking to ensure that the value is
126126
valid.
127127
The receive function may be declared as taking one argument of type
128-
<type>internal</type>, or two arguments of types <type>internal</type>
129-
and <type>oid</type>. It must return a value of the data type itself.
130-
(The first argument is a pointer to a <type>StringInfo</type> buffer
131-
holding the received byte string; the optional second argument is the
132-
element type OID in case this is an array type, or the type's own OID for a
133-
composite type.) Similarly, the optional
128+
<type>internal</type>, or as taking three arguments of types
129+
<type>internal</type>, <type>oid</type>, <type>integer</type>.
130+
The first argument is a pointer to a <type>StringInfo</type> buffer
131+
holding the received byte string; the optional arguments are the
132+
same as for the text input function.
133+
The receive function must return a value of the data type itself.
134+
Similarly, the optional
134135
<replaceable class="parameter">send_function</replaceable> converts
135136
from the internal representation to the external binary representation.
136137
If this function is not supplied, the type cannot participate in binary

‎src/backend/commands/copy.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.246 2005/06/28 05:08:53 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.247 2005/07/10 21:13:58 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -144,7 +144,7 @@ static char *CopyReadAttributeCSV(const char *delim, const char *null_print,
144144
char*quote,char*escape,
145145
CopyReadResult*result,bool*isnull);
146146
staticDatumCopyReadBinaryAttribute(intcolumn_no,FmgrInfo*flinfo,
147-
Oidtypioparam,bool*isnull);
147+
Oidtypioparam,int32typmod,bool*isnull);
148148
staticvoidCopyAttributeOut(char*string,char*delim);
149149
staticvoidCopyAttributeOutCSV(char*string,char*delim,char*quote,
150150
char*escape,boolforce_quote);
@@ -1843,8 +1843,9 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
18431843
copy_attname="oid";
18441844
loaded_oid=
18451845
DatumGetObjectId(CopyReadBinaryAttribute(0,
1846-
&oid_in_function,
1847-
oid_typioparam,
1846+
&oid_in_function,
1847+
oid_typioparam,
1848+
-1,
18481849
&isnull));
18491850
if (isnull||loaded_oid==InvalidOid)
18501851
ereport(ERROR,
@@ -1864,6 +1865,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
18641865
values[m]=CopyReadBinaryAttribute(i,
18651866
&in_functions[m],
18661867
typioparams[m],
1868+
attr[m]->atttypmod,
18671869
&isnull);
18681870
nulls[m]=isnull ?'n' :' ';
18691871
copy_attname=NULL;
@@ -2556,7 +2558,8 @@ CopyReadAttributeCSV(const char *delim, const char *null_print, char *quote,
25562558
* Read a binary attribute
25572559
*/
25582560
staticDatum
2559-
CopyReadBinaryAttribute(intcolumn_no,FmgrInfo*flinfo,Oidtypioparam,
2561+
CopyReadBinaryAttribute(intcolumn_no,FmgrInfo*flinfo,
2562+
Oidtypioparam,int32typmod,
25602563
bool*isnull)
25612564
{
25622565
int32fld_size;
@@ -2594,9 +2597,10 @@ CopyReadBinaryAttribute(int column_no, FmgrInfo *flinfo, Oid typioparam,
25942597
attribute_buf.data[fld_size]='\0';
25952598

25962599
/* Call the column type's binary input converter */
2597-
result=FunctionCall2(flinfo,
2600+
result=FunctionCall3(flinfo,
25982601
PointerGetDatum(&attribute_buf),
2599-
ObjectIdGetDatum(typioparam));
2602+
ObjectIdGetDatum(typioparam),
2603+
Int32GetDatum(typmod));
26002604

26012605
/* Trouble if it didn't eat the whole buffer */
26022606
if (attribute_buf.cursor!=attribute_buf.len)

‎src/backend/commands/typecmds.c

Lines changed: 6 additions & 5 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.74 2005/07/07 20:39:58 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.75 2005/07/10 21:13:58 tgl Exp $
1212
*
1313
* DESCRIPTION
1414
* The "DefineFoo" routines take the parse tree and pick out the
@@ -859,7 +859,7 @@ findTypeInputFunction(List *procname, Oid typeOid)
859859

860860
/*
861861
* Input functions can take a single argument of type CSTRING, or
862-
* three arguments (string,element OID, typmod).
862+
* three arguments (string,typioparam OID, typmod).
863863
*
864864
* For backwards compatibility we allow OPAQUE in place of CSTRING; if we
865865
* see this, we issue a warning and fix up the pg_proc entry.
@@ -973,12 +973,12 @@ findTypeOutputFunction(List *procname, Oid typeOid)
973973
staticOid
974974
findTypeReceiveFunction(List*procname,OidtypeOid)
975975
{
976-
OidargList[2];
976+
OidargList[3];
977977
OidprocOid;
978978

979979
/*
980980
* Receive functions can take a single argument of type INTERNAL, or
981-
*two arguments (internal,oid).
981+
*three arguments (internal,typioparam OID, typmod).
982982
*/
983983
argList[0]=INTERNALOID;
984984

@@ -987,8 +987,9 @@ findTypeReceiveFunction(List *procname, Oid typeOid)
987987
returnprocOid;
988988

989989
argList[1]=OIDOID;
990+
argList[2]=INT4OID;
990991

991-
procOid=LookupFuncName(procname,2,argList, true);
992+
procOid=LookupFuncName(procname,3,argList, true);
992993
if (OidIsValid(procOid))
993994
returnprocOid;
994995

‎src/backend/tcop/fastpath.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.80 2005/05/01 18:56:18 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.81 2005/07/10 21:13:58 tgl Exp $
1212
*
1313
* NOTES
1414
* This cruft is the server side of PQfn.
@@ -493,9 +493,10 @@ parse_fcall_arguments(StringInfo msgBuf, struct fp_info * fip,
493493
/* Call the argument type's binary input converter */
494494
getTypeBinaryInputInfo(fip->argtypes[i],&typreceive,&typioparam);
495495

496-
fcinfo->arg[i]=OidFunctionCall2(typreceive,
496+
fcinfo->arg[i]=OidFunctionCall3(typreceive,
497497
PointerGetDatum(&abuf),
498-
ObjectIdGetDatum(typioparam));
498+
ObjectIdGetDatum(typioparam),
499+
Int32GetDatum(-1));
499500

500501
/* Trouble if it didn't eat the whole buffer */
501502
if (abuf.cursor!=abuf.len)
@@ -579,9 +580,10 @@ parse_fcall_arguments_20(StringInfo msgBuf, struct fp_info * fip,
579580
/* Call the argument type's binary input converter */
580581
getTypeBinaryInputInfo(fip->argtypes[i],&typreceive,&typioparam);
581582

582-
fcinfo->arg[i]=OidFunctionCall2(typreceive,
583+
fcinfo->arg[i]=OidFunctionCall3(typreceive,
583584
PointerGetDatum(&abuf),
584-
ObjectIdGetDatum(typioparam));
585+
ObjectIdGetDatum(typioparam),
586+
Int32GetDatum(-1));
585587

586588
/* Trouble if it didn't eat the whole buffer */
587589
if (abuf.cursor!=abuf.len)

‎src/backend/tcop/postgres.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.452 2005/07/04 04:51:49 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.453 2005/07/10 21:13:58 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -1571,9 +1571,10 @@ exec_bind_message(StringInfo input_message)
15711571
getTypeBinaryInputInfo(ptype,&typreceive,&typioparam);
15721572

15731573
params[i].value=
1574-
OidFunctionCall2(typreceive,
1574+
OidFunctionCall3(typreceive,
15751575
PointerGetDatum(&pbuf),
1576-
ObjectIdGetDatum(typioparam));
1576+
ObjectIdGetDatum(typioparam),
1577+
Int32GetDatum(-1));
15771578

15781579
/* Trouble if it didn't eat the whole buffer */
15791580
if (pbuf.cursor!=pbuf.len)

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.120 2005/05/01 18:56:18 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.121 2005/07/10 21:13:58 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -81,7 +81,7 @@ static Datum *ReadArrayStr(char *arrayStr, const char *origStr,
8181
inttyplen,booltypbyval,chartypalign,
8282
int*nbytes);
8383
staticDatum*ReadArrayBinary(StringInfobuf,intnitems,
84-
FmgrInfo*receiveproc,Oidtypioparam,
84+
FmgrInfo*receiveproc,Oidtypioparam,int32typmod,
8585
inttyplen,booltypbyval,chartypalign,
8686
int*nbytes);
8787
staticvoidCopyArrayEls(char*p,Datum*values,intnitems,
@@ -1121,6 +1121,8 @@ array_recv(PG_FUNCTION_ARGS)
11211121
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
11221122
Oidspec_element_type=PG_GETARG_OID(1);/* type of an array
11231123
* element */
1124+
int32typmod=PG_GETARG_INT32(2);/* typmod for array
1125+
* elements */
11241126
Oidelement_type;
11251127
inttyplen;
11261128
booltypbyval;
@@ -1215,7 +1217,8 @@ array_recv(PG_FUNCTION_ARGS)
12151217
typalign=my_extra->typalign;
12161218
typioparam=my_extra->typioparam;
12171219

1218-
dataPtr=ReadArrayBinary(buf,nitems,&my_extra->proc,typioparam,
1220+
dataPtr=ReadArrayBinary(buf,nitems,&my_extra->proc,
1221+
typioparam,typmod,
12191222
typlen,typbyval,typalign,
12201223
&nbytes);
12211224
nbytes+=ARR_OVERHEAD(ndim);
@@ -1249,6 +1252,7 @@ ReadArrayBinary(StringInfo buf,
12491252
intnitems,
12501253
FmgrInfo*receiveproc,
12511254
Oidtypioparam,
1255+
int32typmod,
12521256
inttyplen,
12531257
booltypbyval,
12541258
chartypalign,
@@ -1289,9 +1293,10 @@ ReadArrayBinary(StringInfo buf,
12891293
buf->data[buf->cursor]='\0';
12901294

12911295
/* Now call the element's receiveproc */
1292-
values[i]=FunctionCall2(receiveproc,
1296+
values[i]=FunctionCall3(receiveproc,
12931297
PointerGetDatum(&elem_buf),
1294-
ObjectIdGetDatum(typioparam));
1298+
ObjectIdGetDatum(typioparam),
1299+
Int32GetDatum(typmod));
12951300

12961301
/* Trouble if it didn't eat the whole buffer */
12971302
if (elem_buf.cursor!=itemlen)

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.110 2005/06/15 00:34:08 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.111 2005/07/10 21:13:59 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -982,12 +982,21 @@ Datum
982982
time_recv(PG_FUNCTION_ARGS)
983983
{
984984
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
985+
#ifdefNOT_USED
986+
Oidtypelem=PG_GETARG_OID(1);
987+
#endif
988+
int32typmod=PG_GETARG_INT32(2);
989+
TimeADTresult;
985990

986991
#ifdefHAVE_INT64_TIMESTAMP
987-
PG_RETURN_TIMEADT((TimeADT)pq_getmsgint64(buf));
992+
result=pq_getmsgint64(buf);
988993
#else
989-
PG_RETURN_TIMEADT((TimeADT)pq_getmsgfloat8(buf));
994+
result=pq_getmsgfloat8(buf);
990995
#endif
996+
997+
AdjustTimeForTypmod(&result,typmod);
998+
999+
PG_RETURN_TIMEADT(result);
9911000
}
9921001

9931002
/*
@@ -1774,18 +1783,24 @@ Datum
17741783
timetz_recv(PG_FUNCTION_ARGS)
17751784
{
17761785
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
1777-
TimeTzADT*time;
1786+
#ifdefNOT_USED
1787+
Oidtypelem=PG_GETARG_OID(1);
1788+
#endif
1789+
int32typmod=PG_GETARG_INT32(2);
1790+
TimeTzADT*result;
17781791

1779-
time= (TimeTzADT*)palloc(sizeof(TimeTzADT));
1792+
result= (TimeTzADT*)palloc(sizeof(TimeTzADT));
17801793

17811794
#ifdefHAVE_INT64_TIMESTAMP
1782-
time->time=pq_getmsgint64(buf);
1795+
result->time=pq_getmsgint64(buf);
17831796
#else
1784-
time->time=pq_getmsgfloat8(buf);
1797+
result->time=pq_getmsgfloat8(buf);
17851798
#endif
1786-
time->zone=pq_getmsgint(buf,sizeof(time->zone));
1799+
result->zone=pq_getmsgint(buf,sizeof(result->zone));
1800+
1801+
AdjustTimeForTypmod(&(result->time),typmod);
17871802

1788-
PG_RETURN_TIMETZADT_P(time);
1803+
PG_RETURN_TIMETZADT_P(result);
17891804
}
17901805

17911806
/*

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 1998-2005, PostgreSQL Global Development Group
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.84 2005/06/04 14:12:50 momjian Exp $
17+
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.85 2005/07/10 21:13:59 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -383,6 +383,10 @@ Datum
383383
numeric_recv(PG_FUNCTION_ARGS)
384384
{
385385
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
386+
#ifdefNOT_USED
387+
Oidtypelem=PG_GETARG_OID(1);
388+
#endif
389+
int32typmod=PG_GETARG_INT32(2);
386390
NumericVarvalue;
387391
Numericres;
388392
intlen,
@@ -419,6 +423,8 @@ numeric_recv(PG_FUNCTION_ARGS)
419423
value.digits[i]=d;
420424
}
421425

426+
apply_typmod(&value,typmod);
427+
422428
res=make_result(&value);
423429
free_var(&value);
424430

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/rowtypes.c,v 1.11 2005/05/01 18:56:18 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/rowtypes.c,v 1.12 2005/07/10 21:13:59 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -54,6 +54,9 @@ record_in(PG_FUNCTION_ARGS)
5454
{
5555
char*string=PG_GETARG_CSTRING(0);
5656
OidtupType=PG_GETARG_OID(1);
57+
#ifdefNOT_USED
58+
int32typmod=PG_GETARG_INT32(2);
59+
#endif
5760
HeapTupleHeaderresult;
5861
int32tupTypmod;
5962
TupleDesctupdesc;
@@ -417,6 +420,9 @@ record_recv(PG_FUNCTION_ARGS)
417420
{
418421
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
419422
OidtupType=PG_GETARG_OID(1);
423+
#ifdefNOT_USED
424+
int32typmod=PG_GETARG_INT32(2);
425+
#endif
420426
HeapTupleHeaderresult;
421427
int32tupTypmod;
422428
TupleDesctupdesc;
@@ -560,10 +566,10 @@ record_recv(PG_FUNCTION_ARGS)
560566
column_info->column_type=column_type;
561567
}
562568

563-
values[i]=FunctionCall2(&column_info->proc,
569+
values[i]=FunctionCall3(&column_info->proc,
564570
PointerGetDatum(&item_buf),
565-
ObjectIdGetDatum(column_info->typioparam));
566-
571+
ObjectIdGetDatum(column_info->typioparam),
572+
Int32GetDatum(tupdesc->attrs[i]->atttypmod));
567573
nulls[i]=' ';
568574

569575
/* Trouble if it didn't eat the whole buffer */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp