DBIx-JCL
view release on metacpan or search on metacpan
lib/DBIx/JCL.pm view on Meta::CPAN
=cut
my ($vdn, $table_name, $max_rows) = @_;
my ($dbh, $sth) = _db_vdn('dump_table', $vdn);
$max_rows = 999_999 unless defined $max_rows;
$table_name = uc $table_name;
my $col_sql = "select column_name " .
" from all_tab_columns " .
" where table_name = '$table_name'";
my ( $tmp_sth, @cols );
$tmp_sth = $dbh->prepare( $col_sql )
or sys_die( DBI->errstr );
$tmp_sth->execute
or sys_die( DBI->errstr );
while ( my @row = $tmp_sth->fetchrow_array() ) {
push @cols, $row[0];
}
$tmp_sth->finish;
my $columns = join ', ', @cols;
my $tab_sql = "select $columns " .
" from $table_name";
$tmp_sth = $dbh->prepare( $tab_sql )
or sys_die( DBI->errstr );
$tmp_sth->execute
or sys_die( DBI->errstr );
my $row_count = 0;
while ( my @row = $tmp_sth->fetchrow_array() ) {
print "RECORD:\n";
for my $i ( 0 .. $#row ) {
print "\t", $cols[$i], "=", _db_null( $row[$i] ), "\n";
}
last if ++$row_count >= $max_rows;
}
$tmp_sth->finish;
return 0;
}
sub db_sqlloader {
=begin wiki
!3 db_sqlloader
Parameters: ( vdn, datfile, ctlname, maxerrors )
* /vdn/ - Virtual Database Name
* /datfile/ - SQL*Loader data file
* /ctlname/ - Job conf key for control file input
* /maxerrors/ - Maximum number of errors allowed
This is a convenience function which provides a simplified method for calling \
the various db_sqlloader functions. This will invoke SQL*Loader and handle \
the various execution and output parsing that whould otherwise have to be \
handled by calling the db_sqlloader functions directly (which certainly you \
can if you prefer).
Execute SQL*Loader using the supplied paramaters. The Virtual Database \
Name is used to obtain login credentials. This will launch SQL*Loader \
and wait for it to finish, returning the SQL*Loader return code to the \
caller.
Data file name must be fully qualified. Path provided by data file name \
will be used for out, bad, and dis files.
Return: One of
* SQLLDR_SUCC
* SQLLDR_WARN
* SQLLDR_FAIL
=cut
my ($vdn, $datfile, $ctlname, $maxerrors) = @_;
my $id = 'db_sqlloader';
my $datfilepath = $db_func_params{$id}{DatFilePath};
my $dbenvr = $db_func_params{$id}{DbEnvr};
my $netservice = $db_func_params{$id}{NetService};
my $datfilefull = $datfilepath . $datfile;
my ($sqlldr_retcd, $sqlldr_result);
log_info( "Executing SQLLoader" );
if ( $dbenvr =~ /$netservice/ ) {
log_info( "Using netservice db connection symantics" );
$sqlldr_retcd = db_sqlloaderx( "$vdn:$dbenvr", $datfilefull, $ctlname, $maxerrors );
} else {
log_info( "Using local db connection symantics" );
$sqlldr_retcd = db_sqlloaderx( $vdn, $datfilefull, $ctlname, $maxerrors );
}
$sqlldr_result = db_sqlloaderx_parse_logfile( $datfilefull );
log_info( "SQLLoader Output:", $sqlldr_result );
if ( $sqlldr_retcd == $SQLLDR_SUCC ) {
log_info( "Load data file $datfile completed successfully" );
}
if ( $sqlldr_retcd == $SQLLDR_WARN ) {
log_warn( "Load data file $datfile completed with warnings" );
}
if ( $sqlldr_retcd == $SQLLDR_FTL || $sqlldr_retcd == $SQLLDR_FAIL ) {
$sqlldr_retcd = $SQLLDR_FAIL;
log_warn( "Load data file $datfile failed" );
}
my $rej_count = db_sqlloaderx_rejected();
if ( $rej_count > 0 ) {
log_warn( "SQLLoader rejected $rej_count records loading $datfile to " . sys_get_dbinst( $vdn ) );
}
if ( $rej_count > $maxerrors ) {
log_warn( "SQLLoader failed loading $datfile to " . sys_get_dbinst( $vdn ) . " due to max rejected records" );
}
return $sqlldr_retcd;
}
sub db_sqlloaderx {
( run in 4.474 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )