The following bug has been logged online: Bug reference: 2956 Logged by: Toshi Harada Email address: [EMAIL PROTECTED] PostgreSQL version: 8.1.4 Operating system: CentOS4 Description: ECPG does not treat multibyte characters correctly. Details:
Hello. The problem occurs by the program that does the data of Shift_Jis in insert by using ecpg of PostgreSQL8.1.4. Shift_Jis is set to environment variable PGCLIENTENCODING and the data base encoding is EUC_JP. (Memo. Shift JIS is one of the Japanese character sets, and it is supported as client encoding in PostgreSQL. Multi byte character including 0x5c(backslash) exists in Shift_Jis. ) The following problems occur if multi byte character including 0x5c is set to the host variable, and SQL is executed. (1) Backslash (0x5c) is given after multi byte character including 0x5c. (2) The constant of "\xHexdigits" form is not correctly interpreted. Example. When 'a\x62c' is set to the host variable and SQL is executed, 'a\\x62c' is transmitted to the back end. However, it is necessary to transmit 'abc' to the back end. It seems that this bug is similar to the bug of libpq that the fixed "PostgreSQL 8.1.4". http://www.postgresql.org/docs/8.1/interactive/release-8-1-4.html Please refer to the following for the source file and DDL to reproduce the event. Regards, ---- source ---- #include <stdlib.h> #include <string.h> #include <stdlib.h> #include <stdio.h> static void PrintAndStop(char *msg) { printf("error, msg=%s\n", msg); printf("sqlcode=%ld\n", sqlca.sqlcode); exit(1); } int main(void) { EXEC SQL BEGIN DECLARE SECTION; int col1; char col2[20]; char col3[20]; int ind3; /* indicator */ char *user = "test"; char msg[1024]; char buffer[1024]; EXEC SQL END DECLARE SECTION; FILE* fp; exec sql whenever sqlerror do PrintAndStop(msg); strcpy(msg,"connect"); exec sql connect to test user :user; if ((fp = fopen("sjis_data.txt", "r")) == NULL) { perror("open error,"); exit(1); } ind3 = 0; /* not null */ strcpy(msg,"insert"); col1 = 10; strcpy(col2, "abc"); fgets(buffer, 1024, fp); buffer[strlen(buffer)-1] = '\0'; strcpy(col3, buffer); EXEC SQL INSERT INTO foo (col1, col2, col3) VALUES (:col1, :col2, :col3:ind3); strcpy(msg,"commit"); exec sql commit; strcpy(msg,"disconnect"); exec sql disconnect; fclose(fp); return 0; } ---- data file (Shift_Jis 0x955c 0x41 0x42) ---- 表AB ---- create table statement ---- create table foo (col1 int, col2 varchar, col3 varchar); ---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq