Re: AW: [GENERAL] Re: [HACKERS] TRANSACTIONS

From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: Zeugswetter Andreas SB <ZeugswetterA(at)wien(dot)spardat(dot)at>
Cc: "'kdebisschop(at)range(dot)infoplease(dot)com'" <kdebisschop(at)range(dot)infoplease(dot)com>, "'hackers(at)postgresql(dot)org'" <hackers(at)postgreSQL(dot)org>
Subject: Re: AW: [GENERAL] Re: [HACKERS] TRANSACTIONS
Date: 2000-02-24 10:46:38
Message-ID: Pine.GSO.3.96.SK.1000224134525.22930M-100000@ra
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Here is my example:

package Apache::Hits;

use strict;
use Apache::Constants qw(:common);

my ($sth_lock, $sth_upd, $sth_ins );

sub handler {
my $r = shift;
if ( $r->args() =~ /msg_id=(\d+)/o ) {
$HTML::Mason::Commands::dbs ||= My::DB->new(1);
my $dbh = $HTML::Mason::Commands::dbs->{dbh};
$sth_lock ||= $dbh->prepare("LOCK TABLE hits IN SHARE ROW EXCLUSIVE MODE");
$sth_upd ||= $dbh->prepare("UPDATE hits SET count=count+1,last_access=now() WHERE msg_id=?");
$sth_ins ||= $dbh->prepare("INSERT INTO hits (msg_id,count) VALUES (?, 1)");
$dbh->{AutoCommit} = 0;
my $success = 1;
$success &&= $sth_lock->execute();
$success &&= $sth_upd->execute( $1 );
$success &&= $sth_ins->execute( $1 ) if ( $success eq '0E0');
my $result = ($success ? $dbh->commit : $dbh->rollback);
unless ( $result ) {
$r->log_error("Unable to process transaction: ". $dbh->errstr ."\n");
}
}
return OK;
}

1;
__END__

On Thu, 24 Feb 2000, Zeugswetter Andreas SB wrote:

> Date: Thu, 24 Feb 2000 10:18:58 +0100
> From: Zeugswetter Andreas SB <ZeugswetterA(at)wien(dot)spardat(dot)at>
> To: "'kdebisschop(at)range(dot)infoplease(dot)com'"
<kdebisschop(at)range(dot)infoplease(dot)com>
> Cc: "'hackers(at)postgresql(dot)org'" <hackers(at)postgreSQL(dot)org>
> Subject: AW: [GENERAL] Re: [HACKERS] TRANSACTIONS
>
> > ========================= example =========================
> >
> > $dbh->{AutoCommit} = 0;
> > $dbh->do("CREATE TABLE tmp (a int unique,b int)");
> > while (<>){
> > if (/([0-9]+) ([0-9]+)/) {
> > $rtv = $dbh->do("INSERT INTO tmp VALUES ($1,$2)");
> > if ($rtv) {$dbh->do("UPDATE tmp SET b=$2 where a=$1")};
> > }
> > }
> > $dbh->commit;
> > $dbh->disconnect;
> >
> > ========================= end ============================
>
> This is a very good example, and is unfortunately currently not possible in
> PostgreSQL. But I am sure Vadim is on his way to fix that :-)
>
> Andreas
>
> ************
>

_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Oliver Elphick 2000-02-24 11:22:38 Re: [HACKERS] Out of memory problem (forwarded bug report)
Previous Message Zeugswetter Andreas SB 2000-02-24 09:18:58 AW: [GENERAL] Re: [HACKERS] TRANSACTIONS