Paved lines are cut in half using node -oracle

I am using node -oracle to connect to Oracle db.

When I select the values ​​from the tables with Cyrillic data, everything is fine, but if I call a proc like:

CREATE OR REPLACE PROCEDURE TEST_ENCODING (CUR OUT SYS_REFCURSOR) AS BEGIN open cur for select '' as hello from dual; -- cyrillic hardcoded text END TEST_ENCODING; 

and then call it from node:

 connection.execute("call TEST_ENCODING(:1)", [new oracle.OutParam(oracle.OCCICURSOR)], function (err, result) { console.log(result) } ); 

Result: [ { HELLO: '' } ] (the line is cut in half).

The database is configured as follows:

 NLS_LANGUAGE AMERICAN NLS_TERRITORY AMERICA NLS_CURRENCY $ NLS_ISO_CURRENCY AMERICA NLS_NUMERIC_CHARACTERS ., NLS_CHARACTERSET CL8MSWIN1251 NLS_CALENDAR GREGORIAN NLS_DATE_FORMAT DD-MON-RR NLS_DATE_LANGUAGE AMERICAN NLS_SORT BINARY NLS_TIME_FORMAT HH.MI.SSXFF AM NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR NLS_DUAL_CURRENCY $ NLS_COMP BINARY NLS_LENGTH_SEMANTICS BYTE NLS_NCHAR_CONV_EXCP FALSE NLS_NCHAR_CHARACTERSET AL16UTF16 NLS_RDBMS_VERSION 11.2.0.3.0 

In my local env: NLS_LANG=AMERICAN_AMERICA.UTF8 (also tried NLS_LANG=RUSSIAN_RUSSIA.UTF8 and RUSSIAN_RUSSIA.AL32UTF8 with the same results)

My configuration:
Mac OS X 10.9
Oracle Client 11.2
node 0.10.22
node -oracle 0.3.4

+6
source share
3 answers
  • It looks like there is no support for encodings other than UTF8 in node-oracle , because node.js does not support native encodings ( proof ).

  • To process strings correctly, you need to set the NLS_LANG parameter on the client to the same value as in the database (CL8MSWIN1251)

So, you can choose one of two options:

A) Transfer the database to UTF8 .

B) A node-oracle source patch to convert strings and CLOBs to UTF8 before returning its contents to node.js and apply the conversion from UTF8 to CL8MSWIN1251 before transferring it to Oracle. The OCI interface has functions for such conversions. For instance. for your local purpose, just schedule the OBJ_GET_STRING macro in utils.h

PS node-oracle looks very simplistic at the moment, so be prepared for a lot of surprises (for example, there is no support for BLOB and collections, lack of connection settings, etc.).

+1
source

This may be due to the fact that the primary encoding of the database is CL8MSWIN1251 when local configuration specifies UTF8.

 NLS_CHARACTERSET CL8MSWIN1251 

The NLS_LANG variable indicates how to interpret your local environment

 NLS_LANG = language_territory.charset 

The last part of NLS_LANG provides information about local encoding and is used to let Oracle know what character set you are using on the client side, so Oracle can do the right conversion. Probably, the values ​​from the tables are converted correctly if the encoding of the value from the double table is not defined correctly.

Try setting the NLS_LANG variable to AMERICAN_AMERICA.CL8MSWIN1251 (or RUSSIAN_RUSSIA.CL8MSWIN1251, it does not matter)

0
source

Are you sure your source code has a UTF-8 character set?
if the problem is only with hard-coded characters, maybe your Oracle GUI does not support UTF-8
I have a similar problem with special characters like ¥ in my package and sql * plus which convert special characters to some unreadable

0
source

Source: https://habr.com/ru/post/958370/


All Articles