X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract.pm;h=099a2213dfd335af68a1a2211d8c1518ed602656;hb=a9e945083b11d3931b24c44a5f5cbc4d3345f014;hp=eb048d09b96d82ddcbb5e63509e53794426b77a3;hpb=ca4f826a37ccb5194b0b5b9b4190b4007d647d9c;p=dbsrgits%2FSQL-Abstract.git diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index eb048d0..099a221 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -368,10 +368,32 @@ sub update { my $options = shift; # first build the 'SET' part of the sql statement - my (@set, @all_bind); puke "Unsupported data type specified to \$sql->update" unless ref $data eq 'HASH'; + my ($sql, @all_bind) = $self->_update_set_values($data); + $sql = $self->_sqlcase('update ') . $table . $self->_sqlcase(' set ') + . $sql; + + if ($where) { + my($where_sql, @where_bind) = $self->where($where); + $sql .= $where_sql; + push @all_bind, @where_bind; + } + + if ($options->{returning}) { + my ($returning_sql, @returning_bind) = $self->_update_returning($options); + $sql .= $returning_sql; + push @all_bind, @returning_bind; + } + + return wantarray ? ($sql, @all_bind) : $sql; +} + +sub _update_set_values { + my ($self, $data) = @_; + + my (@set, @all_bind); for my $k (sort keys %$data) { my $v = $data->{$k}; my $r = ref $v; @@ -419,22 +441,9 @@ sub update { } # generate sql - my $sql = $self->_sqlcase('update') . " $table " . $self->_sqlcase('set ') - . join ', ', @set; - - if ($where) { - my($where_sql, @where_bind) = $self->where($where); - $sql .= $where_sql; - push @all_bind, @where_bind; - } + my $sql = join ', ', @set; - if ($options->{returning}) { - my ($returning_sql, @returning_bind) = $self->_update_returning($options); - $sql .= $returning_sql; - push @all_bind, @returning_bind; - } - - return wantarray ? ($sql, @all_bind) : $sql; + return ($sql, @all_bind); } # So that subclasses can override UPDATE ... RETURNING separately from @@ -478,7 +487,7 @@ sub delete { my $options = shift; my($where_sql, @bind) = $self->where($where); - my $sql = $self->_sqlcase('delete from') . " $table" . $where_sql; + my $sql = $self->_sqlcase('delete from ') . $table . $where_sql; if ($options->{returning}) { my ($returning_sql, @returning_bind) = $self->_delete_returning($options); @@ -2017,7 +2026,7 @@ The parameter default in case of a single L character is the quote character itself. When opening-closing-style quoting is used (L is an arrayref) -this parameter defaults to the B L. Occurences +this parameter defaults to the B L. Occurrences of the B L within the identifier are currently left untouched. The default for opening-closing-style quotes may change in future versions, thus you are B to specify the escape character @@ -2250,7 +2259,7 @@ module: =back -On failure returns C, on sucess returns a B reference +On failure returns C, on success returns a B reference to the original supplied argument. =over @@ -2308,7 +2317,7 @@ module: =back -On failure returns C, on sucess returns an B reference +On failure returns C, on success returns an B reference containing the unpacked version of the supplied literal SQL and bind values. =head1 WHERE CLAUSES