Connecting Tech Pros Worldwide Help | Site Map

MS Access From Perl

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 03:03 AM
Mike S
Guest
 
Posts: n/a
Default MS Access From Perl

Anyone know how I can access a MS Access database from perl?

Any help appreciated.



  #2  
Old November 13th, 2005, 03:03 AM
XMVP
Guest
 
Posts: n/a
Default Re: MS Access From Perl


"Mike S" <thrshr63@aol.com> wrote in message
news:0M33d.28415$Of4.10381100@news4.srv.hcvlny.cv. net...[color=blue]
> Anyone know how I can access a MS Access database from perl?
>
> Any help appreciated.
>[/color]

Wrong newsgroup, moron.
Join here:
access_morons@hotmail.com



  #3  
Old November 13th, 2005, 03:03 AM
gj
Guest
 
Posts: n/a
Default Re: MS Access From Perl

Mike S wrote:
[color=blue]
> Anyone know how I can access a MS Access database from perl?
>
> Any help appreciated.
>
>[/color]

A quick google
(http://www.google.com/search?sourcei...soft+access%22)
found the following script at
http://hypernews.ngdc.noaa.gov/Hyper...16.html?nogifs

I dont know perl myself so I cannot attest to its validity.

<<script begins>>

use Win32::ODBC;

$DEBUG = 0;

$DriverType = "Microsoft Access Driver (*.mdb)";
$DSN = "Win32 ODBC --MAOmaoMAOmaoMAO--";
$Dir = "c:\\mydocu~1";
$DBase = "maotest.mdb";

# Change Field1 and Field2 of Record 1 (i.e., where first column of
table equals 1)
$primaryID = 1;
$newvalue[$primaryID] =
{(
"Field1" => "test Field1",
"Field2" => "test Field2",
)};

Win32::ODBC::ConfigDSN(ODBC_ADD_DSN, $DriverType,
("DSN=$DSN", "Description=MAO Win32 ODBC Test DSN for Perl",
"DBQ=$Dir\\$DBase", "DEFAULTDIR=$Dir", "UID=", "PWD="))
or die "ConfigDSN(): Could not add temporary DSN" .
Win32::ODBC::Error();

$db=new Win32::ODBC($DSN) or die "couldn't ODBC $DSN because ",
Win32::ODBC::Error(), "\n";

my(%data, $key) = $db->GetDSN();
foreach $key (keys %data) {
print "$key: <$data{$key}>\n";
}

# Get list of tables in database
@table = $db->TableList;
print "Tables: @table\n" if $DEBUG;

$query = "select * from $table[0]";
!$db->Sql($query) or die "couldn't do $query because ", $db->Error(), "\n";

# Get list of columns in first table of database
@column = $db->FieldNames();
print "Columns: @column\n" if $DEBUG;

# Check for typos in hard-coded column names in $newvalue above

for $thisvalue (@newvalue)
{
$J = ' ';
$searchin = $J.join($J, @column).$J;
for $name (keys %$thisvalue)
{
$searchfor = $J.$name.$J;

print "Looking for \"$searchfor\" in \"$searchin\"\n"
if $DEBUG;
$searchin =~ /$searchfor/ or die "Can't locate $name in
@column";
}
}

print "Before...\n";
&PrintDatabase($db);

$query = "update $table[0] set
$column[1]=\'$newvalue[$primaryID]{$column[1]}\',
$column[2]=\'$newvalue[$primaryID]{$column[2]}\' where
$column[0]=$primaryID";
!$db->Sql($query) or die "couldn't do $query because ", $db->Error(), "\n";

$query = "select * from $table[0]";
!$db->Sql($query) or die "couldn't do $query because ", $db->Error(), "\n";

print "After...\n";
&PrintDatabase($db);

Win32::ODBC::ConfigDSN(ODBC_REMOVE_DSN, $DriverType, "DSN=$DSN") or die
"ConfigDSN(): Could not remove temporary DSN because ",
Win32::ODBC::Error();

sub PrintDatabase
{
my $db = shift(@_);
my @table = $db->TableList;
my @column;
my $column;
my $query = "select * from $table[0]";

!$db->Sql($query) or die "couldn't do $query because ", $db->Error(), "\n";
@column = $db->FieldNames();

for $column (@column)
{
printf("%15.15s ", $column);
}

print "\n";

for $column (@column)
{
printf("%15.15s ",
"_________________________________________________ ______________________________");
}

print "\n";

while($db->FetchRow())
{
my %Data = $db->DataHash();
for $column (@column)
{
printf("%15.15s ", $Data{$column});
}

print "\n";
}

print "\n";


<<script ends>>
  #4  
Old November 13th, 2005, 03:12 AM
John Mishefske
Guest
 
Posts: n/a
Default Re: MS Access From Perl

Mike S wrote:[color=blue]
> Anyone know how I can access a MS Access database from perl?
>
> Any help appreciated.[/color]

Sure. Use the DBI package. Driver for ADO available here:
http://search.cpan.org/search?query=...3A&mode=module

Same chapter on DBI:
http://www.oreilly.com/catalog/perld...pter/ch04.html

DBI Home Page:
http://dbi.perl.org/

--
'-------------------------------
' John Mishefske
'-------------------------------

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.