Re: Add Unicode Support to the DBI

"H.Merijn Brand" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.sybase.devel
Message-ID <[email protected]>
On Wed, 09 Nov 2011 19:41:33 +0000, "Martin J. Evans"
<[email protected]> wrote:

> Your going to have a lot of problems with this test code and DBD::Unify 
> as we previously discovered that DBD::Unify does not decode the data 
> coming back from the database itself but it can be decoded by any Perl 
> script using DBD::Unify into the correct data. Any chance you could 
> change the test code to print out the results of type_info_all for 
> DBD::Unify and send me them?

Right, I have this:
--8<---
$type_info_all = [
    {	TYPE_NAME          =>  0,
	DATA_TYPE          =>  1,
	COLUMN_SIZE        =>  2,
	LITERAL_PREFIX     =>  3,
	LITERAL_SUFFIX     =>  4,
	CREATE_PARAMS      =>  5,
	NULLABLE           =>  6,
	CASE_SENSITIVE     =>  7,
	SEARCHABLE         =>  8,
	UNSIGNED_ATTRIBUTE =>  9,
	FIXED_PREC_SCALE   => 10,
	AUTO_UNIQUE_VALUE  => 11,
	LOCAL_TYPE_NAME    => 12,
	MINIMUM_SCALE      => 13,
	MAXIMUM_SCALE      => 14,
	SQL_DATA_TYPE      => 15,
	SQL_DATETIME_SUB   => 16,
	NUM_PREC_RADIX     => 17,
	INTERVAL_PRECISION => 18,
	},

#     TYPE_NAME           DATA_TYPE        SIZE  PFX   SFX   PARAMS            N C S UNSIG FPS   AUTO  LOCAL MINSC MAXSC SDT   SDS   RADIX PREC
    [ "UNKNOWN",          0,               undef,undef,undef,undef,            1,0,3,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef, ],
#   [ "GIANT AMOUNT",                      undef,undef,undef,"PRECISION,SCALE",1,0,3,0,    undef,undef,undef,2,    2,    undef,undef,undef,undef, ],
    [ "HUGE AMOUNT",      -207,            undef,undef,undef,"PRECISION,SCALE",1,0,3,0,    undef,undef,undef,2,    2,    undef,undef,undef,undef, ],
    [ "AMOUNT",           -206,            undef,undef,undef,"PRECISION,SCALE",1,0,3,0,    undef,undef,undef,2,    2,    undef,undef,undef,undef, ],
    [ "VARBINARY",        SQL_VARBINARY,   undef,"'", ,"'",  undef,            1,0,3,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef, ],
    [ "BINARY",           SQL_BINARY,      undef,undef,undef,undef,            1,0,3,0,    undef,undef,undef,0,    undef,undef,undef,undef,undef, ],
    [ "CHAR",             SQL_CHAR,        undef,undef,undef,"PRECISION",      1,0,3,0,    undef,undef,undef,0,    undef,undef,undef,undef,undef, ],
    [ "CURRENCY",         -218,            undef,undef,undef,"PRECISION,SCALE",1,0,3,0,    2,    undef,undef,0,    8,    undef,undef,undef,undef, ],
    [ "TIMESTAMP",        SQL_TIMESTAMP,   undef,undef,undef,undef,            1,0,3,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef, ],
    [ "DATE",             SQL_DATE,        undef,undef,undef,undef,            1,0,3,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef, ],
    [ "DECIMAL",          SQL_DECIMAL,     undef,undef,undef,"PRECISION",      1,0,3,0,    undef,undef,undef,0,    undef,undef,undef,undef,undef, ],
    [ "DOUBLE PRECISION", SQL_DOUBLE,      undef,undef,undef,"PRECISION",      1,0,3,0,    undef,undef,undef,0,    undef,undef,undef,undef,undef, ],
    [ "FLOAT",            SQL_FLOAT,       undef,undef,undef,"PRECISION",      1,0,3,0,    undef,undef,undef,0,    undef,undef,undef,undef,undef, ],
    [ "HUGE INTEGER",     SQL_BIGINT,      undef,undef,undef,"PRECISION",      1,0,3,0,    undef,undef,undef,0,    0,    undef,undef,undef,undef, ],
    [ "INTEGER",          SQL_INTEGER,     undef,undef,undef,"PRECISION",      1,0,3,0,    undef,undef,undef,0,    undef,undef,undef,undef,undef, ],
    [ "NUMERIC",          SQL_NUMERIC,     undef,undef,undef,"PRECISION",      1,0,3,0,    undef,undef,undef,0,    0,    undef,undef,undef,undef, ],
    [ "REAL",             SQL_REAL,        undef,undef,undef,"PRECISION",      1,0,3,0,    undef,undef,undef,0,    undef,undef,undef,undef,undef, ],
    [ "SMALLINT",         SQL_SMALLINT,    undef,undef,undef,"PRECISION",      1,0,3,0,    undef,undef,undef,0,    0,    undef,undef,undef,undef, ],
    [ "TEXT",             SQL_LONGVARCHAR, undef,"'", ,"'",  undef,            1,0,3,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef, ],
    [ "TIME",             SQL_TIME,        undef,undef,undef,undef,            1,0,3,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef, ],
    ];

my %odbc_types = map { ( $_->[0] => $_->[1], $_->[1] => $_->[0] ) }
    [  -5  => "BIGINT"		], # SQL_BIGINT
    [  -3  => "VARBINARY"	], # SQL_VARBINARY
    [  -2  => "BINARY"		], # SQL_BINARY
    [  -1  => "TEXT"		], # SQL_LONGVARCHAR
    [   0  => "UNKNOWN_TYPE"	], # SQL_UNKNOWN_TYPE
    [   1  => "CHAR"		], # SQL_CHAR
    [   2  => "NUMERIC"		], # SQL_NUMERIC
    [   3  => "DECIMAL"		], # SQL_DECIMAL
    [   4  => "INTEGER"		], # SQL_INTEGER
    [   5  => "SMALLINT"	], # SQL_SMALLINT
    [   6  => "FLOAT"		], # SQL_FLOAT
    [   7  => "REAL"		], # SQL_REAL
    [   8  => "DOUBLE PRECISION"], # SQL_DOUBLE
    [   9  => "DATE"		], # SQL_DATE
    [  10  => "TIME"		], # SQL_TIME
    [  11  => "TIMESTAMP"	], # SQL_TIMESTAMP
    [  12  => "VARCHAR"		], # SQL_VARCHAR
    [  16  => "BOOLEAN"		], # SQL_BOOLEAN
    [  19  => "ROW"		], # SQL_ROW
    [  20  => "REF"		], # SQL_REF
    [  30  => "BLOB"		], # SQL_BLOB
    [  40  => "CLOB"		], # SQL_CLOB
    ;
$odbc_types{DOUBLE}  = $odbc_types{"DOUBLE PRECISION"};

my %uni_types = map { ( $_->[0] => $_->[1], $_->[1] => $_->[0] ) }
    [ -18  => "CURRENCY"	], # SQLAMT64
    [ -17  => "HUGE INTEGER"	], # SQLINT64
    [ -12  => "BYTE"		], # SQLBYTE
    [ -11  => "HUGE DATE"	], # SQLHDATE
    [ -10  => "BINARY"		], # SQLBINARY
    [  -9  => "TEXT"		], # SQLTEXT
    [  -7  => "TIME"		], # SQLSMTIME
    [  -6  => "HUGE AMOUNT"	], # SQLHUGEAMT
    [  -4  => "AMOUNT"		], # SQLAMOUNT
    [  -3  => "DATE"		], # SQLDATE
    [   0  => "NOTYPE"		], # SQLNOTYPE
    [   1  => "CHAR"		], # SQLCHAR
    [   2  => "NUMERIC"		], # SQLNUMERIC
    [   3  => "DECIMAL"		], # SQLDECIMAL
    [   4  => "INTEGER"		], # SQLINTEGER
    [   5  => "SMALLINT"	], # SQLSMINT
    [   6  => "FLOAT"		], # SQLFLOAT
    [   7  => "REAL"		], # SQLREAL
    [   8  => "DOUBLE PRECISION"], # SQLDBLPREC
    ;
$uni_types{CHARACTER} = $uni_types{CHAR};
$uni_types{DOUBLE}    = $uni_types{"DOUBLE PRECISION"};

sub odbc_type
{
    my $t = shift;
    defined $t or return 0;
    $t = $odbc_types{uc $t} || $t;
    return $t;
    } # uni_type

sub uni_type
{
    my $t = shift;
    defined $t or return 0;
    $t = $uni_types{uc $t} || $t;
    return $t;
    } # uni_type
-->8---

which shows I have set up the DATA_TYPE, not the SQL_DATA_TYPE
shall I just copy DATA_TYPE to SQL_DATA_TYPE?

-- 
H.Merijn Brand  http://tux.nl      Perl Monger  http://amsterdam.pm.org/
using 5.00307 through 5.14 and porting perl5.15.x on HP-UX 10.20, 11.00,
11.11, 11.23 and 11.31, OpenSuSE 10.1, 11.0 .. 11.4 and AIX 5.2 and 5.3.
http://mirrors.develooper.com/hpux/           http://www.test-smoke.org/
http://qa.perl.org      http://www.goldmark.org/jeff/stupid-disclaimers/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.