coredump in perl using DBD::ODBC (was succint view of problem - getting results from DBCC)

From: Martin J. Evans (martin_at_easysoft.com)
Date: 12/30/03


Date: Tue, 30 Dec 2003 20:25:24 -0000 (GMT)
To: dbi-users@perl.org

The following script core dumps in perl:

#!/usr/bin/perl -w
use DBI;
#DBI->trace(6);
$dbh = DBI->connect("dbi:ODBC:test", 'Martin_Evans','easysoft',
            { PrintError => 0,
              RaiseError => 1,
              LongReadLen => 65536,
              odbc_async_exec => 0,
              odbc_err_handler => sub {
                                        my ($state, $msg) = @_;
                                        # Strip out all of the driver ID stuff
                                        $msg =~ s/^(\[[\w\s]*\])+//;
                                        $err_text .= $msg."\n";
                                        return 0;
                                       }
            }
           );
$command = qq%select * from notable%;
print "** command: \n$command\n";
$sth = $dbh->prepare($command);
    die $DBI::errstr unless $sth;
$rc = $sth->execute(); # This is the 'do it'.....
$rows = $sth->dump_results();
print "** return code: $rc \n";
print "** rows: $rows\n";
print "\nCOMMAND OUTPUT (from odbc_err_handler):\n$err_text\n";
$sth->{odbc_more_results};
$rows = $sth->dump_results();
$dbh->disconnect;

(NOTE the table notable does not exist)

on the second dump_results with the following stack dump:

#0 0x4018a1b8 in XS_DBI_dispatch ()
   from /usr/local/lib/perl5/site_perl/5.8.0/i686-linux/auto/DBI/DBI.so
#1 0x809f7c5 in Perl_pp_entersub ()
#2 0x805f8eb in S_call_body ()
#3 0x805f6de in Perl_call_sv ()
#4 0x80a5970 in Perl_sv_clear ()
#5 0x80a5e39 in Perl_sv_free ()
#6 0x80a5be9 in Perl_sv_clear ()
#7 0x80a5e39 in Perl_sv_free ()
#8 0x80978c9 in Perl_hv_free_ent ()
#9 0x8097a4e in S_hfreeentries ()
#10 0x8097a84 in Perl_hv_undef ()
#11 0x80a5b66 in Perl_sv_clear ()
#12 0x80a5e39 in Perl_sv_free ()
#13 0x80a5be9 in Perl_sv_clear ()
#14 0x80a5e39 in Perl_sv_free ()
#15 0x8091c7c in Perl_mg_free ()
#16 0x80a5a91 in Perl_sv_clear ()
#17 0x80a5e39 in Perl_sv_free ()
#18 0x80a053b in do_clean_objs ()
#19 0x80a04b9 in S_visit ()
#20 0x80a05bc in Perl_sv_clean_objs ()
#21 0x805d638 in perl_destruct ()
#22 0x805ca94 in main ()
#23 0x4006a1eb in __libc_start_main (main=0x805ca10 <main>, argc=3,
    argv=0xbffffc34, init=0x805bc48 <_init>, fini=0x80ed73c <_fini>,
    rtld_fini=0x4000a610 <_dl_fini>, stack_end=0xbffffc2c)
    at ../sysdeps/generic/libc-start.c:90

When DBI->trace(6); is added to the start of the script it no longer core
dumps. Where do I go from here?

perl -V gives:

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.2.12-20smp, archname=i686-linux
    uname='linux brimer 2.2.12-20smp #1 smp mon sep 27 10:34:45 edt 1999 i686 un
known '
    config_args='-de'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=unde
f
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SO
URCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)',
 gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize
=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lc -lposix -lcrypt -lutil
    libc=/lib/libc-2.1.2.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.1.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Characteristics of this binary (from libperl):
  Compile-time options: USE_LARGE_FILES
  Built under linux
  Compiled at Jul 1 2003 13:20:06
  @INC:
    /usr/local/lib/perl5/5.8.0/i686-linux
    /usr/local/lib/perl5/5.8.0
    /usr/local/lib/perl5/site_perl/5.8.0/i686-linux
    /usr/local/lib/perl5/site_perl/5.8.0
    /usr/local/lib/perl5/site_perl

and I'm using:

perl -e 'use DBD::ODBC; print $DBD::ODBC::VERSION;'
1.05
perl -e 'use DBI;print $DBI::VERSION;'
1.39[martin@brimer /tmp]$

According to unixODBC tracing the core dump does not occur in unixODBC or the
ODBC driver as the last entries are:

[ODBC][14265][SQLExecute.c][341]
                Exit:[SQL_ERROR]
                DIAG [42S02] [Microsoft][ODBC SQL Server Driver][SQL Server]Inva
lid object name 'notable'.

                DIAG [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Stat
ement(s) could not be prepared.

[ODBC][14265][SQLError.c][342]
                Entry:
                        Statement = 0x82693f8
                        SQLState = 0xbffff7a4
                        Native = 0xbffff590
                        Message Text = 0xbffff5a4
                        Buffer Length = 511
                        Text Len Ptr = 0xbffff596
[ODBC][14265][SQLError.c][379]
                Exit:[SQL_SUCCESS]
                        SQLState = 42S02
                        Native = 0xbffff590 -> 208
                        Message Text = [[unixODBC][Microsoft][ODBC SQL Server Dr
iver][SQL Server]Invalid object name 'notable'.]
[ODBC][14265][SQLError.c][342]
                Entry:
                        Statement = 0x82693f8
                        SQLState = 0xbffff7a4
                        Native = 0xbffff590
                        Message Text = 0xbffff5a4
                        Buffer Length = 511
                        Text Len Ptr = 0xbffff596
[ODBC][14265][SQLError.c][379]
                Exit:[SQL_SUCCESS]
                        SQLState = 42000
                        Native = 0xbffff590 -> 8180
                        Message Text = [[unixODBC][Microsoft][ODBC SQL Server Dr
iver][SQL Server]Statement(s) could not be prepared.]
[ODBC][14265][SQLError.c][342]
                Entry:
                        Statement = 0x82693f8
                        SQLState = 0xbffff7a4
                        Native = 0xbffff590
                        Message Text = 0xbffff5a4
                        Buffer Length = 511
                        Text Len Ptr = 0xbffff596
[ODBC][14265][SQLError.c][379]
                Exit:[SQL_NO_DATA]
[ODBC][14265][SQLError.c][424]
                Entry:
                        Connection = 0x8247128
                        SQLState = 0xbffff7a4
                        Native = 0xbffff590
                        Message Text = 0xbffff5a4
                        Buffer Length = 511
                        Text Len Ptr = 0xbffff596
[ODBC][14265][SQLError.c][461]
                Exit:[SQL_NO_DATA]
[ODBC][14265][SQLError.c][504]
                Entry:
                        Environment = 0x8246b98
                        SQLState = 0xbffff7a4
                        Native = 0xbffff590
                        Message Text = 0xbffff5a4
                        Buffer Length = 511
                        Text Len Ptr = 0xbffff596
[ODBC][14265][SQLError.c][541]
                Exit:[SQL_NO_DATA]

Thanks.

Martin

--
Martin J. Evans
Easysoft Ltd, UK
Development