=over 4
- $data_id_in_table = &InsertInTable($tablename,$data_hashref);
+ $data_id_in_table = &InsertInTable($tablename,$data_hashref,$withprimarykeys);
=back
=cut
sub InsertInTable{
- my ($tablename,$data) = @_;
+ my ($tablename,$data,$withprimarykeys) = @_;
my $dbh = C4::Context->dbh;
- my ($keys,$values)=_filter_hash($tablename,$data,0);
+ my ($keys,$values)=_filter_hash($tablename,$data,($withprimarykeys?"exact":0));
my $query = qq{ INSERT INTO $tablename SET }.join(", ",@$keys);
$debug && warn $query, join(",",@$values);
push @tmpkeys, " $field = ? ";
push @values, $operand;
#By default, exact search
- unless ($searchtype){
+ if (!$searchtype ||$searchtype eq "exact"){
return \@tmpkeys,\@values;
}
my $col_field=(index($field,".")>0?substr($field, index($field,".")+1):$field);
use C4::Debug;
use C4::SQLHelper qw(:all);
-use Test::More tests => 18;
+use Test::More tests => 19;
#1
BEGIN {
use C4::Category;
use C4::Branch;
my @categories=C4::Category->all;
+my $insert;
+ok(($insert=InsertInTable("branches",{branchcode=>"ZZZZ",branchname=>"Brancheinconnue",city=>" ",zipcode=>" "},1))==0,"AddBranch (Insert In Table with primary key defined)");
my $branches=C4::Branch->GetBranches;
my @branchcodes=keys %$branches;
my ($borrid, $borrtmp);