# SQL Portability - Data Types

- ## For raw information about data types supported by the driver:

  $type_info_data = $dbh->type_info_all(…);

- ##

- ## To map data type codes to names:

  - $sth = $dbh->prepare(“select foo, bar from tablename”);
    $sth->execute;
    for my $i (0 .. $sth->{NUM_OF_FIELDS}) {printf ”Column name %s: Column type name: %s”, $sth->{NAME}->[$i], $dbh->type_info( $sth->{TYPE} )->{TYPE_NAME};
    }

- ## To select the nearest type supported by the database:

  - $my_date_type = $dbh->type_info( [ SQL_DATE, SQL_TIMESTAMP ] );
    $my_smallint_type = $dbh->type_info( [ SQL_SMALLINT, SQL_INTEGER, SQL_DECIMAL ] );

Previous slide | Next slide | Back to first slide | View graphic version