pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: mallah@trade-india.com
To: greg@turnstep.com
Cc: pgsql-admin@postgresql.org
Cc: mkoval01@sprintspectrum.com
Subject: Re: Perl DBI question
Date: Thu, 19 Jun 2003 00:58:28 +0530 (IST)
Message-ID: <1205.219.65.233.126.1055964508.squirrel@mail.trade-india.com> (raw)
In-Reply-To: <c4f81faedbd5cdb090c86bacf5fce16b@biglumber.com>
References: <480641561E05E94D9B6CCE1E39AA0300116792@PDAWB06C.ad.sprint.com>
	<c4f81faedbd5cdb090c86bacf5fce16b@biglumber.com>



setting RaiseError to true  is the way to go in DBI.
it catches most of the error and prints in apache error log.

if RaiseError = 1 one does not have to do the explicit
die after the connect even i think

regds
mallah,

>
> -----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-----
>
>
>
> ---------------------------(end of broadcast)--------------------------- TIP 7: don't forget to
> increase your free space map settings



-----------------------------------------
Get your free web based email at trade-india.com.
   "India's Leading B2B eMarketplace.!"
http://www.trade-india.com/





view thread (5+ messages)

Message-ID: <1205.219.65.233.126.1055964508.squirrel@mail.trade-india.com>
Permalink:  ../1205.219.65.233.126.1055964508.squirrel@mail.trade-india.com/
Also on:    postgresql.org/message-id/1205.219.65.233.126.1055964508.squirrel@mail.trade-india.com

 · 

reply

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: mallah@trade-india.com, greg@turnstep.com, mkoval01@sprintspectrum.com
  Subject: Re: Perl DBI question
  In-Reply-To: <1205.219.65.233.126.1055964508.squirrel@mail.trade-india.com>
  References: <480641561E05E94D9B6CCE1E39AA0300116792@PDAWB06C.ad.sprint.com> <c4f81faedbd5cdb090c86bacf5fce16b@biglumber.com> <1205.219.65.233.126.1055964508.squirrel@mail.trade-india.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