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

Commitdc77922

Browse files
committed
Fix for inserting/copying longer multibyte strings into bpchar data
types.
1 parentca1c7e6 commitdc77922

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.70 2000/11/21 21:16:02 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.71 2000/11/26 11:35:23 ishii Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -79,7 +79,17 @@ bpcharin(PG_FUNCTION_ARGS)
7979
atttypmod=len+VARHDRSZ;
8080
}
8181
else
82+
#ifdefMULTIBYTE
83+
{
84+
/*
85+
* truncate multi-byte string preserving multi-byte
86+
* boundary
87+
*/
88+
len=pg_mbcliplen(s,atttypmod-VARHDRSZ,atttypmod-VARHDRSZ);
89+
}
90+
#else
8291
len=atttypmod-VARHDRSZ;
92+
#endif
8393

8494
result= (BpChar*)palloc(atttypmod);
8595
VARATT_SIZEP(result)=atttypmod;
@@ -96,7 +106,11 @@ bpcharin(PG_FUNCTION_ARGS)
96106
#endif
97107

98108
/* blank pad the string if necessary */
109+
#ifdefMULTIBYTE
110+
for (;i<atttypmod-VARHDRSZ;i++)
111+
#else
99112
for (;i<len;i++)
113+
#endif
100114
*r++=' ';
101115

102116
PG_RETURN_BPCHAR_P(result);
@@ -329,7 +343,11 @@ varcharin(PG_FUNCTION_ARGS)
329343

330344
len=strlen(s)+VARHDRSZ;
331345
if (atttypmod >= (int32)VARHDRSZ&&len>atttypmod)
346+
#ifdefMULTIBYTE
347+
len=pg_mbcliplen(s,len-VARHDRSZ,atttypmod-VARHDRSZ)+VARHDRSZ;
348+
#else
332349
len=atttypmod;/* clip the string at max length */
350+
#endif
333351

334352
result= (VarChar*)palloc(len);
335353
VARATT_SIZEP(result)=len;
@@ -383,7 +401,7 @@ varchar(PG_FUNCTION_ARGS)
383401
#ifdefMULTIBYTE
384402

385403
/*
386-
* truncate multi-byte stringin a way not to break multi-byte
404+
* truncate multi-byte stringpreserving multi-byte
387405
* boundary
388406
*/
389407
len=pg_mbcliplen(VARDATA(s),slen-VARHDRSZ,slen-VARHDRSZ);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp