Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

How to get table names using DBI (was Re: changing read permissions on MS ACCESS database)

by bmann (Priest)
on Jul 14, 2005 at 19:37 UTC ( #475026=note: print w/replies, xml ) Need Help??

in reply to changing read permissions on MS ACCESS database

Hi chicago928,

If I read your question(s) right, what you are looking for is a generic way to get a list of table names (and column names) from an access database so you can dump each table to a csv file, right?

There are several ways you can get this info without changing permissions on a db's system tables. One way is to use the DBI's table_info method.

#!/usr/bin/perl use strict; use warnings; use DBI; my $db = "c:\\db.mdb"; my $datasource = "driver=Microsoft Access Driver (*.mdb);dbq=$db"; my $dbh = DBI->connect( "dbi:ODBC:$datasource", '', '', { RaiseError => 1 } ); my $sth = $dbh->table_info( '', '', '', 'TABLE' ); while ( my ( undef, undef, $name ) = $sth->fetchrow_array() ) { print "$name:\n"; my $colsth = $dbh->column_info( '', '', $name, '' ); while ( my (undef, undef, undef, $col_name ) = $colsth->fetchrow_a +rray() ) { print "\t$col_name\n"; } }
Access system tables (MSys*) have a type of "SYSTEM TABLE", regular tables have type "TABLE", and queries have type "VIEW". The fourth parameter to table_info allows you to filter the results, and I chose to display only the regular tables.

This all assumes you are on Win32. You can find more info on table_info and col_info at DBI. You might also be interested in DBI recipes.

  • Comment on How to get table names using DBI (was Re: changing read permissions on MS ACCESS database)
  • Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://475026]
[Corion]: Maybe I should look through my CPAN releases and revisit them in order of last release and think about what to do with the modules :)
[marto]: this cpan day there should be a call to remove old crud :P
[marto]: as well as encourage active development

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2018-07-17 08:20 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (359 votes). Check out past polls.