Category Archives: Perl

Caching The Data Dictionary

In the last couple of posts I have talked about extracting table names using DBI->table_info() and extracting column names using DBI->column_info(). If for example I had a tetchy DBA who didn’t want me to hit the database every time I wanted this information, or I was too impatient to wait for socket set-up/teardown, I might [...]

Posted in Perl | Tagged , , | Leave a comment

Perl DBI table_info method

Just as column_info() returns information about the table columns in your database, so table_info() returns information about the tables themselves. my $sth = $dbh->table_info(); print join(“, “, @{$sth->{NAME}}); print “\n”; while (defined(my $row = $sth->fetchrow_hashref())) { print “Table: $row->{TABLE_NAME}\n”; } Results TABLE_CAT, TABLE_SCHEM, TABLE_NAME, TABLE_TYPE, REMARKS Table: wp_commentmeta Table: wp_comments Table: wp_links Table: wp_options Table: [...]

Posted in Perl | Tagged , | Leave a comment

Database Agnostic Data Dictionary Spelunking with Perl DBI

The various databases all have different ways of querying the internal data dictionary, to find out which tables are available and which columns they contain. Perl DBI provides a unifying interface so that you can extract table and column data from any supported database using the same API. The method to extract column names and [...]

Also posted in Programming | Tagged , | Leave a comment