Debian Codegraph @

src/pl/tcl/sql/pltcl_unicode.sql

raw
1 --
2 -- Unicode handling
3 --
4 -- This test case would fail if the database encoding is EUC_CN, EUC_JP,
5 -- EUC_KR, or EUC_TW, for lack of any equivalent to U+00A0 (no-break space) in
6 -- those encodings. However, testing with plain ASCII data would be rather
7 -- useless, so we must live with that.
8 --
9 SELECT getdatabaseencoding() IN ('EUC_CN', 'EUC_JP', 'EUC_KR', 'EUC_TW')
10 AS skip_test \gset
11 \if :skip_test
12 \quit
13 \endif
14
15 SET client_encoding TO UTF8;
16
17 CREATE TABLE unicode_test (
18 testvalue text NOT NULL
19 );
20
21 CREATE FUNCTION unicode_return() RETURNS text AS $$
22 return "\xA0"
23 $$ LANGUAGE pltcl;
24
25 CREATE FUNCTION unicode_trigger() RETURNS trigger AS $$
26 set NEW(testvalue) "\xA0"
27 return [array get NEW]
28 $$ LANGUAGE pltcl;
29
30 CREATE TRIGGER unicode_test_bi BEFORE INSERT ON unicode_test
31 FOR EACH ROW EXECUTE PROCEDURE unicode_trigger();
32
33 CREATE FUNCTION unicode_plan1() RETURNS text AS $$
34 set plan [ spi_prepare {SELECT $1 AS testvalue} [ list "text" ] ]
35 spi_execp $plan [ list "\xA0" ]
36 return $testvalue
37 $$ LANGUAGE pltcl;
38
39
40 SELECT unicode_return();
41 INSERT INTO unicode_test (testvalue) VALUES ('test');
42 SELECT * FROM unicode_test;
43 SELECT unicode_plan1();