CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: DBI:
Problem reading small numbers using microsoft access driver (*.mdb, *.accdb)

 



ihawkins
New User

Sep 1, 2010, 3:49 AM

Post #1 of 1 (2702 views)
Problem reading small numbers using microsoft access driver (*.mdb, *.accdb) Can't Post

Minimal version of problem attached. Numbers such as 1.23 are read ok using perl .mdb driver or .mdb, .accdb driver. Small numbers such as 1.23E-15 are read ok using .mdb driver, but not .accdb driver. Latter returns E-15 instead.

Have tried database in 2000,2003,2007 format and .accdb driver always has same behaviour. May be able to get away using older driver, but would like to understand how to make the newer one work.

I'm using active state perl 5.10

Output of code is shown below

Testing with driver microsoft access driver (*.mdb)
1 1.23
2 0.0000123
3 0.000000000123
4 1.23E-15
5 1.23E-20

Testing with driver microsoft access driver (*.mdb, *.accdb)
1 1.23
2 0.0000123
3 0.000000000123
4 E-15
5 E-20


Code
#!/bin/perl 
#
# Driver test on access table containing small numbers
#

use DBI;

$database = 'F:\temp\numericTest.mdb';


runTest('microsoft access driver (*.mdb)');
runTest('microsoft access driver (*.mdb, *.accdb)');


sub runTest {

my $driver = shift(@_);
print STDOUT "\nTesting with driver $driver\n";

# Open database connection
$dbh = DBI->connect(
'dbi:ODBC:driver='.$driver.';dbq=' . $database )
|| die "Can't connect to Kromer Database: $DBI::errstr";


# run query
$sqlstatement =
"SELECT numbers from numbersTable";
$sth = runQuery($sqlstatement);
$cnt = 0;
while ( @row = $sth->fetchrow_array() ) {
$cnt++;
$val = $row[0];
print STDOUT "$cnt $val\n";
}


# print most recent errr if exists and close connection
print $dbh->errstr;
$dbh->disconnect;
}

sub runQuery {
my $query = shift(@_);
$sth = $dbh->prepare($sqlstatement)
|| die "Can't prepare statement: $DBI::errstr";

$sth->execute
|| die "Could not execute SQL statement, check query";
return $sth;
}


(Question also posted to experts exchange, but thought I should post it to a perl specific forum also)
Attachments: numericTest.mdb (244 KB)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives