Bug 13897: Surround columns with backticks

We have some column's names that need to be surrounded by ` as they are
protected keywords ('rows' for instance)

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Jonathan Druart 2020-02-12 11:27:39 +01:00 committed by Martin Renvoize
parent 131183b0bf
commit e925eb7a14
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 1 additions and 1 deletions

View File

@ -486,7 +486,7 @@ sub load_sql {
my $table_name = ( keys %$table )[0]; # table name
my @rows = @{ $table->{$table_name}->{rows} }; #
my @columns = ( sort keys %{$rows[0]} ); # column names
my $fields = join ",", @columns; # idem, joined
my $fields = join ",", map{sprintf("`%s`", $_)} @columns; # idem, joined
my $placeholders = join ",", map { "?" } @columns; # '?,..,?' string
my $query = "INSERT INTO $table_name ( $fields ) VALUES ( $placeholders )";
my $sth = $dbh->prepare($query);