column_info()
$dbh->column_info($catalog, $database, $table, $column)
This function returns a statement handle for fetching information about columns in a table. Here is an example:
...
my $sth = $dbh->column_info(undef, 'bookstore', 'books', '%');
my $col_info = $sth->fetchall_arrayref();
foreach my $info(@$col_info) {
foreach (@$info) {
if($_) { print $_ . "|"; }
}
print "\n";
}This program excerpt will produce a list of columns in the
books table of the bookstore
database. Here are a couple of lines of the program results:
bookstore|books|book_id|4|INT|11|10|4|1|NO|1|int(11)| bookstore|books|title|12|VARCHAR|50|1|12|2|YES|varchar(50)| ...
The values of the fields in order are:
TABLE_CAT (usually empty),
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, and
IS_NULLABLE.