last non-DBI attempt - reading MS Access .ldb (locked db file) with Perl

From: Frank A Willis (frank.a.willis_at_lmco.com)
Date: 03/16/05


Date: Wed, 16 Mar 2005 14:47:05 -0500
To: dbi-users@perl.org



DBI users group,

 

I've made one last attempt at looking for a way to read and parse out an
(MS Access) .ldb (locked database) file independent of using the DBI.
One suggestion that I received today was to split the contents of my
buffer ($buf) up using the split command as follows:

 

------------------------------------------------------------------------
------------------------------------------------------------------------
-------------------

#!/usr/local/bin/perl -w

#this command opens the .ldb file

open(odbfile_in,"+<ANYFILE.LDB") || die("Could not open file!");

# this section contains properties of the open .odb file

my
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blks
ize,$blocks)=stat(odbfile_in);

print "\nfile size (bytes) =",$size,"\n";

sysread(odbfile_in,$buf,$size);

@first_array=split(/x00/,$buf);
@second_array=split(/x00+/,@first_array);
print @second_array;

close(odbfile_in);

 

The above script assumes that the .ldb file is in a hexadecimal format
as follows:

 

43 4F 4D 50 55 54 45 52 4E 41 4D 45 30 31 00 20 ; FIELDNAME.
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
55 53 45 52 4E 41 4D 45 20 20 20 30 31 00 00 00 ; FIELDVALUE 01...
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................

 

However, if I just read the file with sysread(odbfile_in,$buf,$size);
and print the contents of the buffer using print $buf; I get the output
below:

 

Version:wsX.X-XXXSource File:
Filenamews>Date/Time:wsM-D-YYwsatwsHH:MM:SS(c)NextField:wsTextCount:wsIn
teger ValuewsNextField:wsText NextField:wsText
AddressField:wsHexadecimalwsCount:wsIntegerwsType: Integer ... the
sequence repeats itself not including Version, Source File, and
Date/Time fields, i.e., NextField, NextField, NextField, AddressField,
Count, Type, NextField, NextField, NextField, AddressField, Count, Type,
...

 

Key: ws = whitespace characters (one or more)

        Bold = Field Names w/Colon (FieldName: )

        (c) = Marks where the non-header part of the file starts

 

Is there any way to do this by just using printf, split, and other
output formatting commands or am I better off using the DBI? I'm going
to try the AnyData::Format::Paragraph module tonight and see what
success I can have with it.

 

Thanks for the helpful reply posts!

 

 

 

Frank Willis

F/A-22 Avionics Engineer

Lockheed-Martin Aeronautics Company

Building L-11, 2nd Floor, Area "F", MZ 0033

86 South Cobb Drive

Marietta, GA 30063

Phone: 770-494-9023

Fax: 770-494-5284

 

 




image001.gif

Relevant Pages

  • Re: Datetime overflow with DBI ODBC setting 19th century dates with placeholders
    ... > The command line utility only allows you to use complete SQL DML ... > former works fine for 1899 with perl DBI anyway. ... > I've also tried the SQL Server profiler on the server side, ... In this way, you're defining what the data type is for the database, not ...
    (comp.lang.perl.misc)
  • Antwort: Re: Field terminated by
    ... I think the "load" command is not a valid SQL-command. ... So it can't be used via DBI. ... load data local infile "orders.txt" ...
    (perl.dbi.users)
  • Re: grep a csv?
    ... I'd load it into a database (assuming your database ... that is) and then hook up to it with DBI. ... and i wanna avoid using command line to do this, ... I don't know if it's relevant to your dataset, but CSV ...
    (comp.lang.ruby)
  • Re: grep a csv?
    ... I'd load it into a database (assuming your database ... that is) and then hook up to it with DBI. ... and i wanna avoid using command line to do this, ... I don't know if it's relevant to your dataset, but CSV ...
    (comp.lang.ruby)
  • Re: grep a csv?
    ... and i wanna avoid using command line to do this, because yes in fact this will be used to process more than one datafile which i hope to setup in optparse to have a command line arg that directs the prog to the file. ... also i wanted to for the meantime not have to throw it on any database...avoiding DBI for the meanwhile. ... I don't know if it's relevant to your dataset, but CSV fields are allowed to contain newlines if the field is quoted. ... this single CSV row will break your process: ...
    (comp.lang.ruby)