On Fri, Feb 01, 2002 at 09:21:09AM +0100, Steffen Goeldner wrote:
> A new patch for DBD::Oracle:
> 
>  - get_info() now takes a numeric value
>  - SQL_DBMS_VERSION is supported
> 
> More info types if desired. (I don't like a blindfold
> adoption of the Oracle ODBC driver results.)

Great, many thanks.

Could I ask that you move the hash setup outside the function
and put in there only the values that are constant.

Then in the function do something like

  sub get_info {
    my($dbh, $info_type) = @_;
    my $v = $get_info_constants{int($info_type)};
    return $v if defined $v;
    ... handle the other values ...
  }

I'd like this to be a good and efficient model for other drivers
to follow.

Umm, here's another idea... for the non-constant items put them into
the %get_info_constants hash as anonymous subs that return the appropriate
value. Then in get_info do:

  sub get_info {
    my($dbh, $info_type) = @_;
    my $v = $get_info_constants{int($info_type)};
    $v = &$v($dbh) if ref $v eq 'CODE';
    return $v;
  }

Umm, carrying on from there... move %get_info_constants into DBD::Oracle::GetInfo
and make get_info do:

  sub get_info {
    my($dbh, $info_type) = @_;
    require DBD::Oracle::GetInfo;
    my $v = $DBD::Oracle::GetInfo::info{int($info_type)};
    $v = &$v($dbh, $info_type) if ref $v eq 'CODE';
    return $v;
  }

:-)

Thanks!

Tim.

> 
> Steffen
> *** DBD-Oracle-1.12.orig/Oracle.pm    Fri Aug 31 18:27:18 2001
> --- Oracle.pm Thu Jan 31 22:33:59 2002
> ***************
> *** 313,318 ****
> --- 313,368 ----
>       }
>   
>   
> +     sub get_info {
> +     my($dbh, $info_type) = @_;
> +     # XXX Caching
> +     my $fmt = '%02d.%02d.%1d%1d%1d%1d';   # ODBC version string: ##.##.#####
> +     if    ($info_type == 18) {            # SQL_DBMS_VERSION
> +         return sprintf $fmt, @{ora_server_version($dbh)};
> +     }
> +     elsif ($info_type ==  7) {            # SQL_DRIVER_VER
> +         return sprintf $fmt, split (/\./, $DBD::Oracle::VERSION);
> +     }
> +     my %gi = (
> +         117 =>  0                         # SQL_ALTER_DOMAIN
> +     ,   114 =>  2                         # SQL_CATALOG_LOCATION
> +     , 10003 => 'N'                        # SQL_CATALOG_NAME
> +     ,    41 => '@'                        # SQL_CATALOG_NAME_SEPARATOR
> +     ,    42 => 'Database Link'            # SQL_CATALOG_TERM
> +     ,    87 => 'Y'                        # SQL_COLUMN_ALIAS
> +     ,    22 =>  1                         # SQL_CONCAT_NULL_BEHAVIOR
> +     ,   130 =>  0                         # SQL_CREATE_DOMAIN
> +     ,     2 => "dbi:Oracle:$dbh->{Name}"  # SQL_DATA_SOURCE_NAME
> +     ,    17 => 'Oracle'                   # SQL_DBMS_NAME
> +     ,     6 => __FILE__                   # SQL_DRIVER_NAME
> +     ,   139 =>  0                         # SQL_DROP_DOMAIN
> +     ,    28 =>  1                         # SQL_IDENTIFIER_CASE
> +     ,    29 => '"'                        # SQL_IDENTIFIER_QUOTE_CHAR
> +     ,    34 =>  0                         # SQL_MAX_CATALOG_NAME_LEN
> +     ,    30 => 30                         # SQL_MAX_COLUMN_NAME_LEN
> +     , 10005 => 30                         # SQL_MAX_IDENTIFIER_LEN
> +     ,    32 => 30                         # SQL_MAX_OWNER_NAME_LEN
> +     ,    34 =>  0                         # SQL_MAX_QUALIFIER_NAME_LEN
> +     ,    32 => 30                         # SQL_MAX_SCHEMA_NAME_LEN
> +     ,    35 => 30                         # SQL_MAX_TABLE_NAME_LEN
> +     ,   107 => 30                         # SQL_MAX_USER_NAME_LEN
> +     ,    39 => 'Owner'                    # SQL_OWNER_TERM
> +     ,    40 => 'Procedure'                # SQL_PROCEDURE_TERM
> +     ,   114 =>  2                         # SQL_QUALIFIER_LOCATION
> +     ,    41 => '@'                        # SQL_QUALIFIER_NAME_SEPARATOR
> +     ,    42 => 'Database Link'            # SQL_QUALIFIER_TERM
> +     ,    93 =>  3                         # SQL_QUOTED_IDENTIFIER_CASE
> +     ,    39 => 'Owner'                    # SQL_SCHEMA_TERM
> +     ,    14 => '\\'                       # SQL_SEARCH_PATTERN_ESCAPE
> +     ,    13 => "$dbh->{Name}"             # SQL_SERVER_NAME
> +     ,    94 => '$#'                       # SQL_SPECIAL_CHARACTERS
> +     ,    45 => 'Table'                    # SQL_TABLE_TERM
> +     ,    47 => "$dbh->{CURRENT_USER}"     # SQL_USER_NAME         # XXX OPS$
> +     );
> +     return $gi{$info_type};
> +     }
> + 
> + 
>       sub table_info {
>       my($dbh, $attr) = @_;
>       # XXX add knowledge of temp tables, etc

Reply via email to