From: greg@turnstep.com
To: pgsql-admin@postgresql.org
Cc: mkoval01@sprintspectrum.com
Subject: Re: Perl DBI question
Date: Wed, 18 Jun 2003 17:47:59 -0000
Message-ID: <c4f81faedbd5cdb090c86bacf5fce16b@biglumber.com> (raw)
In-Reply-To: <480641561E05E94D9B6CCE1E39AA0300116792@PDAWB06C.ad.sprint.com>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
You should not be using the "do" method, but the prepare/execute model
instead. Using placeholders can not only be more efficient but allows
quoting to happen properly. Here is a rewrite:
#--Establish the DB connection
#--Assign the DB name
my $dbName = 'checkbook';
my $dbuser = "joe";
my $dbpass = "sixpak";
my $dbh = DBI->connect("dbi:Pg:dbname=$dbName", $dbuser, $dbpass, {AutoCommit=>1, RaiseError=>1})
or die "Could not connect to the database: $DBI::errstr\n";
my $SQL = "
INSERT INTO transactions (date,description,amount,confirmation,nameid,typeid)
VALUES (? ,? ,? ,? ,? ,? )";
my $sth = $dbh->prepare($SQL);
my $count = $sth->execute($datePaid,$description,$amount, $confirmation,$nameid,$typeid);
print "Insert count: $count\n";
It is hard to tell why your inserts are going wrong without more information, but
the RaiseError should at least help catch some obvious errors.
- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200306181337
-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html
iD8DBQE+8KUHvJuQZxSWSsgRAhWoAJ9/aw9AaCMa5vGvEpvujEEBm4iBXQCggSSw
jPaGcdMt9Qq9XeJqttvdX48=
=x1nu
-----END PGP SIGNATURE-----
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: greg@turnstep.com, mkoval01@sprintspectrum.com
Subject: Re: Perl DBI question
In-Reply-To: <c4f81faedbd5cdb090c86bacf5fce16b@biglumber.com>
References: <480641561E05E94D9B6CCE1E39AA0300116792@PDAWB06C.ad.sprint.com> <c4f81faedbd5cdb090c86bacf5fce16b@biglumber.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox