From 0c601b73125d1bc120e248149bf4d83ecc27f1c2 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Tue, 8 Apr 2008 11:19:34 +0000 Subject: * Removing lulurun's perl UGAI from core svn, pending a link to an external repository, as per mailing list discussion. --- share/perl/lib/DBHandler.pm | 119 -------------------------------------------- 1 file changed, 119 deletions(-) delete mode 100644 share/perl/lib/DBHandler.pm (limited to 'share/perl/lib/DBHandler.pm') diff --git a/share/perl/lib/DBHandler.pm b/share/perl/lib/DBHandler.pm deleted file mode 100644 index 1435ba2..0000000 --- a/share/perl/lib/DBHandler.pm +++ /dev/null @@ -1,119 +0,0 @@ -use strict; -use DBI; -use Carp; - -package DBHandler; - -#our $dbh = undef; -use vars qw ($DB_CONNECTION); - -sub getConnection { - my ($dsn, $user, $pass) = @_; - #return $DB_CONNECTION if ($DB_CONNECTION); - $DB_CONNECTION = DBI->connect($dsn, $user, $pass); - $DB_CONNECTION->{AutoCommit} = 1; - $DB_CONNECTION->{RaiseError} = 1; - return $DB_CONNECTION; -} - -# ############# -# Simple statement -package Statement; - -sub new { - my ( $this, $dbh, $sql, $is_trans ) = @_; - # @@@ sql should be tested OK, so here just die - my $sth = $dbh->prepare($sql) || Carp::croak( $dbh->errstr ); - my %fields = ( - dbh => $dbh, - sql => $sql, - sth => $sth, - is_trans => $is_trans, - ); - return bless \%fields, $this; -} - -sub exec { - my ( $this, @param ) = @_; - my $dbh = $this->{dbh}; - my $sth = $this->{sth}; - my $sql = $this->{sql}; - - if ( !$sth->execute(@param) ) { - if ( $this->{is_trans} ) { - $dbh->rollback(); - } - Carp::croak( $dbh->errstr ); - } - my @ret = (); - if ( $sql =~ /^select/i ) { - # @@@ get result object - while ( my $res = $sth->fetchrow_hashref() ) { - push @ret, $res; - } - } - # @@@ $sth->finish(); - return \@ret; -} - -sub last_id { - my $this = shift; - my $dbh = $this->{dbh}; - return $dbh->last_insert_id(undef, undef, undef, undef); -} - -sub DESTROY { - my $this = shift; - my $sth = $this->{sth}; - $sth->finish(); -} - -# ############# -# Transaction -package Transaction; - -my $IS_TRANS = 1; - -sub new { - my ( $this, $dbh ) = @_; - # @@@ fatal error, just die - $dbh->begin_work() || Carp::croak( $dbh->errstr ); - my %fields = ( - dbh => $dbh, - Active => 1, - ); - return bless \%fields, $this; -} - -sub createStatement { - my ( $this, $sql) = @_; - # @@@ fatal error, just die - Carp::croak("transaction not begin") if ( !$this->{Active} ); - my $dbh = $this->{dbh}; - return new Statement($dbh, $sql, $IS_TRANS); -} - -sub commit { - my $this = shift; - my $dbh = $this->{dbh}; - if ( $this->{Active} && !$dbh->{AutoCommit} ) { - $dbh->commit || Carp::croak( $dbh->errstr ); - } - $this->{Active} = 0; -} - -sub rollback { - my $this = shift; - my $dbh = $this->{dbh}; - if ( $this->{Active} && !$dbh->{AutoCommit} ) { - $dbh->rollback || Carp::croak( $dbh->errstr ); - } - $this->{Active} = 0; -} - -sub DESTROY { - my $this = shift; - $this->rollback; -} - -1; -- cgit v1.1