Subject: | Error output when using SQL Sever through ODBC |
Running Linux RHEL7, freetds 0.91, odbc 3.52.7, perl v5.16.3
Database:
create table test1 (
test1Id int identity primary key,
name varchar(40) not null,
);
create table test2 (
date date not null,
test1Id int not null,
tkey varchar(40) not null,
tvalue varchar(40) not null,
foreign key (test1Id) references test1 (test1Id)
on delete no action
on update no action
);
DBIx::Class Files:
lib/Test/Schema.pm
package Test::Schema;
use base qw/DBIx::Class::Schema/;
__PACKAGE__->load_namespaces;
1;
lib/Test/Schema/Result/Test1.pm
package Test::Schema::Result::Test1;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('test1');
__PACKAGE__->add_columns(
'test1Id' => {is_auto_increment => 1},
'name' => {}
);
__PACKAGE__->set_primary_key('test1Id');
__PACKAGE__->has_many('daily','Test::Schema::Result::Test2',
'test1Id');
1;
lib/Test/Schema/Result/Test2.pm
package Test::Schema::Result::Test2;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('test2');
__PACKAGE__->add_columns(
'date' => {},
'test1Id' => {},
'tkey' => {},
'tvalue' => {}
);
__PACKAGE__->set_primary_key('date','test1Id');
__PACKAGE__->belongs_to('test1','Test::Schema::Result::Test1',
'test1Id');
sub test {
my $self=shift;
print $self->test1->name."\n";
}
1;
Test script "test":
#!/usr/bin/perl
use strict;
use warnings;
use lib qw(./lib);
use Test::Schema;
load();
print "will see error output then 'A'\n";
generateserrorsbutworks();
print "will just see 'A'\n";
workswithnoerrors();
sub generateserrorsbutworks {
my $x = Test::Schema->connect({dsn => $ENV{T_DSN},
user => $ENV{T_USER},
password => $ENV{T_PASS}});
unless ($x) {
die("failed to connect to ".$ENV{T_DSN}.": ".$!);
}
my $t = $x->resultset('Test1')->find({test1Id=>1});
$t->daily->search({date=>'2015/1/1'})->next->test;
}
sub workswithnoerrors {
my $x = Test::Schema->connect({dsn => $ENV{T_DSN},
user => $ENV{T_USER},
password => $ENV{T_PASS}});
unless ($x) {
die("failed to connect to ".$ENV{T_DSN}.": ".$!);
}
my $t = $x->resultset('Test1')->find({test1Id=>1});
($t->daily->search({date=>'2015/1/1'}))[0]->test;
}
sub load {
my $x = Test::Schema->connect({dsn => $ENV{T_DSN},
user => $ENV{T_USER},
password => $ENV{T_PASS}});
unless ($x) {
die("failed to connect to ".$ENV{T_DSN}.": ".$!);
}
$x->populate('Test1',[['name'],['A']]);
$x->populate('Test2',[['date','test1Id','tkey','tvalue'],
['2015/1/1',1,'X',1],
['2015/1/1',1,'Y',2],
['2015/1/1',1,'Z',3]]);
}
Output from above script:
$ ./test
will see error output then 'A'
(in cleanup) DBIx::Class::Storage::DBI::_execute(): DBI Exception: DBD::ODBC::st DESTROY failed: [FreeTDS][SQL Server]Invalid cursor state (SQL-24000) [state was 24000 now HY000]
Unable to fetch information about the error [for Statement "SELECT me.test1Id, me.name FROM test1 me WHERE ( me.test1Id = ? )"] at lib/Test/Schema/Result/Test2.pm line 20
A
will just see 'A'
A
All the above works correctly with no error messages at all when using MySQL.