Lines 848-883
sub _import_table
Link Here
|
848 |
# Insert/Update the row from the spreadsheet in the database |
848 |
# Insert/Update the row from the spreadsheet in the database |
849 |
sub _processRow_DB |
849 |
sub _processRow_DB |
850 |
{ |
850 |
{ |
851 |
my ($dbh, $db_scheme, $table, $fields, $dataStr, $updateStr, $dataFields, $dataFieldsHash, $PKArray, $fieldsPK, $fields2Delete) = @_; |
851 |
my ($dbh, $table, $fields, $dataStr, $updateStr, $dataFields, $dataFieldsHash, $PKArray, $fieldsPK, $fields2Delete) = @_; |
852 |
|
852 |
|
853 |
my $ok = 0; |
853 |
my $ok = 0; |
854 |
my $query; |
854 |
my $query; |
855 |
if ($db_scheme eq 'mysql') { |
855 |
$query = 'INSERT INTO ' . $table . ' (' . $fields . ') VALUES (' . $dataStr . ') ON DUPLICATE KEY UPDATE ' . $updateStr; |
856 |
$query = 'INSERT INTO ' . $table . ' (' . $fields . ') VALUES (' . $dataStr . ') ON DUPLICATE KEY UPDATE ' . $updateStr; |
|
|
857 |
} else { |
858 |
$query = 'INSERT INTO ' . $table . ' (' . $fields . ') VALUES (' . $dataStr . ')'; |
859 |
} |
860 |
eval { |
856 |
eval { |
861 |
my $sth = $dbh->prepare($query); |
857 |
my $sth = $dbh->prepare($query); |
862 |
if ($db_scheme eq 'mysql') { |
858 |
$sth->execute((@$dataFields, @$dataFields)); |
863 |
$sth->execute((@$dataFields, @$dataFields)); |
|
|
864 |
} else { |
865 |
$sth->execute(@$dataFields); |
866 |
} |
867 |
}; |
859 |
}; |
868 |
if ($@) { |
860 |
if ($@) { |
869 |
unless ($db_scheme eq 'mysql') { |
|
|
870 |
$query = 'UPDATE ' . $table . ' SET ' . $updateStr . ' WHERE '; |
871 |
map {$query .= $_ . '=? AND ';} @$PKArray; |
872 |
$query = substr($query, 0, -4); |
873 |
eval { |
874 |
my $sth2 = $dbh->prepare($query); |
875 |
my @dataPK = (); |
876 |
map {push @dataPK, $dataFieldsHash->{$_};} @$PKArray; |
877 |
$sth2->execute((@$dataFields, @dataPK)); |
878 |
}; |
879 |
$ok = 1 unless ($@); |
880 |
} |
881 |
$debug and warn "Error _processRows_Table $@\n"; |
861 |
$debug and warn "Error _processRows_Table $@\n"; |
882 |
} else { |
862 |
} else { |
883 |
$ok = 1; |
863 |
$ok = 1; |
Lines 903-909
sub _processRows_Table
Link Here
|
903 |
my $dataStr = ''; |
883 |
my $dataStr = ''; |
904 |
my $updateStr = ''; |
884 |
my $updateStr = ''; |
905 |
my $j = 0; |
885 |
my $j = 0; |
906 |
my $db_scheme = C4::Context->config("db_scheme"); |
|
|
907 |
my $ok = 0; |
886 |
my $ok = 0; |
908 |
my @fieldsPK = @$PKArray; |
887 |
my @fieldsPK = @$PKArray; |
909 |
shift @fieldsPK; |
888 |
shift @fieldsPK; |
Lines 924-930
sub _processRows_Table
Link Here
|
924 |
# Get data from row |
903 |
# Get data from row |
925 |
my ($dataFields, $dataFieldsR) = _getDataFields($frameworkcode, $nodeR, \@fields, $format); |
904 |
my ($dataFields, $dataFieldsR) = _getDataFields($frameworkcode, $nodeR, \@fields, $format); |
926 |
if (scalar(@fields) == scalar(@$dataFieldsR)) { |
905 |
if (scalar(@fields) == scalar(@$dataFieldsR)) { |
927 |
$ok = _processRow_DB($dbh, $db_scheme, $table, $fields, $dataStr, $updateStr, $dataFieldsR, $dataFields, $PKArray, \@fieldsPK, $fields2Delete); |
906 |
$ok = _processRow_DB($dbh, $table, $fields, $dataStr, $updateStr, $dataFieldsR, $dataFields, $PKArray, \@fieldsPK, $fields2Delete); |
928 |
} |
907 |
} |
929 |
} |
908 |
} |
930 |
$j++; |
909 |
$j++; |
Lines 948-954
sub _import_table_csv
Link Here
|
948 |
my $fieldsNameRead = 0; |
927 |
my $fieldsNameRead = 0; |
949 |
my @arrData; |
928 |
my @arrData; |
950 |
my ($fieldsStr, $dataStr, $updateStr); |
929 |
my ($fieldsStr, $dataStr, $updateStr); |
951 |
my $db_scheme = C4::Context->config("db_scheme"); |
|
|
952 |
my @fieldsPK = @$PKArray; |
930 |
my @fieldsPK = @$PKArray; |
953 |
shift @fieldsPK; |
931 |
shift @fieldsPK; |
954 |
my $ok = 0; |
932 |
my $ok = 0; |
Lines 1005-1011
sub _import_table_csv
Link Here
|
1005 |
} |
983 |
} |
1006 |
$j++ |
984 |
$j++ |
1007 |
} |
985 |
} |
1008 |
$ok = _processRow_DB($dbh, $db_scheme, $table, $fieldsStr, $dataStr, $updateStr, \@arrData, \%dataFields, $PKArray, \@fieldsPK, $fields2Delete); |
986 |
$ok = _processRow_DB($dbh, $table, $fieldsStr, $dataStr, $updateStr, \@arrData, \%dataFields, $PKArray, \@fieldsPK, $fields2Delete); |
1009 |
} |
987 |
} |
1010 |
$pos = tell($dom); |
988 |
$pos = tell($dom); |
1011 |
} |
989 |
} |
1012 |
- |
|
|