re-arange transactions so that drop/create table work
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 22 Feb 2003 23:47:15 +0000 (23:47 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 22 Feb 2003 23:47:15 +0000 (23:47 +0000)
git-svn-id: file:///home/dpavlin/private/svn/webpac/trunk@19 13eb9ef6-21d5-0310-b721-a9d68796d827

index_DBI.pm

index 67886e2..08a922a 100644 (file)
@@ -31,15 +31,18 @@ sub delete_and_create {
 
        my $field = shift;
 
+#print "#### delete_and_create($field)\n";
+
        $self->{dbh}->commit;
-       $self->{dbh}->begin_work;
 
        my $sql = "select count(*) from $field";
        my $sth = $self->{dbh}->prepare($sql) || die $self->{dbh}->errstr();
 # FIX: this is not a good way to check if table exists!
        if ($sth->execute() && $sth->fetchrow_hashref) {
                my $sql = "drop table $field";
+               $self->{dbh}->begin_work;
                my $sth = $self->{dbh}->do($sql) || die "SQL: $sql ".$self->{dbh}->errstr();
+               $self->{dbh}->commit;
        }
        $sql = "create table $field (
                        item varchar(255),
@@ -48,9 +51,11 @@ sub delete_and_create {
                        ord int,
                        primary key (item,ident)
                )";
-       $sth = $self->{dbh}->do($sql); # || warn "SQL: $sql ".$self->{dbh}->errstr();
 
+       $self->{dbh}->begin_work;
+       $sth = $self->{dbh}->do($sql); # || warn "SQL: $sql ".$self->{dbh}->errstr();
        $self->{dbh}->commit;
+
        $self->{dbh}->begin_work;
 }