Bug 13897: Surround columns with backticks
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 12 Feb 2020 10:27:39 +0000 (11:27 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 9 Mar 2020 13:50:36 +0000 (13:50 +0000)
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>

C4/Installer.pm

index 2e09627..012bc1c 100644 (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);