开发者

How do I use SQL to "Show tables" in a MS Access database?

开发者 https://www.devze.com 2022-12-19 17:49 出处:网络
I based my code on the answer to the question Access get all tables, but am getting the following error:

I based my code on the answer to the question Access get all tables, but am getting the following error:

DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access Driver] Record(s) cannot be read; no read permission on 'MSysObjects'. (SQL-42000) at direct.pl line 22.

[Microsoft][ODBC Microsoft Access Driver] Record(s) cannot be read; no read permission on 'MSysObjects'. (SQL-42000) at direct.pl line 22.

Here is what I have tried so far. I commented out my first attempt. The current attempt is based on SELECT "Table" AS [Table] which astander mentioned in his answer to said question. I get the same error either way. Here is my code, in its entirety:

use strict;
use warnings;

use DBI;

my $dbh = DBI->connect('DBI:ODBC:MutantDB','','') 
    or die 'could not connect to database' . DBI::errstr;

my $sth = $dbh->prepare('SELECT "Table" AS [Table],
             MSysObjects.Name,
             MSysObjects.Type
             FROM MSysObjects
             WHERE MSysObjects.Type =1
             Or MSysObjects.Type=6
             ORDER BY MSysObjects.Name;')
    or die 'could not prepare statement' . $dbh->errstr();


# my $sth = $dbh->prepare('SELECT MSysObjects.*, MSysObjects.Type
#              FROM MSysObjects
#              WHERE (((MSysObjects.Type开发者_运维问答)=1)) OR (((MSysObjects.Type)=6));'
# ) or die 'could not prepare statment' . $dbh->errstr();

$sth->execute() or die $sth->errstr();

while( my ($name, $type) = $sth->fetchrow()){
    print "name: $name \t type: $type \n";
}


How about a schema?

http://www.cpan.org/authors/id/T/TL/TLOWERY/DBD-ADO-2.1.readme

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号