gms_i18n高级包功能

This commit is contained in:
yanguotao
2024-11-07 19:18:01 +08:00
parent 4be8953465
commit 72eedf2c4b
20 changed files with 388 additions and 2 deletions

View File

@ -109,6 +109,7 @@ install:
@if test -d contrib/gms_profiler; then $(MAKE) -C contrib/gms_profiler $@; fi
@if test -d contrib/gms_xmlgen; then $(MAKE) -C contrib/gms_xmlgen $@; fi
@if test -d contrib/gms_output; then $(MAKE) -C contrib/gms_output $@; fi
@if test -d contrib/gms_i18n; then $(MAKE) -C contrib/gms_i18n $@; fi
@if test -d contrib/timescaledb; then (./contrib/timescaledb/run_to_build.sh && $(MAKE) -C contrib/timescaledb/build $@); fi
@if test -d contrib/chparser; then \
if command -v scws &> /dev/null; then \

View File

@ -71,6 +71,8 @@
./share/postgresql/extension/gms_lob.control
./share/postgresql/extension/gms_sql--1.0.sql
./share/postgresql/extension/gms_sql.control
./share/postgresql/extension/gms_i18n--1.0.sql
./share/postgresql/extension/gms_i18n.control
./share/postgresql/timezone/GB-Eire
./share/postgresql/timezone/Turkey
./share/postgresql/timezone/Kwajalein
@ -764,6 +766,7 @@
./lib/postgresql/gms_profiler.so
./lib/postgresql/gms_lob.so
./lib/postgresql/gms_sql.so
./lib/postgresql/gms_i18n.so
./include/postgresql/server/postgres_ext.h
./include/postgresql/server/pg_config_os.h
./include/postgresql/server/pgtime.h

View File

@ -135,6 +135,8 @@
./share/postgresql/extension/gms_sql.control
./share/postgresql/extension/gms_xmlgen--1.0.sql
./share/postgresql/extension/gms_xmlgen.control
./share/postgresql/extension/gms_i18n--1.0.sql
./share/postgresql/extension/gms_i18n.control
./share/postgresql/timezone/GB-Eire
./share/postgresql/timezone/Turkey
./share/postgresql/timezone/Kwajalein
@ -841,6 +843,7 @@
./lib/postgresql/gms_profiler.so
./lib/postgresql/gms_sql.so
./lib/postgresql/gms_xmlgen.so
./lib/postgresql/gms_i18n.so
./lib/libpljava.so
./lib/libpq.a
./lib/libpq.so

View File

@ -62,6 +62,8 @@
./share/postgresql/extension/gms_lob.control
./share/postgresql/extension/gms_sql--1.0.sql
./share/postgresql/extension/gms_sql.control
./share/postgresql/extension/gms_i18n--1.0.sql
./share/postgresql/extension/gms_i18n.control
./share/postgresql/timezone/GB-Eire
./share/postgresql/timezone/Turkey
./share/postgresql/timezone/Kwajalein
@ -753,6 +755,7 @@
./lib/postgresql/gms_profiler.so
./lib/postgresql/gms_lob.so
./lib/postgresql/gms_sql.so
./lib/postgresql/gms_i18n.so
./include/postgresql/server/postgres_ext.h
./include/postgresql/server/pg_config_os.h
./include/postgresql/server/pgtime.h

View File

@ -92,6 +92,8 @@
./share/postgresql/extension/gms_lob.control
./share/postgresql/extension/gms_sql--1.0.sql
./share/postgresql/extension/gms_sql.control
./share/postgresql/extension/gms_i18n--1.0.sql
./share/postgresql/extension/gms_i18n.control
./share/postgresql/timezone/GB-Eire
./share/postgresql/timezone/Turkey
./share/postgresql/timezone/Kwajalein
@ -771,6 +773,7 @@
./lib/postgresql/gms_profiler.so
./lib/postgresql/gms_lob.so
./lib/postgresql/gms_sql.so
./lib/postgresql/gms_i18n.so
./lib/libpljava.so
./lib/libpq.a
./lib/libpq.so

View File

@ -123,6 +123,8 @@
./share/postgresql/extension/gms_tcp.control
./share/postgresql/extension/gms_xmlgen--1.0.sql
./share/postgresql/extension/gms_xmlgen.control
./share/postgresql/extension/gms_i18n--1.0.sql
./share/postgresql/extension/gms_i18n.control
./share/postgresql/timezone/GB-Eire
./share/postgresql/timezone/Turkey
./share/postgresql/timezone/Kwajalein
@ -811,6 +813,7 @@
./lib/postgresql/gms_sql.so
./lib/postgresql/gms_tcp.so
./lib/postgresql/gms_xmlgen.so
./lib/postgresql/gms_i18n.so
./lib/libpljava.so
./lib/libpq.a
./lib/libpq.so

View File

@ -71,6 +71,8 @@
./share/postgresql/extension/gms_lob.control
./share/postgresql/extension/gms_sql--1.0.sql
./share/postgresql/extension/gms_sql.control
./share/postgresql/extension/gms_i18n--1.0.sql
./share/postgresql/extension/gms_i18n.control
./share/postgresql/timezone/GB-Eire
./share/postgresql/timezone/Turkey
./share/postgresql/timezone/Kwajalein
@ -763,6 +765,7 @@
./lib/postgresql/gms_profiler.so
./lib/postgresql/gms_lob.so
./lib/postgresql/gms_sql.so
./lib/postgresql/gms_i18n.so
./lib/libxgboost.so
./include/postgresql/server/postgres_ext.h
./include/postgresql/server/pg_config_os.h

View File

@ -135,6 +135,8 @@
./share/postgresql/extension/gms_sql.control
./share/postgresql/extension/gms_xmlgen--1.0.sql
./share/postgresql/extension/gms_xmlgen.control
./share/postgresql/extension/gms_i18n--1.0.sql
./share/postgresql/extension/gms_i18n.control
./share/postgresql/timezone/GB-Eire
./share/postgresql/timezone/Turkey
./share/postgresql/timezone/Kwajalein
@ -841,6 +843,7 @@
./lib/postgresql/gms_profiler.so
./lib/postgresql/gms_sql.so
./lib/postgresql/gms_xmlgen.so
./lib/postgresql/gms_i18n.so
./lib/libpljava.so
./lib/libpq.a
./lib/libpq.so

View File

@ -32,6 +32,7 @@ set(CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/gms_lob
${CMAKE_CURRENT_SOURCE_DIR}/gms_sql
${CMAKE_CURRENT_SOURCE_DIR}/gms_tcp
${CMAKE_CURRENT_SOURCE_DIR}/gms_i18n
)
if("${USE_LIBXML}" STREQUAL "ON")
@ -75,3 +76,4 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/chparser)
endif()
add_subdirectory(gms_profiler)
add_subdirectory(gms_lob)
add_subdirectory(gms_i18n)

View File

@ -59,8 +59,10 @@ SUBDIRS = \
ndpplugin \
gms_profiler \
gms_output \
gms_stats \
gms_lob \
gms_sql
gms_sql \
gms_i18n
ifeq ($(with_openssl),yes)
SUBDIRS += sslinfo

View File

@ -0,0 +1,21 @@
#This is the main CMAKE for build all gms_i18n.
# gms_i18n
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} TGT_gms_i18n_SRC)
set(TGT_gms_i18n_INC
${PROJECT_OPENGS_DIR}/contrib/gms_i18n
${PROJECT_OPENGS_DIR}/contrib
)
set(gms_i18n_DEF_OPTIONS ${MACRO_OPTIONS})
set(gms_i18n_COMPILE_OPTIONS ${OPTIMIZE_OPTIONS} ${OS_OPTIONS} ${PROTECT_OPTIONS} ${WARNING_OPTIONS} ${LIB_SECURE_OPTIONS} ${CHECK_OPTIONS})
set(gms_i18n_LINK_OPTIONS ${LIB_LINK_OPTIONS})
add_shared_libtarget(gms_i18n TGT_gms_i18n_SRC TGT_gms_i18n_INC "${gms_i18n_DEF_OPTIONS}" "${gms_i18n_COMPILE_OPTIONS}" "${gms_i18n_LINK_OPTIONS}")
set_target_properties(gms_i18n PROPERTIES PREFIX "")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gms_i18n.control
DESTINATION share/postgresql/extension/
)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gms_i18n--1.0.sql
DESTINATION share/postgresql/extension/
)
install(TARGETS gms_i18n DESTINATION lib/postgresql)

26
contrib/gms_i18n/Makefile Normal file
View File

@ -0,0 +1,26 @@
# contrib/gms_i18n/Makefile
MODULE_big = gms_i18n
OBJS = gms_i18n.o
EXTENSION = gms_i18n
DATA = gms_i18n--1.0.sql
exclude_option = -fPIE
override CPPFLAGS := $(filter-out $(exclude_option),$(CPPFLAGS))
REGRESS = gms_i18n
ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir = contrib/gms_i18n
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
regress_home = $(top_builddir)/src/test/regress
REGRESS_OPTS = -c 0 -d 1 -r 1 -p 25632 --single_node -w --keep_last_data=false \
--regconf=$(regress_home)/regress.conf \
--temp-config=$(regress_home)/make_fastcheck_postgresql.conf
include $(top_srcdir)/contrib/contrib-global.mk
endif

View File

@ -0,0 +1 @@
The openGauss regression needs this file to run.

View File

@ -0,0 +1,145 @@
create extension gms_i18n;
create schema gms_i18n_test;
set search_path=gms_i18n_test;
-- test gms_i18n.raw_to_char
select gms_i18n.raw_to_char(hextoraw('616263646566C2AA'), 'utf8');
raw_to_char
-------------
abcdefª
(1 row)
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'), 'utf8');
raw_to_char
-------------
测试
(1 row)
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'), '');
raw_to_char
-------------
测试
(1 row)
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'));
raw_to_char
-------------
测试
(1 row)
select gms_i18n.raw_to_char('', 'utf8');
raw_to_char
-------------
(1 row)
select gms_i18n.raw_to_char('', '');
raw_to_char
-------------
(1 row)
select gms_i18n.raw_to_char('');
raw_to_char
-------------
(1 row)
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'), 'unvalid_charset');
ERROR: invalid source encoding name "unvalid_charset"
CONTEXT: referenced column: raw_to_char
select gms_i18n.raw_to_char(hextoraw('b2e2cad4'), 'gbk');
raw_to_char
-------------
测试
(1 row)
select gms_i18n.raw_to_char(hextoraw('b2e2cad4'), 'euc_cn');
raw_to_char
-------------
测试
(1 row)
select gms_i18n.raw_to_char(hextoraw('b4fab8d5'), 'big5');
raw_to_char
-------------
測試
(1 row)
select gms_i18n.raw_to_char();
ERROR: function gms_i18n.raw_to_char() does not exist
LINE 1: select gms_i18n.raw_to_char();
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
CONTEXT: referenced column: raw_to_char
-- test gms_i18n.string_to_raw
select gms_i18n.string_to_raw('abcdefª', 'utf8');
string_to_raw
------------------
616263646566C2AA
(1 row)
select gms_i18n.string_to_raw('测试', 'utf8');
string_to_raw
---------------
E6B58BE8AF95
(1 row)
select gms_i18n.string_to_raw('测试', '');
string_to_raw
---------------
E6B58BE8AF95
(1 row)
select gms_i18n.string_to_raw('测试');
string_to_raw
---------------
E6B58BE8AF95
(1 row)
select gms_i18n.string_to_raw('', 'utf8');
string_to_raw
---------------
(1 row)
select gms_i18n.string_to_raw('', '');
string_to_raw
---------------
(1 row)
select gms_i18n.string_to_raw('');
string_to_raw
---------------
(1 row)
select gms_i18n.string_to_raw('测试', 'unvalid_charset');
ERROR: invalid destination encoding name "unvalid_charset"
CONTEXT: referenced column: string_to_raw
select gms_i18n.string_to_raw('测试', 'gbk');
string_to_raw
---------------
B2E2CAD4
(1 row)
select gms_i18n.string_to_raw('测试', 'euc_cn');
string_to_raw
---------------
B2E2CAD4
(1 row)
select gms_i18n.string_to_raw('測試', 'big5');
string_to_raw
---------------
B4FAB8D5
(1 row)
select gms_i18n.string_to_raw();
ERROR: function gms_i18n.string_to_raw() does not exist
LINE 1: select gms_i18n.string_to_raw();
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
CONTEXT: referenced column: string_to_raw
reset search_path;
drop schema gms_i18n_test cascade;

View File

@ -0,0 +1,17 @@
/* contrib/gms_i18n/gms_i18n--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION gms_i18n" to load this file. \quit
CREATE SCHEMA gms_i18n;
GRANT USAGE ON SCHEMA gms_i18n TO PUBLIC;
CREATE OR REPLACE FUNCTION gms_i18n.raw_to_char(IN rawdata raw, IN charset varchar2 DEFAULT NULL)
RETURNS varchar2
AS 'MODULE_PATHNAME', 'gms_i18n_raw_to_char'
LANGUAGE C IMMUTABLE;
CREATE OR REPLACE FUNCTION gms_i18n.string_to_raw(IN strdata varchar2, IN charset varchar2 DEFAULT NULL)
RETURNS raw
AS 'MODULE_PATHNAME', 'gms_i18n_string_to_raw'
LANGUAGE C IMMUTABLE;

View File

@ -0,0 +1,5 @@
# gms_i18n extension
comment = 'collection of i18n for PL/SQL applications'
default_version = '1.0'
module_pathname = '$libdir/gms_i18n'
relocatable = true

View File

@ -0,0 +1,91 @@
/*
* Copyright (c) 2024 Huawei Technologies Co.,Ltd.
*
* openGauss is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* --------------------------------------------------------------------------------------
*
* gms_i18n.cpp
* gms_i18n package
*
*
* IDENTIFICATION
* contrib/gms_i18n/gms_i18n.cpp
*
* --------------------------------------------------------------------------------------
*/
#include "postgres.h"
#include "utils/builtins.h"
#include "gms_i18n.h"
PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(gms_i18n_raw_to_char);
PG_FUNCTION_INFO_V1(gms_i18n_string_to_raw);
Datum gms_i18n_raw_to_char(PG_FUNCTION_ARGS)
{
Datum raw = PG_GETARG_DATUM(0);
Datum src_encoding_name;
Datum dest_encoding_name;
Datum result;
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
dest_encoding_name = DirectFunctionCall1(namein, CStringGetDatum(u_sess->mb_cxt.DatabaseEncoding->name));
if (PG_ARGISNULL(1)) {
src_encoding_name = dest_encoding_name;
} else {
src_encoding_name = DirectFunctionCall1(text_name, PG_GETARG_DATUM(1));
}
/*
* pg_convert expects a bytea as its first argument. We're passing it a
* raw argument here, relying on the fact that they are both in fact
* varlena types, and thus structurally identical.
*/
result = DirectFunctionCall3(pg_convert, raw, src_encoding_name, dest_encoding_name);
PG_RETURN_DATUM(result);
}
Datum gms_i18n_string_to_raw(PG_FUNCTION_ARGS)
{
Datum string = PG_GETARG_DATUM(0);
Datum dest_encoding_name;
Datum src_encoding_name;
Datum result;
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
src_encoding_name = DirectFunctionCall1(namein, CStringGetDatum(u_sess->mb_cxt.DatabaseEncoding->name));
if (PG_ARGISNULL(1)) {
dest_encoding_name = src_encoding_name;
} else {
dest_encoding_name = DirectFunctionCall1(text_name, PG_GETARG_DATUM(1));
}
/*
* pg_convert expects a bytea as its first argument. We're passing it a
* varchar2 argument here, relying on the fact that they are both in fact
* varlena types, and thus structurally identical.
*/
result = DirectFunctionCall3(pg_convert, string, src_encoding_name, dest_encoding_name);
PG_RETURN_DATUM(result);
}

View File

@ -0,0 +1,19 @@
/*---------------------------------------------------------------------------------------*
* gms_i18n.h
*
* Definition about gms_i18n package.
*
* IDENTIFICATION
* contrib/gms_i18n/gms_i18n.h
*
* ---------------------------------------------------------------------------------------
*/
#ifndef __GMS_I18N__
#define __GMS_I18N__
#include "postgres.h"
extern "C" Datum gms_i18n_raw_to_char(PG_FUNCTION_ARGS);
extern "C" Datum gms_i18n_string_to_raw(PG_FUNCTION_ARGS);
#endif // __GMS_I18N__

View File

@ -0,0 +1,34 @@
create extension gms_i18n;
create schema gms_i18n_test;
set search_path=gms_i18n_test;
-- test gms_i18n.raw_to_char
select gms_i18n.raw_to_char(hextoraw('616263646566C2AA'), 'utf8');
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'), 'utf8');
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'), '');
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'));
select gms_i18n.raw_to_char('', 'utf8');
select gms_i18n.raw_to_char('', '');
select gms_i18n.raw_to_char('');
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'), 'unvalid_charset');
select gms_i18n.raw_to_char(hextoraw('b2e2cad4'), 'gbk');
select gms_i18n.raw_to_char(hextoraw('b2e2cad4'), 'euc_cn');
select gms_i18n.raw_to_char(hextoraw('b4fab8d5'), 'big5');
select gms_i18n.raw_to_char();
-- test gms_i18n.string_to_raw
select gms_i18n.string_to_raw('abcdefª', 'utf8');
select gms_i18n.string_to_raw('测试', 'utf8');
select gms_i18n.string_to_raw('测试', '');
select gms_i18n.string_to_raw('测试');
select gms_i18n.string_to_raw('', 'utf8');
select gms_i18n.string_to_raw('', '');
select gms_i18n.string_to_raw('');
select gms_i18n.string_to_raw('测试', 'unvalid_charset');
select gms_i18n.string_to_raw('测试', 'gbk');
select gms_i18n.string_to_raw('测试', 'euc_cn');
select gms_i18n.string_to_raw('測試', 'big5');
select gms_i18n.string_to_raw();
reset search_path;
drop schema gms_i18n_test cascade;

View File

@ -101,7 +101,8 @@ static void DropExtensionInListIsSupported(List* objname)
"gms_profiler",
"gms_xmlgen",
"gms_lob",
"gms_sql"
"gms_sql",
"gms_i18n"
#endif
};
int len = lengthof(supportList);