Attached is *not* a patch - it's a first cut and a cry for help!
I have problems mapping the ADO fields to SQL/CLI (ODBC, DBI)
fields, especially the datatype related fields.
I guess that the magic DBD::ADO::_determine_type_support() may
provide part of a solution.
Any suggestions, hints, insides, patches, ... are welcome!

BTW: It seems, that the statement handle attributes need the
     same mapping.


Steffen

        sub column_info {
                my( $dbh, @Criteria ) = @_;
                my $Criteria = \@Criteria if @Criteria;
                my $QueryType = 'adSchemaColumns';
                my @Rows;
                my $conn = $dbh->{ado_conn};
                my $tmpCursorLocation = $conn->{CursorLocation};
                $conn->{CursorLocation} = $ado_consts->{adUseClient};

                my $RecSet = $conn->OpenSchema( $ado_consts->{$QueryType}, $Criteria );
                my $lastError = DBD::ADO::errors($conn);
                return DBI::set_err($dbh, $DBD::ADO::err,
                        "Error occurred with call to OpenSchema ($QueryType): 
$lastError")
                                if $lastError;

                $RecSet->{Sort} = 'TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, 
ORDINAL_POSITION';
                $lastError = DBD::ADO::errors($conn);
                return DBI::set_err($dbh, $DBD::ADO::err,
                        "Error occurred defining sort order : $lastError")
                                if $lastError;

                while ( ! $RecSet->{EOF} ) {
                        my @Fields;
#                       my @Fields = map { $RecSet->Fields($_)->{Value} } ( 
0..3,11,x,6..9,12..14,16,15,17 );
                        $Fields[ 0] = $RecSet->Fields('TABLE_CATALOG'           
)->{Value}; # TABLE_CAT
                        $Fields[ 1] = $RecSet->Fields('TABLE_SCHEMA'            
)->{Value}; # TABLE_SCHEM
                        $Fields[ 2] = $RecSet->Fields('TABLE_NAME'              
)->{Value}; # TABLE_NAME
                        $Fields[ 3] = $RecSet->Fields('COLUMN_NAME'             
)->{Value}; # COLUMN_NAME
                        $Fields[ 4] = $RecSet->Fields('DATA_TYPE'               
)->{Value}; # DATA_TYPE !!!
                        $Fields[ 5] = $RecSet->Fields('COLUMN_FLAGS'            
)->{Value}; # TYPE_NAME !!!
                        $Fields[ 6] = $RecSet->Fields('NUMERIC_SCALE'           
)->{Value}; # COLUMN_SIZE !!!
                        $Fields[ 7] = 
$RecSet->Fields('CHARACTER_MAXIMUM_LENGTH')->{Value}; # BUFFER_LENGTH !!!
                        $Fields[ 8] = $RecSet->Fields('NUMERIC_PRECISION'       
)->{Value}; # DECIMAL_DIGITS ???
#                       $Fields[ 9] = $RecSet->Fields(''                        
)->{Value}; # NUM_PREC_RADIX !!!
                        $Fields[10] = $RecSet->Fields('IS_NULLABLE'             
)->{Value}; # NULLABLE !!!
                        $Fields[11] = $RecSet->Fields('DESCRIPTION'             
)->{Value}; # REMARKS
                        $Fields[12] = $RecSet->Fields('COLUMN_DEFAULT'          
)->{Value}; # COLUMN_DEF
#                       $Fields[13] = $RecSet->Fields(''                        
)->{Value}; # SQL_DATA_TYPE !!!
#                       $Fields[14] = $RecSet->Fields(''                        
)->{Value}; # SQL_DATETIME_SUB !!!
                        $Fields[15] = $RecSet->Fields('CHARACTER_OCTET_LENGTH'  
)->{Value}; # CHAR_OCTET_LENGTH
                        $Fields[16] = $RecSet->Fields('ORDINAL_POSITION'        
)->{Value}; # ORDINAL_POSITION
                        $Fields[17] = $RecSet->Fields('IS_NULLABLE'             
)->{Value}; # IS_NULLABLE !!!

#                       TODO:
#                       $Fields[ 4] = ado2sql_type( ... );
#                       ...

                        push( @Rows, \@Fields );
                        $RecSet->MoveNext;
                }
                $RecSet->Close; undef $RecSet;
                $conn->{CursorLocation} = $tmpCursorLocation;

                DBI->connect('dbi:Sponge:','','', { RaiseError => 1 })->prepare(
                        $QueryType, { rows => \@Rows, NAME =>
                        [ qw( TABLE_CAT TABLE_SCHEM TABLE_NAME COLUMN_NAME DATA_TYPE 
TYPE_NAME COLUMN_SIZE BUFFER_LENGTH DECIMAL_DIGITS NUM_PREC_RADIX NULLABLE REMARKS 
COLUMN_DEF SQL_DATA_TYPE SQL_DATETIME_SUB CHAR_OCTET_LENGTH ORDINAL_POSITION 
IS_NULLABLE ) ]});
        }

Reply via email to