/[registar]/convert.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /convert.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by dpavlin, Tue Jun 19 10:10:48 2001 UTC revision 1.7 by dpavlin, Tue Jun 19 13:39:05 2001 UTC
# Line 82  sub Log { Line 82  sub Log {
82  }  }
83    
84  sub CondInsert {  sub CondInsert {
85          my @values=pop @_;      # chop last argument which is array          my $table = shift @_;
86          my ($table, $name, $key, $fields) = @_;          my $name = shift @_;
87          my $sql = "SELECT $name FROM $table WHERE ($name = $key)";          my $key = shift @_;
88          my $cnt = $pgdbh->do($sql);          my $fields = shift @_;
89          return 0 if ($cnt > 0);          my @values=@_;          # chop argument(s) are values array
90          return 0 if ($#values == 0);          my $sql = "SELECT count($name) FROM $table WHERE ($name = ?)";
91            my $sth = $pgdbh->prepare($sql);
92            my $ret = $sth->execute($key);
93            my ($cnt) = $sth->fetchrow_array();
94            return 0 if (!$cnt == 0);
95          my @valtpl;          my @valtpl;
96          for (my $i=0; $i<=$#values; $i++) { push @valtpl,"?" }          for (my $i=0; $i<=$#values; $i++) { push @valtpl,"?" }
97          $sql = "INSERT INTO $table $fields VALUES (".join(",",@valtpl).")";          $sql = "INSERT INTO $table $fields VALUES (".join(",",@valtpl).")";
98          my $sth = $pgdbh->prepare($sql);          $sth = $pgdbh->prepare($sql);
99          my $ret = $sth->execute(@values);          $ret = $sth->execute(@values);
100          my $err = $pgdbh->errstr;          my $err = $pgdbh->errstr;
101          print &Log("[$sql] [".join(",",@values)."]".$err) if ($err);          print &Log("[$sql] [".join(",",@values)."]".$err) if ($err);
102          return $ret;          return $ret;

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

  ViewVC Help
Powered by ViewVC 1.1.26