Database Reference
In-Depth Information
Attribute name
Array element meaning
Name of table the column is part of
mysql_table
Data type (numeric internal MySQL code)
mysql_type
Data type name
mysql_type_name
Some types of metadata, listed in the following table, are accessed as references to hashes
rather than arrays. These hashes have one element per column value. The element key
is the column name and its value is the position of the column within the result set. For
example:
$col_pos = $sth -> { NAME_hash } -> { col_name };
Attribute name Hash element meaning
NAME_hash Column name
NAME_hash_lc Column name in lowercase
NAME_hash_uc Column name in uppercase
The number of columns in a result set is available as a scalar value:
$num_cols = $sth -> { NUM_OF_FIELDS };
This example code shows how to execute a statement and display result set metadata:
my $stmt = "SELECT name, birth FROM profile" ;
printf "Statement: %s\n" , $stmt ;
my $sth = $dbh -> prepare ( $stmt );
$sth -> execute ();
# metadata information becomes available at this point ...
printf "NUM_OF_FIELDS: %d\n" , $sth -> { NUM_OF_FIELDS };
print "Note: statement has no result set\n" if $sth -> { NUM_OF_FIELDS } == 0 ;
for my $i ( 0 .. $sth -> { NUM_OF_FIELDS } - 1 )
{
printf "--- Column %d (%s) ---\n" , $i , $sth -> { NAME } -> [ $i ];
printf "NAME_lc: %s\n" , $sth -> { NAME_lc } -> [ $i ];
printf "NAME_uc: %s\n" , $sth -> { NAME_uc } -> [ $i ];
printf "NULLABLE: %s\n" , $sth -> { NULLABLE } -> [ $i ];
printf "PRECISION: %d\n" , $sth -> { PRECISION } -> [ $i ];
printf "SCALE: %d\n" , $sth -> { SCALE } -> [ $i ];
printf "TYPE: %d\n" , $sth -> { TYPE } -> [ $i ];
printf "mysql_is_blob: %s\n" , $sth -> { mysql_is_blob } -> [ $i ];
printf "mysql_is_key: %s\n" , $sth -> { mysql_is_key } -> [ $i ];
printf "mysql_is_num: %s\n" , $sth -> { mysql_is_num } -> [ $i ];
printf "mysql_is_pri_key: %s\n" , $sth -> { mysql_is_pri_key } -> [ $i ];
printf "mysql_max_length: %d\n" , $sth -> { mysql_max_length } -> [ $i ];
printf "mysql_table: %s\n" , $sth -> { mysql_table } -> [ $i ];
printf "mysql_type: %d\n" , $sth -> { mysql_type } -> [ $i ];
printf "mysql_type_name: %s\n" , $sth -> { mysql_type_name } -> [ $i ];
}
$sth -> finish (); # release result set because we didn't fetch its rows
 
Search WWH ::




Custom Search