mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
Fix for inserting/copying longer multibyte strings into bpchar data
types.
This commit is contained in:
parent
ca1c7e662f
commit
dc779228f2
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.70 2000/11/21 21:16:02 petere Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.71 2000/11/26 11:35:23 ishii Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -79,7 +79,17 @@ bpcharin(PG_FUNCTION_ARGS)
|
|||||||
atttypmod = len + VARHDRSZ;
|
atttypmod = len + VARHDRSZ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#ifdef MULTIBYTE
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* truncate multi-byte string preserving multi-byte
|
||||||
|
* boundary
|
||||||
|
*/
|
||||||
|
len = pg_mbcliplen(s, atttypmod - VARHDRSZ, atttypmod - VARHDRSZ);
|
||||||
|
}
|
||||||
|
#else
|
||||||
len = atttypmod - VARHDRSZ;
|
len = atttypmod - VARHDRSZ;
|
||||||
|
#endif
|
||||||
|
|
||||||
result = (BpChar *) palloc(atttypmod);
|
result = (BpChar *) palloc(atttypmod);
|
||||||
VARATT_SIZEP(result) = atttypmod;
|
VARATT_SIZEP(result) = atttypmod;
|
||||||
@ -96,7 +106,11 @@ bpcharin(PG_FUNCTION_ARGS)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* blank pad the string if necessary */
|
/* blank pad the string if necessary */
|
||||||
|
#ifdef MULTIBYTE
|
||||||
|
for (; i < atttypmod - VARHDRSZ; i++)
|
||||||
|
#else
|
||||||
for (; i < len; i++)
|
for (; i < len; i++)
|
||||||
|
#endif
|
||||||
*r++ = ' ';
|
*r++ = ' ';
|
||||||
|
|
||||||
PG_RETURN_BPCHAR_P(result);
|
PG_RETURN_BPCHAR_P(result);
|
||||||
@ -329,7 +343,11 @@ varcharin(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
len = strlen(s) + VARHDRSZ;
|
len = strlen(s) + VARHDRSZ;
|
||||||
if (atttypmod >= (int32) VARHDRSZ && len > atttypmod)
|
if (atttypmod >= (int32) VARHDRSZ && len > atttypmod)
|
||||||
|
#ifdef MULTIBYTE
|
||||||
|
len = pg_mbcliplen(s, len - VARHDRSZ, atttypmod - VARHDRSZ) + VARHDRSZ;
|
||||||
|
#else
|
||||||
len = atttypmod; /* clip the string at max length */
|
len = atttypmod; /* clip the string at max length */
|
||||||
|
#endif
|
||||||
|
|
||||||
result = (VarChar *) palloc(len);
|
result = (VarChar *) palloc(len);
|
||||||
VARATT_SIZEP(result) = len;
|
VARATT_SIZEP(result) = len;
|
||||||
@ -383,7 +401,7 @@ varchar(PG_FUNCTION_ARGS)
|
|||||||
#ifdef MULTIBYTE
|
#ifdef MULTIBYTE
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* truncate multi-byte string in a way not to break multi-byte
|
* truncate multi-byte string preserving multi-byte
|
||||||
* boundary
|
* boundary
|
||||||
*/
|
*/
|
||||||
len = pg_mbcliplen(VARDATA(s), slen - VARHDRSZ, slen - VARHDRSZ);
|
len = pg_mbcliplen(VARDATA(s), slen - VARHDRSZ, slen - VARHDRSZ);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user