From 706bf7ca28367f9f94a8638698aa3986b170e1a9 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Wed, 10 Sep 2008 13:24:34 +0000 Subject: [PATCH] new regtest to detect encoding handling problems (draft) --- Makefile | 3 +- expected/plproxy_encoding.out | 89 +++++++++++++++++++++++++++++++++++ sql/plproxy_encoding.sql | 71 ++++++++++++++++++++++++++++ sql/plproxy_init.sql | 27 ++++++----- 4 files changed, 176 insertions(+), 14 deletions(-) create mode 100644 expected/plproxy_encoding.out create mode 100644 sql/plproxy_encoding.sql diff --git a/Makefile b/Makefile index 1679306..66b2a46 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,8 @@ DIST_FILES = Makefile src/plproxy.h src/rowstamp.h src/scanner.l src/parser.y \ # regression testing setup REGRESS = plproxy_init plproxy_test plproxy_select plproxy_many \ - plproxy_errors plproxy_clustermap plproxy_dynamic_record + plproxy_errors plproxy_clustermap plproxy_dynamic_record \ + plproxy_encoding REGRESS_OPTS = --load-language=plpgsql # load PGXS makefile diff --git a/expected/plproxy_encoding.out b/expected/plproxy_encoding.out new file mode 100644 index 0000000..4ee200d --- /dev/null +++ b/expected/plproxy_encoding.out @@ -0,0 +1,89 @@ +set client_min_messages = 'warning'; +drop database if exists test_enc_proxy; +drop database if exists test_enc_part; +create database test_enc_proxy with encoding 'utf-8'; +create database test_enc_part with encoding 'euc_jp'; +\c test_enc_proxy +create language plpgsql; +\i plproxy.sql +-- handler function +CREATE FUNCTION plproxy_call_handler () +RETURNS language_handler AS '$libdir/plproxy' LANGUAGE C; +-- language +CREATE LANGUAGE plproxy HANDLER plproxy_call_handler; +-- create cluster info functions +create schema plproxy; +create or replace function plproxy.get_cluster_version(cluster_name text) +returns integer as $$ begin return 1; end; $$ language plpgsql; +create or replace function +plproxy.get_cluster_partitions(cluster_name text) +returns setof text as $$ +begin + if cluster_name = 'testcluster' then + return next 'host=127.0.0.1 dbname=test_enc_part'; + return; + end if; + raise exception 'no such cluster: %', cluster_name; +end; $$ language plpgsql; +create or replace function plproxy.get_cluster_config(cluster_name text, out key text, out val text) +returns setof record as $$ begin return; end; $$ language plpgsql; +------------------------------------------------- +-- intialize part +------------------------------------------------- +\c test_enc_part +set client_encoding = 'utf8'; +create table intl_data ( + id serial, + val text +); +NOTICE: CREATE TABLE will create implicit sequence "intl_data_id_seq" for serial column "intl_data.id" +-- insert into intl_data (val) values ('õäöüÕÄÖÜ'); +insert into intl_data (val) values ('日本につきましては、'); +select id, val from intl_data order by 1; + id | val +----+---------------------- + 1 | 日本につきましては、 +(1 row) + +set client_encoding = 'sjis'; +select id, val from intl_data order by 1; + id | val +----+---------------------- + 1 | “ú–{‚ɂ‚«‚Ü‚µ‚ẮA +(1 row) + +set client_encoding = 'euc_jp'; +select id, val from intl_data order by 1; + id | val +----+---------------------- + 1 | ÆüËܤˤĤ­¤Þ¤·¤Æ¤Ï¡¢ +(1 row) + +\c test_enc_proxy +create function test_encoding(out id int4, out val text) +returns setof record as $$ + cluster 'testcluster'; + run on 0; + select id, val from intl_data order by 1; +$$ language plproxy; +set client_encoding = 'utf8'; +select * from test_encoding(); + id | val +----+---------------------- + 1 | 日本につきましては、 +(1 row) + +set client_encoding = 'sjis'; +select * from test_encoding(); + id | val +----+---------------------- + 1 | “ú–{‚ɂ‚«‚Ü‚µ‚ẮA +(1 row) + +set client_encoding = 'euc_jp'; +select * from test_encoding(); + id | val +----+---------------------- + 1 | ÆüËܤˤĤ­¤Þ¤·¤Æ¤Ï¡¢ +(1 row) + diff --git a/sql/plproxy_encoding.sql b/sql/plproxy_encoding.sql new file mode 100644 index 0000000..76e5cf1 --- /dev/null +++ b/sql/plproxy_encoding.sql @@ -0,0 +1,71 @@ + +set client_min_messages = 'warning'; + +drop database if exists test_enc_proxy; +drop database if exists test_enc_part; + +create database test_enc_proxy with encoding 'utf-8'; +create database test_enc_part with encoding 'euc_jp'; + +\c test_enc_proxy +create language plpgsql; + +\i plproxy.sql + +-- create cluster info functions +create schema plproxy; + +create or replace function plproxy.get_cluster_version(cluster_name text) +returns integer as $$ begin return 1; end; $$ language plpgsql; + +create or replace function +plproxy.get_cluster_partitions(cluster_name text) +returns setof text as $$ +begin + if cluster_name = 'testcluster' then + return next 'host=127.0.0.1 dbname=test_enc_part'; + return; + end if; + raise exception 'no such cluster: %', cluster_name; +end; $$ language plpgsql; + +create or replace function plproxy.get_cluster_config(cluster_name text, out key text, out val text) +returns setof record as $$ begin return; end; $$ language plpgsql; + +------------------------------------------------- +-- intialize part +------------------------------------------------- + +\c test_enc_part +set client_encoding = 'utf8'; + +create table intl_data ( + id serial, + val text +); +-- insert into intl_data (val) values ('õäöüÕÄÖÜ'); +insert into intl_data (val) values ('日本につきましては、'); + +select id, val from intl_data order by 1; + +set client_encoding = 'sjis'; +select id, val from intl_data order by 1; +set client_encoding = 'euc_jp'; +select id, val from intl_data order by 1; + +\c test_enc_proxy + +create function test_encoding(out id int4, out val text) +returns setof record as $$ + cluster 'testcluster'; + run on 0; + select id, val from intl_data order by 1; +$$ language plproxy; + +set client_encoding = 'utf8'; +select * from test_encoding(); +set client_encoding = 'sjis'; +select * from test_encoding(); +set client_encoding = 'euc_jp'; +select * from test_encoding(); + diff --git a/sql/plproxy_init.sql b/sql/plproxy_init.sql index 280eb7c..b1fa580 100644 --- a/sql/plproxy_init.sql +++ b/sql/plproxy_init.sql @@ -1,6 +1,8 @@ \set ECHO none +set client_min_messages = 'warning'; + \i plproxy.sql -- create cluster info functions @@ -36,28 +38,27 @@ end; $$ language plpgsql; -- intialize part ------------------------------------------------- drop database if exists test_part; +drop database if exists test_part0; +drop database if exists test_part1; +drop database if exists test_part2; +drop database if exists test_part3; create database test_part; +create database test_part0; +create database test_part1; +create database test_part2; +create database test_part3; + +drop database if exists test_enc_proxy; +drop database if exists test_enc_part; + \c test_part create language plpgsql; - -drop database if exists test_part0; -create database test_part0; \c test_part0 create language plpgsql; - -drop database if exists test_part1; -create database test_part1; \c test_part1 create language plpgsql; - -drop database if exists test_part2; -create database test_part2; \c test_part2 create language plpgsql; - -drop database if exists test_part3; -create database test_part3; \c test_part3 create language plpgsql; - -- 2.39.5