273a274,332
> sub replace {
>   my $self  = shift;
>   my $table = $self->_table(shift);
>   my $data  = shift;
>   my $where = shift;
> 
>   return if ( ! defined $data && $data );
> 
>   # first build the 'SET' part of the sql statement
>   my (@set, @all_bind);
>   puke "Unsupported data type specified to \$sql->replace"
>     unless ref $data eq 'HASH';
> 
>   for my $k (sort keys %$data) {
>     my $v = $data->{$k};
>     my $r = ref $v;
>     my $label = $self->_quote($k);
> 
>     $self->_SWITCH_refkind($v, {
>       ARRAYREF => sub { 
>         if ($self->{array_datatypes}) { # array datatype
>           push @set, "$label = ?";
>           push @all_bind, $self->_bindtype($k, $v);
>         }
>         else {                          # literal SQL with bind
>           my ($sql, @bind) = @$v;
>           $self->_assert_bindval_matches_bindtype(@bind);
>           push @set, "$label = $sql";
>           push @all_bind, @bind;
>         }
>       },
>       ARRAYREFREF => sub { # literal SQL with bind
>         my ($sql, @bind) = @${$v};
>         $self->_assert_bindval_matches_bindtype(@bind);
>         push @set, "$label = $sql";
>         push @all_bind, @bind;
>       },
>       SCALARREF => sub {  # literal SQL without bind
>         push @set, "$label = $$v";
>        },
>       SCALAR_or_UNDEF => sub {
>         push @set, "$label = ?";
>         push @all_bind, $self->_bindtype($k, $v);
>       },
>     });
>   }
> 
>   # generate sql
>   my $sql = $self->_sqlcase('replace') . " $table " . $self->_sqlcase('set ')
>           . join ', ', @set;
> 
>   if (defined $where && $where) {
>     my($where_sql, @where_bind) = $self->where($where);
>     $sql .= $where_sql;
>     push @all_bind, @where_bind;
>   }
> 
>   return wantarray ? ($sql, @all_bind) : $sql;
> }
1134a1194,1195
>     
>     my($stmt, @bind) = $sql->replace($table, \%fieldvals, \%where);
1245a1307,1315
> Finally, a REPLACE is handled in exactly the same way and you can just as easily
> generate the SQL for one:
> 
>    my($stmt, @bind) = $sql->replace('people', \%data, \%where);
> 
> A REPLACE works in the same way as an UPDATE with the only difference that
> if existing rows in the table that match the C<%where> clause get deleted
> first.
> 
1494a1565,1573
> =head2 replace($table, \%fieldvals, \%where)
> 
> This takes a table, hashref of field/value pairs, and an optional
> hashref L<WHERE clause|/WHERE CLAUSES>. It returns an SQL REPLACE function and a list
> of bind values.
> See the sections on L</"Inserting and Updating Arrays"> and
> L</"Inserting and Updating SQL"> for information on how to insert
> with those data types.
> 
2267a2347
>     Spiros Denaxas (patch for "REPLACE" support)
