--- convert.pl 2001/06/19 10:10:48 1.6 +++ convert.pl 2001/06/19 13:39:05 1.7 @@ -82,17 +82,21 @@ } sub CondInsert { - my @values=pop @_; # chop last argument which is array - my ($table, $name, $key, $fields) = @_; - my $sql = "SELECT $name FROM $table WHERE ($name = $key)"; - my $cnt = $pgdbh->do($sql); - return 0 if ($cnt > 0); - return 0 if ($#values == 0); + my $table = shift @_; + my $name = shift @_; + my $key = shift @_; + my $fields = shift @_; + my @values=@_; # chop argument(s) are values array + my $sql = "SELECT count($name) FROM $table WHERE ($name = ?)"; + my $sth = $pgdbh->prepare($sql); + my $ret = $sth->execute($key); + my ($cnt) = $sth->fetchrow_array(); + return 0 if (!$cnt == 0); my @valtpl; for (my $i=0; $i<=$#values; $i++) { push @valtpl,"?" } $sql = "INSERT INTO $table $fields VALUES (".join(",",@valtpl).")"; - my $sth = $pgdbh->prepare($sql); - my $ret = $sth->execute(@values); + $sth = $pgdbh->prepare($sql); + $ret = $sth->execute(@values); my $err = $pgdbh->errstr; print &Log("[$sql] [".join(",",@values)."]".$err) if ($err); return $ret;