This problem occurs because DBD::Sybase will open new connections for
you if you create more than one simultaneously active $sth on the same
$dbh.

Subsequent $sth's will "use" the database passed in the connect()
call, or the user's default database. DBD::Sybase does *not* (yet)
track "use <database>" statements issued with a $dbh->do() or some
other method.

The same issue has been raised on perlmonks, and I may address it if I
find a decent way to handle this (for example, does a database change
on a child sth affect the parent dbh?)

Michael

Hall, Roger writes:
 > Oops... corrected to visibly use the same dbh but the problem is the same...
 > (They were the same dbh, but it was not obvious from the code sample before)
 > 
 > 
 > ##################################################
 >       my($sth_1, $sth_2, $sth_3);
 >       $sth_1 = $dbh->prepare("select db_name()"); #### Changed from $sybh to
 > $dbh
 >       $sth_1->execute();
 >       while (my($d) = $sth_1->fetchrow_array()) {
 >           print "***** $d *****\n";
 >       }
 > ##################################################
 > 
 >    my $tabsth = $dbh->table_info();
 >    my $colsth;
 >    my $sql;
 >    my $table;
 > 
 > ###############################################################
 >       $sth_1 = $dbh->prepare("select db_name()");
 >       $sth_1->execute();
 >       while (my($d) = $sth_1->fetchrow_array()) {
 >           print "***** $d *****\n";
 >       }
 >       $sth_1->finish();
 > 
 > 
 > 
 > > -----Original Message-----
 > > From: Hall, Roger 
 > > Sent: Tuesday, November 20, 2001 10:23 AM
 > > To: [EMAIL PROTECTED]
 > > Subject: table_info bug with Sybase - switches database ?
 > > 
 > > 
 > > Hi,
 > > 
 > > I am using DBI-1.14.tar.gz and DBD-Sybase-0.91.tar.gz and am getting
 > > some behavior that I do not understand... I guess its either 
 > > me or a bug.
 > > 
 > > When I use table_info, I seem to be switching to the default 
 > > database of the
 > > login id that I use. An example of some code I was testing 
 > > stuff with is
 > > shown
 > > below. The two prints show me a different database.
 > > 
 > > Roger.
 > > 
 > > 
 > > ##################################################
 > >       my($sth_1, $sth_2, $sth_3);
 > >       $sth_1 = $sybh->prepare("select db_name()"); 
 > >       $sth_1->execute();
 > >       while (my($d) = $sth_1->fetchrow_array()) {
 > >           print "***** $d *****\n";
 > >       }
 > > ##################################################
 > > 
 > >    my $tabsth = $dbh->table_info();
 > >    my $colsth;
 > >    my $sql;
 > >    my $table;
 > > 
 > > ###############################################################
 > >       $sth_1 = $dbh->prepare("select db_name()");
 > >       $sth_1->execute();
 > >       while (my($d) = $sth_1->fetchrow_array()) {
 > >           print "***** $d *****\n";
 > >       }
 > > 

-- 
Michael Peppler - Data Migrations Inc. - http://www.mbay.net/~mpeppler
[EMAIL PROTECTED] - [EMAIL PROTECTED]
International Sybase User Group - http://www.isug.com

Reply via email to