- my $strcmd;
- my $cmd;
- if ( $self->{dbms} eq 'mysql' ) {
- $cmd = qx(which mysql 2>/dev/null || whereis mysql 2>/dev/null);
- chomp $cmd;
- $cmd = $1 if ($cmd && $cmd =~ /^(.+?)[\r\n]+$/);
- $cmd = 'mysql' if (!$cmd || !-x $cmd);
- $strcmd = "$cmd "
- . ( $self->{hostname} ? " -h $self->{hostname} " : "" )
- . ( $self->{port} ? " -P $self->{port} " : "" )
- . ( $self->{user} ? " -u $self->{user} " : "" )
- . ( $self->{password} ? " -p'$self->{password}'" : "" )
- . " $self->{dbname} ";
- $error = qx($strcmd --default-character-set=utf8 <$filename 2>&1 1>/dev/null);
- } elsif ( $self->{dbms} eq 'Pg' ) {
- $cmd = qx(which psql 2>/dev/null || whereis psql 2>/dev/null);
- chomp $cmd;
- $cmd = $1 if ($cmd && $cmd =~ /^(.+?)[\r\n]+$/);
- $cmd = 'psql' if (!$cmd || !-x $cmd);
- $strcmd = "$cmd "
- . ( $self->{hostname} ? " -h $self->{hostname} " : "" )
- . ( $self->{port} ? " -p $self->{port} " : "" )
- . ( $self->{user} ? " -U $self->{user} " : "" )
-# . ( $self->{password} ? " -W $self->{password}" : "" ) # psql will NOT accept a password, but prompts...
- . " $self->{dbname} "; # Therefore, be sure to run 'trust' on localhost in pg_hba.conf -fbcit
- $error = qx($strcmd -f $filename 2>&1 1>/dev/null);
- # Be sure to set 'client_min_messages = error' in postgresql.conf
- # so that only true errors are returned to stderr or else the installer will
- # report the import a failure although it really succeded -fbcit
- }
-# errors thrown while loading installer data should be logged
- if($error) {
- warn "C4::Installer::load_sql returned the following errors while attempting to load $filename:\n";
- warn "$error";
+
+ my $dbh = $self->{ dbh };
+
+ my $dup_stderr;
+ do {
+ local *STDERR;
+ open STDERR, ">>", \$dup_stderr;
+
+ eval {
+ DBIx::RunSQL->run_sql_file(
+ dbh => $dbh,
+ sql => $filename,
+ );
+ };
+ };
+ # errors thrown while loading installer data should be logged
+ if( $dup_stderr ) {
+ warn "C4::Installer::load_sql returned the following errors while attempting to load $filename:\n";
+ $error = $dup_stderr;