View | Details | Raw Unified | Return to bug 24904
Collapse All | Expand All

(-)a/C4/Installer.pm (-6 / +7 lines)
Lines 487-505 sub load_sql { Link Here
487
                    my @rows         = @{ $table->{$table_name}->{rows} };           #
487
                    my @rows         = @{ $table->{$table_name}->{rows} };           #
488
                    my @columns      = ( sort keys %{$rows[0]} );                    # column names
488
                    my @columns      = ( sort keys %{$rows[0]} );                    # column names
489
                    my $fields       = join ",", map{sprintf("`%s`", $_)} @columns;  # idem, joined
489
                    my $fields       = join ",", map{sprintf("`%s`", $_)} @columns;  # idem, joined
490
                    my $placeholders = join ",", map { "?" } @columns;               # '?,..,?' string
490
                    my $query        = "INSERT INTO $table_name ( $fields ) VALUES ";
491
                    my $query        = "INSERT INTO $table_name ( $fields ) VALUES ( $placeholders )";
492
                    my $sth          = $dbh->prepare($query);
493
                    my @multiline    = @{ $table->{$table_name}->{'multiline'} };    # to check multiline values;
491
                    my @multiline    = @{ $table->{$table_name}->{'multiline'} };    # to check multiline values;
492
                    my $placeholders = '(' . join ( ",", map { "?" } @columns ) . ')'; # '(?,..,?)' string
493
                    my @values;
494
                    foreach my $row ( @rows ) {
494
                    foreach my $row ( @rows ) {
495
                        my @values = map {
495
                        push @values, map {
496
                                        my $col = $_;
496
                                        my $col = $_;
497
                                        ( @multiline and grep { $_ eq $col } @multiline )
497
                                        ( @multiline and grep { $_ eq $col } @multiline )
498
                                        ? join "\r\n", @{$row->{$col}}                # join multiline values
498
                                        ? join "\r\n", @{$row->{$col}}                # join multiline values
499
                                        : $row->{$col};
499
                                        : $row->{$col};
500
                                     } @columns;
500
                                     } @columns;
501
                        $sth->execute( @values );
502
                    }
501
                    }
502
                    # Doing only 1 INSERT query for the whole table
503
                    $query .= join ', ', ( $placeholders ) x scalar @rows;
504
                    $dbh->do( $query, undef, @values );
503
                }
505
                }
504
                for my $statement ( @{ $yaml->{'sql_statements'} } ) {               # extra SQL statements
506
                for my $statement ( @{ $yaml->{'sql_statements'} } ) {               # extra SQL statements
505
                    $dbh->do($statement);
507
                    $dbh->do($statement);
506
- 

Return to bug 24904