Thingy now has a copy thing data option.
This commit is contained in:
parent
55da5c6889
commit
1cc87c159b
3 changed files with 97 additions and 1 deletions
|
|
@ -110,6 +110,43 @@ sub definition {
|
|||
return $class->SUPER::definition($session,$definition);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 copyCollateral ( tableName, keyName, keyValue )
|
||||
|
||||
Copies a row of collateral data where keyName=keyValue. Generates a new key for keyName.
|
||||
|
||||
=head3 tableName
|
||||
|
||||
The name of the table you wish to copy the data from.
|
||||
|
||||
=head3 keyName
|
||||
|
||||
The name of a column in the table. Is not checked for invalid input.
|
||||
|
||||
=head3 keyValue
|
||||
|
||||
Criteria (value) used to find the data to copy.
|
||||
|
||||
=cut
|
||||
|
||||
sub copyCollateral {
|
||||
my $self = shift;
|
||||
my $table = shift;
|
||||
my $keyName = shift;
|
||||
my $keyValue = shift;
|
||||
my $db = $self->session->db;
|
||||
my $newId = $self->session->id->generate;
|
||||
|
||||
my $temp = $self->session->db->buildArrayRefOfHashRefs(
|
||||
"select * from ".$db->dbh->quote_identifier($table)." where ".$db->dbh->quote_identifier($keyName)."=".$db->quote($keyValue));
|
||||
my $hash = $temp->[0];
|
||||
$hash->{$keyName} = $newId;
|
||||
my @keys = keys %$hash;
|
||||
my $sql = "insert into ".$db->dbh->quote_identifier($table)
|
||||
." (".join(',',map("`$_`",@keys)).") values(".join(',',map("?",@keys)).")";
|
||||
$self->session->db->write($sql,[map($hash->{$_},@keys)]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue