From ad88c37581b39c4e291853a0fac13bfed6fc8df4 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 6 May 2010 20:48:39 -0700 Subject: [PATCH] Revert back to the old setRow that handles sparse updates, like the one used by Group. --- lib/WebGUI/SQL.pm | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/WebGUI/SQL.pm b/lib/WebGUI/SQL.pm index dadc180a4..6f1f6fd00 100644 --- a/lib/WebGUI/SQL.pm +++ b/lib/WebGUI/SQL.pm @@ -961,24 +961,28 @@ Use this ID to create a new row. Same as setting the key value to "new" except t =cut sub setRow { - my ($self, $table, $keyColumn, $data, $id) = @_; - if ($data->{$keyColumn} eq "new" || $id) { - $data->{$keyColumn} = $id || $self->session->id->generate(); - } - my $dbh = $self->dbh; - my @fields = (); - my @data = (); - my @placeholders = (); - foreach my $key (keys %{$data}) { - push(@fields, $dbh->quote_identifier($key)); - push(@placeholders, '?'); - push(@data,$data->{$key}); - } - $self->write("replace into $table (" . join(",",@fields) . ") values (".join(",",@placeholders).")",\@data); - return $data->{$keyColumn}; + my ($self, $table, $keyColumn, $data, $id) = @_; + if ($data->{$keyColumn} eq "new" || $id) { + $data->{$keyColumn} = $id || $self->session->id->generate(); + $self->write("replace into ".$self->dbh->quote_identifier($table) + ." (" . $self->dbh->quote_identifier($keyColumn) . ") values (?)",[$data->{$keyColumn}]); + } + my @fields = (); + my @data = (); + foreach my $key (keys %{$data}) { + unless ($key eq $keyColumn) { + push(@fields, $self->dbh->quote_identifier($key).'=?'); + push(@data,$data->{$key}); + } + } + if ($fields[0] ne "") { + push(@data,$data->{$keyColumn}); + $self->write("update ".$self->dbh->quote_identifier($table)." set " . join(", ", @fields) + . " where " . $self->dbh->quote_identifier($keyColumn) . "=?", \@data); + } + return $data->{$keyColumn}; } - #------------------------------------------------------------------- =head2 unconditionalRead ( sql [, placeholders ] )