fixed to work with constraints

This commit is contained in:
JT Smith 2009-10-20 15:01:01 -05:00
parent 5750a6352f
commit acf8e7816d
2 changed files with 30 additions and 23 deletions

View file

@ -944,23 +944,20 @@ Use this ID to create a new row. Same as setting the key value to "new" except t
sub setRow {
my ($self, $table, $keyColumn, $data, $id) = @_;
if ($data->{$keyColumn} eq "new" || $id) {
$data->{$keyColumn} = $id || $self->session->id->generate();
$self->write("replace into $table (" . $self->dbh->quote_identifier($keyColumn) . ") values (?)",[$data->{$keyColumn}]);
$data->{$keyColumn} ||= $id;
if ($data->{$keyColumn} eq "new") {
$data->{$keyColumn} = $self->session->id->generate();
}
my $dbh = $self->dbh;
my @fields = ();
my @data = ();
my @placeholders = ();
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 $table set " . join(", ", @fields)
. " where " . $self->dbh->quote_identifier($keyColumn) . "=?", \@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};
}