perlquestion
taioba
<br>Hi! I am trying to connect to an OppenOffice database using Perl. I suspect I could do this through ODBC, but I don't know which driver to use.</br><br>I'm using Active Perl 5.10.x installed in a Windows XP machine, but I'll have to implement this code in a machine running Mac OS X, hence the need to migrate to OpenOffice.</br><br>I have the code working for an Access database. One of the operations is simply to store the database information in a hash (see example below, targeting the Access database.) <br>Any help is greatly appreciated.</br><br>Best wishes.</br>
<code>sub dbQuery {
my ($queryStr) = @_;
my $dbObject = DBI->connect("dbi:ODBC:driver=Microsoft Access Driver (*.mdb, *.accdb); dbq=$logHsh{dbPath}",
{RaiseError => 1}) || errMsg("Cannot connect to database.\n$DBI::errstr");
my $dbQuery = $dbObject->prepare($queryStr, {RaiseError => 1}) || errMsg("Couldn't prepare querying statement.\n$DBI::errstr");
$dbQuery->execute || errMsg("Error fetching data.\n$DBI::errstr");
my %dbHsh;
while (my ($hshKey, $hshRec) = $dbQuery->fetchrow_array) {
$dbHsh{$hshKey} = $hshRec;
}
$dbObject->disconnect;
return %dbHsh;
}</code>