[HACKERS] proposal: Support Unicode host variable in ECPG - Mailing list pgsql-hackers

From Jing Wang
Subject [HACKERS] proposal: Support Unicode host variable in ECPG
Date
Msg-id CAF3+xMLcare1QrDzTxP-3JZyH5SXRkGzNUf-khSgPfmpQpkz+A@mail.gmail.com
Whole thread Raw
Responses Re: [HACKERS] proposal: Support Unicode host variable in ECPG  (Jing Wang <jingwangian@gmail.com>)
List 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.


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

pgsql-hackers by date:

Previous
From: Thomas Munro
Date:
Subject: Re: [HACKERS] Server crash due to SIGBUS(Bus Error) when trying toaccess the memory created using dsm_create().
Next
From: Michael Paquier
Date:
Subject: Re: [HACKERS] Race conditions with WAL sender PID lookups