DBD-Teradata
view release on metacpan or search on metacpan
#!/usr/local/bin/perl
#
# testutf8.pl - UTF8 based test suite for DBD::Teradata
#
BEGIN {
push @INC, './t';
}
use DBI;
use DBI qw(:sql_types);
use FileHandle;
use DBD::Teradata;
use Encode;
use Time::HiRes qw(time);
use Config;
use TdTestDataGen qw(gen_test_data);
use TdTestBulkload qw(
load_nb_raw
load_nb_vartext
load_thrd_raw
load_thrd_vartext);
use TdTestBigInt qw(dectests);
use TdTestBigSQL qw(bigsqltest);
use TdTestCursors qw(
init_for_cursors
updatable_cursor
persistent_cursor
rewind_cursor);
*STDERR = *STDOUT;
my %typestr = (
SQL_VARCHAR, 'VARCHAR',
SQL_CHAR, 'CHAR',
SQL_FLOAT, 'FLOAT',
SQL_DECIMAL, 'DECIMAL',
SQL_INTEGER, 'INTEGER',
SQL_SMALLINT, 'SMALLINT',
SQL_TINYINT, 'TINYINT',
SQL_VARBINARY, 'VARBINARY',
SQL_BINARY, 'BINARY',
SQL_LONGVARBINARY, 'LONG VARBINARY',
SQL_DATE, 'DATE',
SQL_TIMESTAMP, 'TIMESTAMP',
SQL_TIME, 'TIME'
);
use strict;
use warnings;
my $dbh;
#
# process cmdline options
#
my $label;
my %opts = ( '-s', 8, '-d', 9, '-t', 10, '-v', 12);
my $logfile = undef;
# do all of normal,
# tests 2 session limit, no tracing, threads on, default Teradata version
my @specials = (undef, 1, undef, undef, undef, undef, undef, undef, 2, 0, 1, 1, undef);
#
# for mp debug
#$DB::fork_TTY = '/dev/ttyp2';
my $doall = 1;
if ($ARGV[0]=~/^-/) {
@specials = (0) x 12;
$specials[8] = 2; # deflt util sesscount
$specials[10] = 1; # deflt threads enabled
$specials[11] = 1; # deflt use cli enabled
while (1) {
last
unless ($ARGV[0]=~/^-/);
$label = shift @ARGV;
usage() and exit
if ($label eq '-h');
die "Unknown option $label; valid options are -[hsdv]\n"
unless $opts{$label};
$specials[$opts{$label}] = 1;
$specials[$opts{$label}] = shift @ARGV
if (($label eq '-t') && ($ARGV[0]=~/^[012]$/));
dectests($dbh);
###################################################
#
# test Big SQL
#
###################################################
bigsqltest($dbh)
if ($dbh->{tdat_versnum} >= 5000000);
###################################################
#
# test stored procedures
#
###################################################
if ($dbh->{tdat_versnum} >= 4000000) {
eval {
require TdTestProcs;
import TdTestProcs qw(sptests);
};
die "Unable to load TdTestProcs: $@"
if $@;
sptests($dbh);
}
else {
print STDERR "Unable to test stored procedures: not supported by DBMS.\n";
}
###################################################
#
# test bulkloads
#
###################################################
$| = 1;
$ristarted = load_nb_raw($dbh, $dsn, $userid, $passwd, $sescnt, 1000);
$rvstarted = load_nb_vartext($dbh, $dsn, $userid, $passwd, $sescnt, 1000);
###################################################
#
# test threaded implementation of above,
# but only with no-cli
#
###################################################
#if ($Config{useithreads} && $specials[10] && (! $dbh->{tdat_uses_cli})) {
if ($Config{useithreads} &&
($Config{useithreads} eq 'define') &&
$specials[10]) {
$tristarted = load_thrd_raw($dsn, $userid, $passwd, $sescnt, 1000);
$trvstarted = load_thrd_vartext($dsn, $userid, $passwd, $sescnt, 1000);
}
else {
print STDERR "Perl built without thread support, skipping thread tests\n"
if $specials[10];
}
###################################################
#
# test updatable cursors
#
###################################################
if ($dbh->{tdat_uses_cli}) {
print STDERR "Using CLI, skipping persistent/rewindable cursors.\n";
}
else {
init_for_cursors($dbh, 1000);
updatable_cursor($dbh, $dsn, $userid, $passwd);
persistent_cursor($dbh);
rewind_cursor($dbh);
}
###################################################
#
# test output mode
#
###################################################
print STDERR "Testing standard output mode...\n";
init_for_cursors($dbh, 10000);
$ostarted = time;
$ssth = $dbh->prepare('SELECT * FROM alltypetst') or die ($dbh->errstr . "\n");
$names = $ssth->{NAME};
print join(' ', @$names), "\n";
$ssth->execute or die ($ssth->errstr . "\n");
$reccnt = 0;
while ($row = $ssth->fetchrow_arrayref() ) {
$reccnt++;
print STDERR "Got $reccnt rows\n"
unless $reccnt%1000;
}
$ostarted = trim_time($ostarted);
print STDERR "$reccnt rows retrieved in $ostarted secs.\n";
print STDERR "Std output ok.\n";
###################################################
#
# test formatted output mode
#
###################################################
print STDERR "Testing formatted output mode...\n";
$fmostarted = time;
$ssth = $dbh->prepare('SELECT * FROM alltypetst', {tdat_formatted => 1}) ||
die ($dbh->errstr . "\n");
$names = $ssth->{NAME};
print join(' ', @$names), "\n";
$ssth->execute or die ($ssth->errstr . "\n");
$reccnt = 0;
while ($row = $ssth->fetchrow_arrayref() ) {
$reccnt++;
print STDERR "Got $reccnt rows\n"
unless $reccnt%1000;
}
$fmostarted = trim_time($fmostarted);
print STDERR "$reccnt rows retrieved in $fmostarted secs.\n";
print STDERR "Formatted output ok.\n";
###################################################
#
# test raw output mode
#
###################################################
print STDERR "Testing raw output mode...\n";
$rostarted = time;
$ssth = $dbh->prepare('SELECT * FROM alltypetst', {
tdat_raw_out => 'IndicatorMode'
}) || die ($dbh->errstr . "\n");
$names = $ssth->{NAME};
#print join(' ', @$names), "\n";
$ssth->execute or die ($ssth->errstr . "\n");
$reccnt = 0;
while ($row = $ssth->fetchrow_arrayref() ) {
$reccnt++;
print STDERR "Got $reccnt rows\n" unless $reccnt%1000;
}
$rostarted = trim_time($rostarted);
( run in 0.549 second using v1.01-cache-2.11-cpan-39bf76dae61 )