B库下MOT表char类型判断长度修改为字符长度
This commit is contained in:
@ -29,6 +29,7 @@
|
||||
#include "column.h"
|
||||
#include "utilities.h"
|
||||
#include "mot_error.h"
|
||||
#include "knl/knl_session.h"
|
||||
|
||||
extern uint16_t MOTTimestampToStr(uintptr_t src, char* destBuf, size_t len);
|
||||
extern uint16_t MOTTimestampTzToStr(uintptr_t src, char* destBuf, size_t len);
|
||||
@ -893,11 +894,16 @@ uint16_t ColumnDECIMAL::PrintValue(uint8_t* data, char* destBuf, size_t len, boo
|
||||
|
||||
bool ColumnVARCHAR::Pack(uint8_t* dest, uintptr_t src, size_t len)
|
||||
{
|
||||
if (len > (m_size - 4)) {
|
||||
size_t tlen = len;
|
||||
if (u_sess->attr.attr_sql.sql_compatibility == B_FORMAT) {
|
||||
/* use char length instead byte length */
|
||||
tlen = pg_mbstrlen_with_len((char*)src, (int) len);
|
||||
}
|
||||
if (tlen > (m_size - 4)) {
|
||||
return false;
|
||||
}
|
||||
*((uint32_t*)(dest + m_offset)) = len;
|
||||
errno_t erc = memcpy_s(dest + m_offset + 4, m_size - 4, (void*)src, len);
|
||||
errno_t erc = memcpy_s(dest + m_offset + 4, len > m_size - 4 ? len : m_size - 4, (void*)src, len);
|
||||
securec_check(erc, "\0", "\0");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
#include "catalog_column_types.h"
|
||||
#include "utils/elog.h"
|
||||
#include "securec.h"
|
||||
#include "postgres.h"
|
||||
|
||||
#define MOT_MAXDATELEN 128
|
||||
|
||||
|
||||
@ -109,3 +109,11 @@ SELECT '' AS four, * FROM VARCHAR_TBL ORDER BY f1;
|
||||
(4 rows)
|
||||
|
||||
DROP FOREIGN TABLE VARCHAR_TBL;
|
||||
CREATE DATABASE db_varchar DBCOMPATIBILITY 'B' ENCODING 'UTF8';
|
||||
\c db_varchar
|
||||
create Foreign table t_foreign1 (c1 int not null, c2 numeric, c3 char(30));
|
||||
insert into t_foreign1 values (1, 50, '嘿嘿');
|
||||
insert into t_foreign1 values (1, 50, '嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿');
|
||||
insert into t_foreign1 values (1, 50, '嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿');
|
||||
\c postgres
|
||||
DROP DATABASE db_varchar;
|
||||
|
||||
@ -66,3 +66,13 @@ INSERT INTO VARCHAR_TBL (f1) VALUES ('abcd ');
|
||||
|
||||
SELECT '' AS four, * FROM VARCHAR_TBL ORDER BY f1;
|
||||
DROP FOREIGN TABLE VARCHAR_TBL;
|
||||
|
||||
CREATE DATABASE db_varchar DBCOMPATIBILITY 'B' ENCODING 'UTF8';
|
||||
\c db_varchar
|
||||
create Foreign table t_foreign1 (c1 int not null, c2 numeric, c3 char(30));
|
||||
insert into t_foreign1 values (1, 50, '嘿嘿');
|
||||
insert into t_foreign1 values (1, 50, '嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿');
|
||||
insert into t_foreign1 values (1, 50, '嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿');
|
||||
\c postgres
|
||||
DROP DATABASE db_varchar;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user