COPY-LOB database CLOB to LONGCHAR code page conversion is wrong, the code page of the LONGCHAR after the copy is in the original CLOBDB code page instead of the -cpinternal of the session
When copying CLOB data from the database to LONGCHAR variables the documentation states that the code page conversion happens:
"From the database's defined code page to -cpinternal or the fixed code page".
The database's defined code page to -cpinternal or the fixed code page does not happen when a CLOB is copied to a LONGCHAR
The code page of the LONGCHAR after the copy remains in the original Database CLOB code page. For example:
- The database includes a table (table1) with both a UTF-8 CLOBCP (clob1) and a 1252 CLOBDB (clob2) field (see attached CopyLob.zip).
- A session is started to connect to the database with -cpinternal UTF-8:
$ prowin.exe -db sports2000 -1 -cpinternal UTF-8
- The UTF-8 client session runs the following code against the database:
DEFINE VARIABLE cltest1 AS LONGCHAR.
DEFINE VARIABLE cltest2 AS LONGCHAR.
DEFINE VARIABLE cltest3 AS LONGCHAR.
DEFINE VARIABLE c1 AS CHARACTER NO-UNDO.
DEFINE VARIABLE c2 AS CHARACTER NO-UNDO.
DEFINE VARIABLE c3 AS CHARACTER NO-UNDO.
DEFINE VARIABLE m1 AS MEMPTR NO-UNDO.
set-size(m1) = 10.
FIND FIRST table1.
COPY-LOB table1.clob1 TO clTest1.
c1 = clTest1.
COPY-LOB table1.clob2 TO clTest2.
c2 = clTest2.
COPY-LOB table1.clob2 TO m1.
COPY-LOB m1 TO clTest3.
c3 = clTest3.
MESSAGE "SESSION:CPINTERNAL : " SESSION:CPINTERNAL SKIP
"DB CODEPAGE : " DBCODEPAGE(1) SKIP(2)
"UTF-8 DB field table1.clob1 copied to LONGCHAR" SKIP
"-----------------------------------------------------" SKIP
"Is CLOBDB : " NOT(IS-COLUMN-CODEPAGE(table1.clob1)) SKIP
"CLOB data : " c1 SKIP
"CLOB data length in Bytes : " LENGTH(clTest1,"RAW") SKIP
"Longchar code page after COPY-LOB : " GET-CODEPAGE(cltest1) SKIP
SKIP(2)
"1252 DB field table1.clob2 copied to LONGCHAR" SKIP
"---------------------------------------------------" SKIP
"Is CLOBDB : " NOT(IS-COLUMN-CODEPAGE(table1.clob2)) SKIP
"CLOB data : " c2 SKIP
"CLOB data length in Bytes : " LENGTH(clTest2,"RAW") SKIP
"Longchar code page after COPY-LOB : " GET-CODEPAGE(cltest2) SKIP
SKIP(2)
"1252 DB field table1.clob2 copied to MEMPTR" SKIP
"------------------------------------------------" SKIP
"Is CLOBDB : " NOT(IS-COLUMN-CODEPAGE(table1.clob2)) SKIP
"CLOB data : " c3 SKIP
"CLOB data length in Bytes : " LENGTH(clTest3,"RAW") SKIP
"Longchar code page after COPY-LOB : " GET-CODEPAGE(cltest3) SKIP
VIEW-AS ALERT-BOX INFO BUTTONS OK.
- After the COPY-LOB the LONGCHAR variable remains in the original CLOBDB fields 1252 code page when it should have been converted to the -cpinternal code page (UTF-8), as has happened with the copy to the MEMPTR.