Re: Unable to run sample code from DBD::DBM on Strawberry Perl
- From: "jl_post@xxxxxxxxxxx" <jl_post@xxxxxxxxxxx>
- Date: Fri, 26 Feb 2010 12:08:55 -0800 (PST)
On Feb 26, 11:25 am, Steve C <smallp...@xxxxxxxx> wrote:
These are not perl errors, they are errors in your
understanding of how a database works. You can't
create a new table if a table already exists with
that name. If you don't want the old one, you need
to DROP it first.
I understand that. But the first time I run the script, there is
no database by the name 'user'. Therefore, it shouldn't be
complaining that the 'user' table already exists.
In fact, just to make sure, I went ahead and added "DROP TABLE
user;" to my script, just like you said (I also commented out the
'RaiseError' line), making it look like this:
use DBI;
my $dbh = DBI->connect('dbi:DBM:');
# $dbh->{RaiseError} = 1;
for my $sql( split /;\n+/,"
DROP TABLE user;
CREATE TABLE user ( user_name TEXT, phone TEXT );
INSERT INTO user VALUES ('Fred Bloggs','233-7777');
INSERT INTO user VALUES ('Sanjay Patel','777-3333');
INSERT INTO user VALUES ('Junk','xxx-xxxx');
DELETE FROM user WHERE user_name = 'Junk';
UPDATE user SET phone = '999-4444' WHERE user_name = 'Sanjay
Patel';
SELECT * FROM user
"){
my $sth = $dbh->prepare($sql);
$sth->execute;
$sth->dump_results if $sth->{NUM_OF_FIELDS};
}
$dbh->disconnect;
Now when I run the script, I see:
Execution ERROR: Table 'user' already exists..
DBD::DBM::st execute failed: Can't call method "column" on an
undefined value at C:/strawberry/perl/site/lib/SQL/Statement/Term.pm
line 190.
[for Statement " DELETE FROM user WHERE user_name = 'Junk'"] at
dbi_dbm.pl line 15.
Execution ERROR: Column 'phone' not known in any table called from C:/
strawberry/perl/site/lib/DBD/File.pm at 446.
Execution ERROR:
Execution ERROR: Column 'phone' not known in any table called from C:/
strawberry/perl/site/lib/DBD/File.pm at 446.
called from dbi_dbm.pl at 15.
Execution ERROR:
Execution ERROR:
Execution ERROR: Column 'phone' not known in any table called from C:/
strawberry/perl/site/lib/DBD/File.pm at 446.
called from dbi_dbm.pl at 15.
..
undef, undef
undef, undef
undef, undef
3 rows
Notice that the Execution ERROR stating that table 'user' already
exists is still reported. I don't think it's my understanding that's
in error here. (Especially since the example script (as shown in
"perldoc DBD::DBM") worked just fine for time the first time I ran it
in Linux.)
(What I'm trying to say is, if "DROP TABLE user;" was required to
run the example the first time, then the perldocs would have given a
faulty script by not including that line.)
Why do you think deleting the files is the right thing to do?
If you want to use a database, learn how first. Don't just guess.
Because when I ran the script it created those three new files,
each beginning with "user". That's consistent with what I know of DBM
databases, in that the DBM data is stored in files beginning with the
database name. (At least, that's the behavior I've seen with all the
DBM databases I've tinkered with.)
But if you have a concrete example that contradicts mine, please
show it to me. I mentioned that I deleted the "user*" files to
indicate that I shouldn't have any DBM files hanging around that begin
with "user". But if the table already exists because it's stored in
some other file (thus proving my assumption false), I'd definitely
like to know.
The fact that I could see the inserted data (with a hex editor) in
the "user.pag" file seems to reinforce my assumption.
But if you can prove my assumption wrong (which is that the
database data is held in the "user*" files), please do so! I would
appreciate having that false assumption corrected (if it is indeed
false).
Cheers,
-- Jean-Luc
.
- Follow-Ups:
- References:
- Unable to run sample code from DBD::DBM on Strawberry Perl
- From: jl_post@xxxxxxxxxxx
- Re: Unable to run sample code from DBD::DBM on Strawberry Perl
- From: Steve C
- Unable to run sample code from DBD::DBM on Strawberry Perl
- Prev by Date: Re: OT, blowing off steam
- Next by Date: Re: Unable to run sample code from DBD::DBM on Strawberry Perl
- Previous by thread: Re: Unable to run sample code from DBD::DBM on Strawberry Perl
- Next by thread: Re: Unable to run sample code from DBD::DBM on Strawberry Perl
- Index(es):
Relevant Pages
|