selecting nvarchar with Oratcl?



Hi all,

maybe someone can enlighten me how to correctly use Oratcl to select
nvarchar from a database.
I try to verify some setup where a python based oracle connector
(cx_Oracle) fails badly and want to check if its my environment or a
problem with OCI libs or something else, so i used Oratcl for a
verification.

Basically i try to select an char created with NCHR() in oracle
(National Character Set).

I currently have no idea whats still wrong with it.

Michael

The database encoding setup is like this:
OCI from instantclient10_1 (oci.dll Version 10.01.0000.0004)
NLS_LANG set to GERMAN_GERMANY.AL32UTF8 before loading Oratcl
Windows XP SP 2

from sqlplus:
SQL> select * from nls_database_parameters;

PARAMETER VALUE
------------------------------
----------------------------------------
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET WE8MSWIN1252
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM

PARAMETER VALUE
------------------------------
----------------------------------------
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 10.2.0.3.0

# with utfmode 1
C:\unicode>tclsh testuc.tcl
Could match without conversion 127
Could match with utf-8 conversion 206

# with utfmode 0
C:\unicode>tclsh testuc.tcl
Could match without conversion 238
Could match with utf-8 conversion 180

# Tcl and Oratcl are from the ActiveTcl build
C:\unicode>tclsh
% info patchlevel
8.4.16
% package require Oratcl
4.4
%

My Oratcl test script looks like this:

set ::env(PATH) {c:\sdk\win32\1.0\instantclient10_1}
set ::env(TNS_ADMIN) U:\\
set ::env(NLS_LANG) GERMAN_GERMANY.AL32UTF8

package require Oratcl


proc loop_utf8 {handle} {
set shandle [oraopen $handle]
oraconfig $shandle utfmode 0 ;# changing this just changes the
amount of non-matches a little bit, but not much

oraparse $shandle {SELECT
ASCIISTR(nchr(:codepoint)),nchr(:codepoint) FROM DUAL}
set hits 0
set utfhits 0
for {set i 1} {$i < 3000} {incr i} {
set code [format {\u%04x} $i]
eval set c $code
orabind $shandle :codepoint $i
if {[catch {
oraexec $shandle
} msg]} {
puts $::errorInfo
puts "Failed at Index $i"
}
while {1403 != [orafetch $shandle -datavariable r]} {
set ascii [lindex $r 0]
set val [lindex $r 1]
set val2 [encoding convertfrom utf-8 $val]
if {$val == $c} { incr hits}
if {$val2 == $c} { incr utfhits}
}
}
puts "Could match without conversion $hits"
puts "Could match with utf-8 conversion $utfhits"
}

set handle [oralogon "scott/tiger@DEV1"]
loop_utf8 $handle
oralogoff $handle
exit 0

.



Relevant Pages

  • Re: selecting nvarchar with Oratcl?
    ... maybe someone can enlighten me how to correctly use Oratcl to select ... Could match with utf-8 conversion 206 ... set shandle ... Which converts the values into the native system encoding? ...
    (comp.lang.tcl)
  • Re: ORACLE Logon with ORATCL4.1 as SYSDBA
    ... % package require Oratcl ... % puts $env ... I.E. oralogon user/password ... Does your database config allow remote sysdba connections. ...
    (comp.lang.tcl)
  • Re: Oratcl
    ... In Oratcl 4.3 you would do it this way. ... set plsql {BEGIN ... set cur [oraopen $lda] ... puts $params ...
    (comp.lang.tcl)