in reply to Re: Can SQL be used without a database?
in thread Can SQL be used without a database?
I can vouch for DBD::SQLite. It rocks. :) The first hurdle with SQLite is the fact that you have to have an egg before you can have chickens. What i mean is that you first have to write a script that creates (and then optionally populates) the database file. Something as trivial as:
However, you may notice from the code that i am supplying the ID. I do not think that SQLite offers auto-incremented ID's for you.use DBI; use Data::Dumper; my $dbh = DBI->connect( 'dbi:SQLite:dbname=dbfile','','', # { RaiseError => 1}, ); eval { $dbh->do('drop table foo'); $dbh->do('create table foo(id int unsigned, name char(64))'); }; my $sth = $dbh->prepare('insert into foo values (?,?)'); $sth->execute(@$_) for [1,'moe'],[2,'curly'],[3,'larry']; print Dumper $dbh->selectall_arrayref('select * from foo');
Alternatively, if you already have your data stored in another format, check out SQL Fairy before you roll your own.
UPDATE:
That's right ... thanks for pointing out my error (once again!) merlyn. :)
Here is are updated lines for the snippet above:
Much better. ;)$dbh->do('create table foo(id integer primary key, name char(64))'); my $sth = $dbh->prepare('insert into foo(name) values (?)'); $sth->execute($_) for qw(moe curry lary);
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
---|
Replies are listed 'Best First'. | |
---|---|
•Re: 2Re: Can SQL be used without a database?
by merlyn (Sage) on Dec 30, 2003 at 20:03 UTC | |
by lachoy (Parson) on Dec 30, 2003 at 22:22 UTC |
In Section
Seekers of Perl Wisdom