chicago928 has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

Thanks to the wonderful perl monks I've worked out connecting to a database file once security permissions are such that I can read the MSysObjects table.

However, I have many many many of these files and it would not be feasible to change the permissions on each one manually. Does anyone know how to have perl give me read permission on the database?

-Thanks

  • Comment on changing read permissions on MS ACCESS database

Replies are listed 'Best First'.
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
    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.

Re: changing read permissions on MS ACCESS database
by marto (Cardinal) on Jul 14, 2005 at 17:18 UTC
    Hi,

    I remember talking to you in the CB about this today.
    Without being sure what you alredy have code wise to do this its hard to say.
    Please post an example so we can be sure.

    If we are still talking about exporting all tables as csv files you first want to get a list of all the tables.
    The Access (yuck) SQL to return all table names is:

    SELECT MSysObjects.Name
    FROM MSysObjects
    WHERE (((MSysObjects.Flags)=0) AND ((MSysObjects.Type)=1));

    With Flags being zero you get only user defined tables, none of the Access (yuck) system tables.

    That should get you started. Once you have the list of tables you should be able to dump it as a csv file quite easily.
    I will check later tonight to see if you have posted the code you are using.

    Hope this helps

    Martin