From c62d71e0421d25d4ca6a626ddfdf7dabcdeb14f6 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 --- C4/Installer.pm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/C4/Installer.pm b/C4/Installer.pm index a7ca5d807b..b9a0ce53b2 100644 --- a/C4/Installer.pm +++ b/C4/Installer.pm @@ -470,12 +470,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 }; } @@ -509,8 +509,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