Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

DBI modules for database representation in plain files

by filipe (Novice)
on Feb 25, 2004 at 16:32 UTC ( [id://331702]=perlquestion: print w/replies, xml ) Need Help??

filipe has asked for the wisdom of the Perl Monks concerning the following question:

Hello All.

I'm implementing a cgi to store and classify links form users. Because it will run on a remote machine where i don't have access i've decided to simplify the life of the person running the script and use plain files instead. So i've looked up CPAN and found DBD::CVS, DBD::AnyData and DBD::Sprite. But all have penaltys in performance.

Well, i know i should use some relational database like mysql, postgress, ... but is there any way of combining DBI abstract interface with MLDBM alike files?

Thanks in advance

Filipe

update (broquaint): tidied up formatting

  • Comment on DBI modules for database representation in plain files

Replies are listed 'Best First'.
Re: DBI modules for database representation in plain files
by perrin (Chancellor) on Feb 25, 2004 at 16:39 UTC
    Did you consider DBD::SQLite?
      I second this. I use DBD::SQLite with DBI all the time, and have found it to be an excellent solution in every application I've had for it. Certanly there will be times that more traditional databases are required, but I haven't found that time yet.

      From the DBD::SQLite POD:

      SQLite is fast, very fast.

      It is! It is also happens to be a complete RDBMS database engine wrapped in one convenient module.


      Dave

        davido,
        It is also happens to be a complete RDBMS database engine

        That is a bit misleading since some people would argue that the omitted SQL Features make it incomplete. Since I have very limited db experience, I am not going to make that case. I like SQLite very much and have used it on at least 3 projects now. I also here there may be locking issues with too many concurrent updates. I guess someone deciding what to use knows their own requirements well enough to know if SQLite is right for the job.

        Cheers - L~R
      Yes.

      I've forgot two say that here i would prefer a PURE PERL that is no external code to compile.
      so any DB file type that comes bundled with perl distrib. would be great.

      Thanks
      Filipe
        Well, by limiting yourself in this way you are basically stuck with either MLDBM (using GDBM or DB_File), or one of the text-based things you mentioned. If you really think performance is going to be a big issue, use MLDBM. If you can't live without SQL support and still need performance, you have to bite the bullet and get a real database.

        What is nice about compiling DBD::SQLite is that all the code is contained in the dist. A lot easier than installing mysql, postgresql, ...etc. I have installed on a variety of *nixes without any problems. I'm sure you are aware of this, just my 2 cents.

        sth

Re: DBI modules for database representation in plain files
by xdg (Monsignor) on Feb 25, 2004 at 18:13 UTC

    Check out DBD::SQLite -- it's relational, it uses plain files and it's fast. It's also typeless, so essentially you just have to use Storeable to freeze/thaw your data into a field in the table. Another option might be to try using Class::DBI which gives you a nice relational data abstraction layer with DBD::SQLite as the data storage mechanism.

    -xdg

    Code posted by xdg on PerlMonks is public domain. It has no warranties, express or implied. Posted code may not have been tested. Use at your own risk.

Re: DBI modules for database representation in plain files
by jZed (Prior) on Feb 25, 2004 at 19:21 UTC
    Have you actually tested the penalties in performance? Depending on the size and complexity of your data, they may not be relevant.

    I second all the other recommendations of SQLite, it rocks. However it is not pure perl and it does not create cross-platform, human readable data files.

    P.S. I will be releasing a pure perl DBD::DBM soon but it is too early to say how it will compare performance-wise with the others. Obviously its files won't be cross-platform or human readable, but it should work anywhere that perl works with SDBM that comes with perl or with other DBMs if they are available.

      That's sound wounderfull :=) Would it also interface with DB_files and MLDBM?
      i've finally put the DBD::SQlite working. i've created a few tables, a unique index but i got one concern
      how can i limit the data to fit in a standard SQl type:like info char(32) i've run a small test and i don't get a data limit.
      #!/usr/bin/perl -w use strict; use warnings; use DBI; use DBD::SQLite; my $dbh = DBI->connect("dbi:SQLite:dbname=foo", "", "", {AutoCommit => + 1, RaiseError => 1}); $dbh->do("CREATE TABLE info (f1 char(3) primary KEY, f2 char(3), f3 ch +ar(3))"); $dbh->do('create unique index info_idx on info (f1)'); my $sth = $dbh->prepare("INSERT INTO info VALUES (?, ?, ?)"); $sth->execute("Fred", "Bloggs", "fred\@bloggs.com"); $sth = $dbh->prepare("SELECT * FROM info"); $sth->execute(); while (my @row = $sth->fetchrow_array ) { print "@row\n"; } $dbh->disconnect;
      this get Fred", "Bloggs", "fred\@bloggs.com". So i must assume that DBD::SQLite don't test for type size?
      sure i can count the data size each time i insert them into the database but would prefer that SQLite ensures
      that i don't forget about it... Any hint if i can get a free lunch here?

      Thanks for all the help here and thanks in advance for all the forthcomming one.
      Filipe

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://331702]
Front-paged by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-23 14:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found