I have a situation with DBI and the Sybase drivers. If I specify a TDS level, and I use a query with placeholders, and that query returns no results, the fetchall_arrayref() call hangs. If I don't do all three of those things, the call returns an array, as expected.

Steps to reproduce on Ubuntu 20.04:

Install perlbrew

sudo apt install gcc make -y wget -O - https://install.perlbrew.pl | bash echo "source ~/perl5/perlbrew/etc/bashrc" >> ~/.profile source ~/perl5/perlbrew/etc/bashrc perlbrew install perl-5.33.8 perlbrew switch perl-5.33.8 perlbrew install-cpanm
Install FreeTDS
wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.2.20.tar.gz tar xfvz freetds-1.2.20.tar.gz cd freetds-1.2.20/ ./configure --prefix=/home/username/tdslib make make install
Install DBI and Sybase
export SYBASE=/home/username/tdslib cpanm install DBI cpanm DBD::Sybase --verbose --force
run test script
use warnings; use strict; use DBI; use Data::Dumper; runTest(''); runTest(';tdsLevel=CS_TDS_495'); sub runTest { my ($tdsLevel) = @_; my $dsn = "dbi:Sybase:server=172.28.79.294$tdsLevel"; my $UserName = 'myusername'; my $Password = 'supersecretpassword'; my $dbh = DBI->connect( $dsn, $UserName, $Password, ) or ( print "Can't connect to the DB: $DBI::errstr\n" and die ); print "\nTesting no placeholders, no results $dsn\n"; my $sth = $dbh->prepare("select 'test' where 1=0"); $sth->execute(); my $results = $sth->fetchall_arrayref( {} ); print Dumper $results; print "\nTesting placeholders with results $dsn\n"; my $sthSecond = $dbh->prepare("select ? where 1=1"); $sthSecond->execute("test"); my $resultsSecond = $sthSecond->fetchall_arrayref( {} ); print Dumper $resultsSecond; print "\nTesting placeholders with no results $dsn\n"; my $sthThird = $dbh->prepare("select ? where 1=0"); $sthThird->execute("test"); my $resultsThird = $sthThird->fetchall_arrayref( {} ); print Dumper $resultsThird; $dbh->disconnect(); }
The test code above runs a total of six queries with different combinations of (1) specifying the TDS level (2), running a query with or without placeholders , and (3) running a query that does or does not return results. The test query that produces the hang is run last.

Full disclosure: I first wrote this test script on one computer and then created a virtual machine to test the "steps to reproduce" shown above. On the second computer, the connection with no TDS level specified does not work. However, I believe this to be a separate issue.

The SQL Server here is MS SQL Server Standard version 12.0.5223.6


In reply to fetchall_arrayref hangs with placeholders query with no results by TieUpYourCamel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.