From 222717165eda786302df2216a2494afa789fe752 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 19 Mar 2020 12:20:23 +0100 Subject: [PATCH] Bug 24883: Move to a flat array with all values to an array of arrayref For the following SQL query: INSERT INTO cities(city_name, city_country) VALUES ('Madrid', 'Spain'), ('Buenos Aires', 'Argentina'); We move from: [ 'Madrid', 'Spain', 'Buenos Aires', 'Argentina' ] to: [ [ 'Madrid', 'Spain' ], [ 'Buenos Aires', 'Argentina' ] ] Which make more sense to split, build and construct the queries Signed-off-by: Martin Renvoize --- C4/Installer.pm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/C4/Installer.pm b/C4/Installer.pm index c0ff508519..ec56c0e2d0 100644 --- a/C4/Installer.pm +++ b/C4/Installer.pm @@ -496,12 +496,12 @@ sub process_yml_table { my $placeholders = '(' . join ( ",", map { "?" } @columns ) . ')'; # '(?,..,?)' string my @values; foreach my $row ( @rows ) { - push @values, map { + push @values, [ map { my $col = $_; ( @multiline and grep { $_ eq $col } @multiline ) ? join "\r\n", @{$row->{$col}} # join multiline values : $row->{$col}; - } @columns; + } @columns ]; } return { query => $query, placeholders => $placeholders, values => \@values }; } @@ -535,8 +535,9 @@ sub load_sql { my $placeholders = $query_info->{placeholders}; my $values = $query_info->{values}; # Doing only 1 INSERT query for the whole table - $query .= join ', ', ( $placeholders ) x scalar @values; - $dbh->do( $query, undef, @values ); + my @all_rows_values = map { @$_ } @$values; + $query .= join ', ', ( $placeholders ) x scalar @$values; + $dbh->do( $query, undef, @all_rows_values ); } for my $statement ( @{ $yaml->{'sql_statements'} } ) { # extra SQL statements $dbh->do($statement); -- 2.20.1