Subject: | SQL Server error with DBD::ODBC 1.17 |
The sub-select in test_failing.pl gives the error "String data,
right truncation".
c:\>test_failing.pl
Using DBI 1.607 and DBD::ODBC 1.17
DB = DBI:ODBC:driver={SQL Server};Server=SQLVS2;Database=CS90PRD
DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server Driver]String
data, right truncation (SQL-22001) at c:\test_failing.pl line 44.
The program works correctly with DBD::ODBC 1.16.
c:\>test_failing.pl
Using DBI 1.607 and DBD::ODBC 1.16
DB = DBI:ODBC:driver={SQL Server};Server=SQLVS2;Database=CS90PRD
Count = 4218
If I change the where clause on the sub-select, it works:
c:\>test_working.pl
Using DBI 1.607 and DBD::ODBC 1.17
DB = DBI:ODBC:driver={SQL Server};Server=SQLVS2;Database=CS90PRD
Count = 4218
c:\>fc test_working.pl test_failing.pl
Comparing files test_working.pl and TEST_FAILING.PL
***** test_working.pl
AND R.CLASS_NBR = S.CLASS_NBR
)
FROM
***** TEST_FAILING.PL
AND R.CLASS_NBR = S.CLASS_NBR
AND R.STDNT_ENRL_STATUS = 'E'
AND R.CRSE_GRADE_OFF <> 'W'
AND R.GRADING_BASIS_ENRL <> 'AUD'
)
FROM
*****
The target database is SQL Server 9.0.3042 (Microsoft SQL Server 2005
Service Pack 2).
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 12 registered patches, see perl -V for more detail)
Copyright 1987-2007, Larry Wall
Binary build 824 [287188] provided by ActiveState http://www.ActiveState.com
Built Sep 3 2008 11:14:55
This is under Windows Server 2003 R2.
Subject: | test_working.pl |
use strict;
use warnings;
use DBI;
use Rosters2::Globals;
my $college = 'CER90';
my $dbh = DBI->connect( $config{$college}->{db},
$config{$college}->{login},
$config{$college}->{password},
{RaiseError=>1,PrintError=>0}
)
or croak( "Can't connect to PSDB: $DBI::errstr" );
print "Using DBI $DBI::VERSION and DBD::ODBC $DBD::ODBC::VERSION\n";
print "DB = $config{$college}->{db}\n";
my $classes_sql = q{
SELECT
S.CLASS_NBR,
(SELECT COUNT(R.EMPLID)
FROM PS_CER_ROS_STD_VW AS R
WHERE
R.STRM = S.STRM
AND R.CLASS_NBR = S.CLASS_NBR
)
FROM
PS_CER_ROS_SCH_VW AS S
WHERE
S.STRM = ?
};
my $term_code = 1089;
#print "Execute $DBI::VERSION $classes_sql with $term_code\n" ;
my $classes = $dbh->prepare( $classes_sql );
$classes->execute( $term_code );
my $count = 0;
MEETING:
while (my ( $class_nbr, $enrl_tot ) = $classes->fetchrow_array ) {
$count++;
}
print "Count = $count";
Subject: | test_failing.pl |
use strict;
use warnings;
use DBI;
use Rosters2::Globals;
my $college = 'CER90';
my $dbh = DBI->connect( $config{$college}->{db},
$config{$college}->{login},
$config{$college}->{password},
{RaiseError=>1,PrintError=>0}
)
or croak( "Can't connect to PSDB: $DBI::errstr" );
print "Using DBI $DBI::VERSION and DBD::ODBC $DBD::ODBC::VERSION\n";
print "DB = $config{$college}->{db}\n";
my $classes_sql = q{
SELECT
S.CLASS_NBR,
(SELECT COUNT(R.EMPLID)
FROM PS_CER_ROS_STD_VW AS R
WHERE
R.STRM = S.STRM
AND R.CLASS_NBR = S.CLASS_NBR
AND R.STDNT_ENRL_STATUS = 'E'
AND R.CRSE_GRADE_OFF <> 'W'
AND R.GRADING_BASIS_ENRL <> 'AUD'
)
FROM
PS_CER_ROS_SCH_VW AS S
WHERE
S.STRM = ?
};
my $term_code = 1089;
#print "Execute $DBI::VERSION $classes_sql with $term_code\n" ;
my $classes = $dbh->prepare( $classes_sql );
$classes->execute( $term_code );
my $count = 0;
MEETING:
while (my ( $class_nbr, $enrl_tot ) = $classes->fetchrow_array ) {
$count++;
}
print "Count = $count";