Skip to content

Commit 4e783a9

Browse files
Improve documentation based on feedback
(oracle#343).
1 parent a16a944 commit 4e783a9

File tree

2 files changed

+35
-56
lines changed

2 files changed

+35
-56
lines changed

doc/src/api_manual/module.rst

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,8 @@ Module Interface
9292
The newpassword parameter is expected to be a string if specified and sets
9393
the password for the logon during the connection process.
9494

95-
The encoding parameter is expected to be one of the
96-
`Python standard encodings
97-
<https://docs.python.org/3/library/codecs.html#standard-encodings>`__
98-
such as 'UTF-8', if specified, and sets the encoding to use for regular
99-
database strings. If not specified, the Oracle environment variable
100-
NLS_LANG is used and the Oracle character set is translated to one of the
101-
standard encodings, if possible. If the Oracle environment variable
102-
NLS_LANG is not set, ASCII is used.
103-
104-
The nencoding parameter is expected to be one of the
105-
`Python standard encodings
106-
<https://docs.python.org/3/library/codecs.html#standard-encodings>`__
107-
such as 'UTF-8', if specified, and sets the encoding to use for national
108-
character set database strings. If not specified, the Oracle environment
109-
variable NLS_NCHAR is used and the Oracle character set is translated to
110-
one of the standard encodings, if possible. If the Oracle environment
111-
variable NLS_NCHAR is not used, the Oracle environment variable NLS_LANG is
112-
used instead, and if the Oracle environment variable NLS_LANG is not set,
113-
ASCII is used.
95+
See the :ref:`globalization <globalization>` section for details on the
96+
encoding and nencoding parameters.
11497

11598
The edition parameter is expected to be a string if specified and sets the
11699
edition to use for the session. It is only relevant if both the client and
@@ -222,25 +205,8 @@ Module Interface
222205
authenticating the user to the database. This includes the use of operating
223206
system authentication and Oracle wallets.
224207

225-
The encoding parameter is expected to be one of the
226-
`Python standard encodings
227-
<https://docs.python.org/3/library/codecs.html#standard-encodings>`__
228-
such as 'UTF-8', if specified, and sets the encoding to use for regular
229-
database strings. If not specified, the Oracle environment variable
230-
NLS_LANG is used and the Oracle character set is translated to one of the
231-
standard encodings, if possible. If the Oracle environment variable
232-
NLS_LANG is not set, ASCII is used.
233-
234-
The nencoding parameter is expected to be one of the
235-
`Python standard encodings
236-
<https://docs.python.org/3/library/codecs.html#standard-encodings>`__
237-
such as 'UTF-8', if specified, and sets the encoding to use for national
238-
character set database strings. If not specified, the Oracle environment
239-
variable NLS_NCHAR is used and the Oracle character set is translated to
240-
one of the standard encodings, if possible. If the Oracle environment
241-
variable NLS_NCHAR is not used, the Oracle environment variable NLS_LANG is
242-
used instead, and if the Oracle environment variable NLS_LANG is not set,
243-
ASCII is used.
208+
See the :ref:`globalization <globalization>` section for details on the
209+
encoding and nencoding parameters.
244210

245211
The edition parameter is expected to be a string, if specified, and sets
246212
the edition to use for the sessions in the pool. It is only relevant if

doc/src/user_guide/globalization.rst

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ other features that will be useful in applications. See the
2121
Setting the Client Character Set
2222
================================
2323

24-
You can specify the Oracle client character set used by cx_Oracle by passing the
25-
``encoding`` and ``nencoding`` parameters to the :meth:`cx_Oracle.connect` and
26-
:meth:`cx_Oracle.SessionPool` methods. For example:
24+
You can specify the Oracle client character set used by cx_Oracle by passing
25+
the ``encoding`` and ``nencoding`` parameters to the :meth:`cx_Oracle.connect`
26+
and :meth:`cx_Oracle.SessionPool` methods. For example:
2727

2828
.. code-block:: python
2929
@@ -34,35 +34,48 @@ You can specify the Oracle client character set used by cx_Oracle by passing the
3434
The ``encoding`` parameter affects character data such as VARCHAR2 and CLOB
3535
columns. The ``nencoding`` parameter affects "National Character" data such as
3636
NVARCHAR2 and NCLOB. If you are not using national character types, then you
37-
can omit ``nencoding``.
37+
can omit ``nencoding``. Both the ``encoding`` and ``nencoding`` parameters are
38+
expected to be one of the `Python standard encodings
39+
<https://docs.python.org/3/library/codecs.html#standard-encodings>`__ such as
40+
``UTF-8``. Do not accidentally use ``UTF8``, which Oracle uses to specify the
41+
older Unicode 3.0 Universal character set, ``CESU-8``. Note that Oracle does
42+
not recognize all of the encodings that Python recognizes. You can see which
43+
encodings Oracle supports by issuing this query:
3844

39-
cx_Oracle will first treat the encoding parameter values as `IANA encoding names
40-
<https://www.iana.org/assignments/character-sets/character-sets.xhtml>`__. If
41-
no name is matched, it will attempt to use `Oracle character set names
42-
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-9529D1B5-7366-4195-94B5-0F90F3B472E1>`__. For
43-
example, for ``UTF-8`` characters you should use the IANA name "UTF-8" or the
44-
Oracle name "AL32UTF8". Do not accidentally use "UTF8", which Oracle uses to
45-
specify the older Unicode 3.0 Universal character set, ``CESU-8``.
45+
.. code-block:: sql
46+
47+
select distinct utl_i18n.map_charset(value)
48+
from v$nls_valid_values
49+
where parameter = 'CHARACTERSET'
50+
and utl_i18n.map_charset(value) is not null
51+
order by 1
4652
4753
An alternative to setting the encoding parameters is to set Oracle's
4854
``NLS_LANG`` environment variable to a value such as
4955
``AMERICAN_AMERICA.AL32UTF8``. See :ref:`Setting environment variables
5056
<envset>`. As well as setting the character set, the ``NLS_LANG`` environment
5157
variable lets you specify the Language (``AMERICAN`` in this example) and
52-
Territory (``AMERICA``) used for NLS globalization. See `Choosing a Locale with
53-
the NLS_LANG Environment Variable
54-
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-86A29834-AE29-4BA5-8A78-E19C168B690A>`__.
58+
Territory (``AMERICA``) used for NLS globalization. See
59+
`Choosing a Locale with the NLS_LANG Environment Variables
60+
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&
61+
id=GUID-86A29834-AE29-4BA5-8A78-E19C168B690A>`__.
5562

5663
A character set specified by an ``encoding`` parameter will override the
5764
character set in ``NLS_LANG``. The language and territory components will still
5865
be used by Oracle.
5966

6067
If the ``NLS_LANG`` environment variable is set in the application with
61-
``os.environ['NLS_LANG']``, it must be set before any connection pool is created,
62-
or before any standalone connections are created.
68+
``os.environ['NLS_LANG']``, it must be set before any connection pool is
69+
created, or before any standalone connections are created.
70+
71+
If neither of the encoding parameters are specified and the ``NLS_LANG``
72+
environment variable is not set, the character set ``ASCII`` is used.
73+
74+
Other Oracle globalization variable can also be set, see
75+
`Setting NLS Parameters
76+
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&
77+
id=GUID-6475CA50-6476-4559-AD87-35D431276B20>`__.
6378

64-
Other Oracle globalization variable can also be set, see `Setting NLS Parameters
65-
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-6475CA50-6476-4559-AD87-35D431276B20>`__.
6679

6780
Character Set Example
6881
=====================

0 commit comments

Comments
 (0)