Salesforce

COPY-LOB database CLOB to LONGCHAR code page conversion is wrong

« Go Back

Information

 
TitleCOPY-LOB database CLOB to LONGCHAR code page conversion is wrong
URL NameCOPY-LOB-database-CLOB-to-LONGCHAR-code-page-conversion-is-wrong
Article Number000192981
EnvironmentProduct: OpenEdge
Version: 11.x
OS: Windows
Question/Problem Description
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.

User-added image
 
 
Steps to Reproduce
Clarifying Information
The same problem happens with general assignment statements (i.e. not just with COPY-LOB):
 
/* COPY-LOB table1.clob1 TO clTest1. */
clTest1 = table1.clob1.
c1 = clTest1.

/* COPY-LOB table1.clob2 TO clTest2. */
clTest2 = table1.clob2.
c2 = clTest2.

 
Error Message
Defect NumberDefect PSC00351219
Enhancement Number
Cause
The value of the CLOB_CODEPAGE is always returned as the Database Clob codepage (CLOB_DB) without first verifying the client codepage (CLOB_CP)
Resolution
Upgrade to OpenEdge 11.7.0, where the the proper value for a CLOB codepage is used by the COPY-LOB statement.
Workaround
There are two ways to work around the problem:
  1. Copy the CLOBDB to a MEMPTR before copying the MEMPTR to a LONGCHAR.
  2. FIX the codepage of the longchar to cpinternal:
FIX-CODEPAGE(clTest2) = SESSION:CPINTERNAL.

 
Notes
References to Other Documentation:

OpenEdge Development: ABL Reference, "COPY-LOB statement"
OpenEdge Web Paper: ABL Data Types Addenda, Chapter 3: Large object data types, "CLOB code pages"
Keyword Phrase
Last Modified Date6/11/2019 9:07 AM

Powered by