pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrei Bintintan <klodoma@ar-sd.net>
To: Stef <svb@ucs.co.za>
To: pgsql-sql@postgresql.org
Subject: Re: Exceptions when 0 rows affected.
Date: Tue, 11 May 2004 09:02:19 +0300
Message-ID: <007001c4371d$8560f640$0b00a8c0@forge> (raw)
References: <20040510150808.7ea12c06@svb.ucs.co.za>

Hi Stef,

Your problem depends on what interface/programming language you're using.
In a Begin End transaction you will have to verify if the returned data is
good for you so then you decide if you run at the end "COMMIT" or
"ROLLBACK".

In php (and where is compatible) I suggest this:

//this is php code:

$error = false;
dbExec("BEGIN");

//I use a switch statement so I can jump out of it with a break at any time
switch (1){
case 1:
    ...
    $sql = "Insert....";
    if (!dbExec($sql)) {$error = true; break;}//was an error?? we jump out
from switch
    ...
    $sql = "Select ....";
    if (!dbExec($sql)) {$error = true; break;}
    ...
    $sql = "Update....";
    if (!dbExec($sql)) {$error = true; break;}
    ...
}//switch

if ($error) dbExec("ROLBACK"); //an error ocured
else dbExec("COMMIT");//there was no error

Hope this helps.

Best regards,
Andy.

----- Original Message -----
From: "Stef" <svb@ucs.co.za>
To: <pgsql-sql@postgresql.org>
Sent: Monday, May 10, 2004 4:08 PM
Subject: [SQL] Exceptions when 0 rows affected.

Hi all,

I've been looking on Google,the archives and documentation,
but cannot find what I'm looking for. Maybe I've read the
answer, but it's still evading me.

I'm working with postgres 7.3.4 using the psql client.

I want to know if it's possible to raise an error in a
transactional BEGIN->END block when e.g. an update
or delete statement affects zero rows.

I want the entire transaction block to rollback when
this happens. I can do it in perl and java , but would
in this instance like to load a file with SQL statements
using psql -f . Is it possible?

Kind Regards
Stefan






view thread (3+ messages)  latest in thread

Message-ID: <007001c4371d$8560f640$0b00a8c0@forge>
Permalink:  ../007001c4371d$8560f640$0b00a8c0@forge/
Also on:    postgresql.org/message-id/007001c4371d$8560f640$0b00a8c0@forge

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: klodoma@ar-sd.net, svb@ucs.co.za
  Subject: Re: Exceptions when 0 rows affected.
  In-Reply-To: <007001c4371d$8560f640$0b00a8c0@forge>

* 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