summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorkhoff <khoff>2003-04-24 18:46:36 +0000
committerkhoff <khoff>2003-04-24 18:46:36 +0000
commitcc6317796afe74fd6dcbc4712abfcb09ff199598 (patch)
treef34acd63ada5fc04365a3277e128d302b12d8460 /FS
parentfdf62da26a4a9127fd43f359163f231a89bc692d (diff)
MySQL returns zero on an update when no values change. We would insert on an rv of zero, so now we select count(*)... instead of relying on the rv of the update.
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/part_export/sqlmail.pm16
1 files changed, 9 insertions, 7 deletions
diff --git a/FS/FS/part_export/sqlmail.pm b/FS/FS/part_export/sqlmail.pm
index f97674c27..64f72df07 100644
--- a/FS/FS/part_export/sqlmail.pm
+++ b/FS/FS/part_export/sqlmail.pm
@@ -115,17 +115,19 @@ sub sqlmail_replace {
my %attrs = @_;
map { $attrs{$_} = $attrs{$_} ? qq!'$attrs{$_}'! : 'NULL'; } keys(%attrs);
- my $query = sprintf('UPDATE %s SET %s WHERE svcnum = %s',
- $table, join(', ', map {"$_ = $attrs{$_}"} keys(%attrs)),
- $oldsvcnum);
-
- my $rv = $dbh->do($query) or die $dbh->errstr;
-
- if ($rv == 0) {
+ my $query = "SELECT COUNT(*) FROM $table WHERE svcnum = $oldsvcnum";
+ my $result = $dbh->selectrow_arrayref($query) or die $dbh->errstr;
+
+ if (@$result[0] == 0) {
$query = sprintf("INSERT INTO %s (%s) values (%s)",
$table, join(",", keys(%attrs)),
join(',', values(%attrs)));
$dbh->do($query) or die $dbh->errstr;
+ } else {
+ $query = sprintf('UPDATE %s SET %s WHERE svcnum = %s',
+ $table, join(', ', map {"$_ = $attrs{$_}"} keys(%attrs)),
+ $oldsvcnum);
+ $dbh->do($query) or die $dbh->errstr;
}
$dbh->disconnect;