Problem using DB_File

A

Andras Malatinszky

I'm trying to read a database that I created using the DB_File module on
a Linux box and then transferred to a Windows box. Here's a simplified
setup illustration of my problem:

First, on the Linux box I ran this script:

#!/usr/bin/perl -w
use strict;
use DB_File;

tie my %db, 'DB_File', 'database.db';

$db{'blue'}='azul';

untie %db;


As expected, it creates a file called database.db, and when I run this
script:

#!/usr/bin/perl -w
use strict;
use DB_File;

tie my %db, 'DB_File', 'database.db' or die $!;

print $db{'blue'};

untie %db;


I get the word "azul" printed on the screen as expected.

So now I FTP database.db and the second script over to my Windows box
and run the script. What I get is an error message saying "Died at
read.pl line 5." (Line 5 being the one with the tie.)

Why is this happening? Why am I not getting anything in the $! variable?
Does DB_File work with different formats on Linux and Windows? Any
suggestions for addressing this, short of dumping the database on the
Linux box and rebuilding it on the Windows box?

Thanks,

Andras
 
G

Gunnar Hjalmarsson

Andras said:
I'm trying to read a database that I created using the DB_File module
on a Linux box and then transferred to a Windows box.

What I get is an error message saying "Died at read.pl line 5." (Line
5 being the one with the tie.)

Why is this happening? Why am I not getting anything in the $!
variable? Does DB_File work with different formats on Linux and
Windows?

As you can see in the DB_File docs

perldoc DB_File

there are more than one version of Berkeley DB.
Any suggestions for addressing this, short of dumping the database on
the Linux box and rebuilding it on the Windows box?

One possible solution might be to use SDBM_File on Linux and transfer
that database to Windows. SDBM_File is portable between those platforms.
 
M

Maxim

Andras said:
So now I FTP database.db and the second script over to my Windows box
and run the script. What I get is an error message saying "Died at
read.pl line 5." (Line 5 being the one with the tie.)

I've had similar problem with one filesystem. It looks like, BerkeleyDB
files are not very fond of moving. Try making db_dump and db_load'ing it
then. Worked for me.

Hope this helps a little.
 
A

Andras Malatinszky

One possible solution might be to use SDBM_File on Linux and transfer
that database to Windows. SDBM_File is portable between those platforms.


Thanks!
 
P

Paul Marquess

Andras Malatinszky said:
I'm trying to read a database that I created using the DB_File module on
a Linux box and then transferred to a Windows box. Here's a simplified
setup illustration of my problem:

First, on the Linux box I ran this script:

#!/usr/bin/perl -w
use strict;
use DB_File;

tie my %db, 'DB_File', 'database.db';

$db{'blue'}='azul';

untie %db;


As expected, it creates a file called database.db, and when I run this
script:

#!/usr/bin/perl -w
use strict;
use DB_File;

tie my %db, 'DB_File', 'database.db' or die $!;

print $db{'blue'};

untie %db;


I get the word "azul" printed on the screen as expected.

So now I FTP database.db and the second script over to my Windows box
and run the script. What I get is an error message saying "Died at
read.pl line 5." (Line 5 being the one with the tie.)

Why is this happening? Why am I not getting anything in the $! variable?
Does DB_File work with different formats on Linux and Windows? Any
suggestions for addressing this, short of dumping the database on the
Linux box and rebuilding it on the Windows box?

If compatible versions of Berkeley DB have been used to build DB_File on
both platforms, the database files are portable. In your case I would guess
that they aren't compatible.

Run this on the Linux box to see what version of Berkeley DB was used to
build DB_File

perl -e 'use DB_File; print qq{Berkeley DB ver $DB_File::db_ver\n}'

and this on the windows box

perl -e "use DB_File; print qq{Berkeley DB ver $DB_File::db_ver\n}"

If the version numbers are identical, your problem lies elsewhere (possibly
an ASCII FTP).

If they are different, then you need to know which versions of Berkeley DB
are compatible with each other. To find that out, run the dbinfo script that
comes with DB_File against the database file on your Linux box. This script
will tell you what versions of Berkeley DB can be used to access the
database file. Usage is

perl dbinfo database_file

Assuming you have incompatible versions of Berkeley DB, you options are

1. rebuild DB_File on one/both platforms to use the same version of Berkeley
DB.
2. use the db_dump/db_load utilities that come with Berkeley DB to dump and
load the database.


Paul
 
A

Andras Malatinszky

If compatible versions of Berkeley DB have been used to build DB_File on
both platforms, the database files are portable. In your case I would guess
that they aren't compatible.

Run this on the Linux box to see what version of Berkeley DB was used to
build DB_File

perl -e 'use DB_File; print qq{Berkeley DB ver $DB_File::db_ver\n}'

and this on the windows box

perl -e "use DB_File; print qq{Berkeley DB ver $DB_File::db_ver\n}"

If the version numbers are identical, your problem lies elsewhere (possibly
an ASCII FTP).

If they are different, then you need to know which versions of Berkeley DB
are compatible with each other. To find that out, run the dbinfo script that
comes with DB_File against the database file on your Linux box. This script
will tell you what versions of Berkeley DB can be used to access the
database file. Usage is

perl dbinfo database_file

Assuming you have incompatible versions of Berkeley DB, you options are

1. rebuild DB_File on one/both platforms to use the same version of Berkeley
DB.
2. use the db_dump/db_load utilities that come with Berkeley DB to dump and
load the database.


Paul

This was very helpful, thank you. There were indeed incompatible
versions of Berkeley DB, and after an upgrade I no longer have the problem.

Andras
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top