kyle has asked for the wisdom of the Perl Monks concerning the following question:
Hello most gracious monks,
I was happily writing a Catalyst app with DBIx::Class when I tripped over some database problem. I haven't been able to pin it down, but I'm pretty sure it has to do with DBD::Sybase used with our MSSQL server.
My original problem is I tried to call ->first on a DBIx::Class::ResultSet twice. That produced the error "DBIx::Class::ResultSet::first(): Unknown error: execute() returned false, but error flags were not set...", which you can find in DBIx::Class::Storage::DBI in sub _dbh_execute.
# Can this fail without throwing an exception anyways??? my $rv = $sth->execute(); $self->throw_exception( $sth->errstr || $sth->err || 'Unknown error: execute() returned fa +lse, but error flags were not set...' ) if !$rv;
I have a minimal test using only DBI that demonstrates the problem.
use 5.014; use strict; use warnings; use DBI; use Test::More; my @connect_info = ( "dbi:Sybase:server=xxx;database=xxx", 'xxx', ':)', { RaiseError => 1 }, ); # @connect_info = ("dbi:SQLite2:dbname=dbfile","",""); my $dbh = DBI->connect( @connect_info ); isa_ok $dbh, 'DBI::db'; my $sql = 'SELECT 1'; test_query( $sql ); test_query( $sql ); sub test_query { my ($sql) = @_; my $sth = $dbh->prepare_cached( $sql ); isa_ok $sth, 'DBI::st'; my $r = $sth->execute(); { no warnings 'uninitialized'; ok defined( $r ), "defined: '$r'"; } ok $sth->finish(), '$sth->finish'; return; } done_testing;
I've obscured the actual connect info. This is what the output looks like:
ok 1 - The object isa DBI::db ok 2 - The object isa DBI::st ok 3 - defined: '-1' ok 4 - $sth->finish ok 5 - The object isa DBI::st not ok 6 - defined: '' # Failed test 'defined: ''' # at t/dbi-bug-pm.t line 35. ok 7 - $sth->finish 1..7 # Looks like you failed 1 test of 7.
Note that if you uncomment the SQLite connect info, it works fine. That's why I think this is a problem with my database or driver. You can see a run with SQLite below.
ok 1 - The object isa DBI::db ok 2 - The object isa DBI::st ok 3 - defined: '0E0' ok 4 - $sth->finish ok 5 - The object isa DBI::st ok 6 - defined: '0E0' ok 7 - $sth->finish 1..7
Note also that if I disconnect from the database and reconnect between the queries, they work, but I don't think disconnecting from the database after every query is a very good workaround.
I'd be happy with a workaround for this issue. If I could stick some code in every ResultSet so that it avoids the problem until it's fixed elsewhere, that would be fine with me, but I don't even understand what's going wrong. I'm asking here to see if someone is familiar with it and what it means.
My searching for the issue online turned up a thread from about a year ago (http://lists.scsys.co.uk/pipermail/dbix-class/2012-June/010553.html). If there's an answer in there, I failed to comprehend it.
Any help would be appreciated. Thank you.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: My MSSQL query fails the second time.
by karlgoethebier (Abbot) on Apr 30, 2013 at 19:25 UTC | |
by kyle (Abbot) on Apr 30, 2013 at 20:50 UTC | |
by Anonymous Monk on Jul 15, 2013 at 20:21 UTC | |
by Anonymous Monk on Nov 14, 2013 at 19:31 UTC | |
Re: My MSSQL query fails the second time.
by moritz (Cardinal) on Apr 30, 2013 at 17:52 UTC | |
by kyle (Abbot) on Apr 30, 2013 at 19:26 UTC | |
by moritz (Cardinal) on May 01, 2013 at 04:59 UTC | |
by kyle (Abbot) on May 01, 2013 at 16:13 UTC | |
by mpeppler (Vicar) on May 05, 2013 at 13:09 UTC |