proposal: Support Unicode host variable in ECPG

From: Jing Wang <jingwangian(at)gmail(dot)com>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: proposal: Support Unicode host variable in ECPG
Date: 2017-06-29 00:34:14
Message-ID: CAF3+xMLcare1QrDzTxP-3JZyH5SXRkGzNUf-khSgPfmpQpkz+A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

This is a new requirement comes from some customers hoping the ECPG can
support Unicode host variable which can compatible with the same feature in
Oracle Pro*C.

https://docs.oracle.com/database/121/LNPCC/pc_05adv.htm#LNPCC3273

By using this Unicode data type, user can define Unicode variables in ECPG
application in windows platform, save the content of the Unicode host
variables into the database as database character set or get the content
from the database into the Unicode host variables.

Requirements
============
1. support utext keyword in ECPG

The utext is used to define the Unicode host variable in ECPG application
in windows platform.

2. support UVARCHAR keyword in ECPG

The UVARCHAR is used to define the Unicode vary length host variable in
ECPG application in windows platform.

3. Saving the content of the Unicode variables into the database as
database character set or getting the content from the database into the
Unicode variables.

4. Firstly can only consider the UTF8 as database character set and UTF16
as the Unicode format for host variable. A datatype convert will be done
between the UTF8 and UTF16 by ECPG.

5. Since Unicode has big-endian and little-endian format, a environment
variable is used to identify them and do the endianness convert accordingly.

Usage
============
int main() {
EXEC SQL BEGIN DECLARE SECTION;
utext employee[20] ; /* define Unicode host variable */
UVARCHAR address[50] ; /* defin a vary length Unicode host
variable */
EXEC SQL END DECLARE SECTION;

...

EXEC SQL CREATE TABLE emp (ename char(20), address varchar(50));

/* UTF8 is the database character set */
EXEC SQL INSERT INTO emp (ename) VALUES ('Mike', '1 sydney, NSW') ;

/* Database character set converted to Unicode */
EXEC SQL SELECT ename INTO :employee FROM emp ;

/* Database character set converted to Unicode */
EXEC SQL SELECT address INTO :address FROM emp ;

wprintf(L"employee name is %s\n",employee);

wprintf(L"employee address is %s\n", address.attr);

DELETE * FROM emp;

/* Unicode converted to Database character */
EXEC SQL INSERT INTO emp (ename,address) VALUES (:employee, :address);

EXEC SQL DROP TABLE emp;
EXEC SQL DISCONNECT ALL;
}

--
Regards,
Jing Wang
Fujitsu Australia

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2017-06-29 00:34:28 Re: Race conditions with WAL sender PID lookups
Previous Message Thomas Munro 2017-06-29 00:24:23 Re: Server crash due to SIGBUS(Bus Error) when trying to access the memory created using dsm_create().