|
|
sybperl-l Archive
Up Prev Next
From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Re: Simple Question
Date: Sep 9 1997 4:26PM
Jeremy Hansen wrote:
>
> Basically I'm getting an error:
>
> DB-Library error:
> Attempt to initiate a new SQL Server operation with results
> pending.
> DB-Library error:
> Attempt to initiate a new SQL Server operation with results
> pending.
> DB-Library error:
> Attempt to initiate a new SQL Server operation with results
> pending.
>
> I'm a beginner so I'm still trying to work things out, but what I'm trying
> to do should be very simple. Here's the perl program doing the
> processing:
You are trying to send a new command on a $dbh before having processed
all the results (data) from the first command. To get the behaviour
that you want you need to have two connections ($dbh's) open
simultaneaously. The first is used to query the database, and you
use the second to send updates to the database, like this:
#!/usr/local/bin/perl
#
# Query/Update Cable DB by anything.
#
use Sybase::DBlib;
# do query
$dbh = new Sybase::DBlib 'foo', 'bar', 'DBSRV' || die "Hmmm...$!";
$dbh_update = new Sybase::DBlib 'foo', 'bar', 'DBSRV' || die
"Hmmm...$!";
$dbh->dbuse('Accounting');
$dbh_update->dbuse('Acconting');
$dbh->dbcmd("select * from Cable_cust");
$dbh->dbsqlexec;
$dbh->dbresults;
# retrieve and place values
while(($ID, $ENTRY_DATE, $TESTER, $CABLE_COMPANY, $FIRST_NAME,
$MIDDLE_INITIAL, $LAST_NAME, $CONTACT_NAME, $COMPANY_NAME,
$STREET_ADDRESS, $STATE, $ZIP, $PHONE, $CABLE_STATUS, $CABLE_IP_ADDRESS,
$BOX_IP_ADDRESS, $SERIAL_NUMBER, $MAC_NUMBER, $PROSPECT, $IN STALLED,
$INSTALL_DATE, $AVAIL_NO_ORDER, $NOT_AVAIL, $EST_DATE_AVAIL, $EMAIL,
$DIAL_UP_CUSTOMER, $ACCOUNT_NUMBER) = $dbh->dbnextrow) {
($FIRST, $SECOND, $THIRD, $FOURTH, $FIVE) = split(/\s* /,
$CONTACT_NAME);
$dbh_update->dbcmd("update Cable_cust set FIRST_NAME='$FIRST',
LAST_NAME='$SECOND $THIRD $FORTH $FIVE' where CONTACT_NAME =
'$CONTACT_NAME'");
$dbh_update->dbsqlexec;
$dbh_update->dbresults;
print "...Done.\n";
}
Note that you should also add error checking (ie test whether commands
return FAIL).
Michael
--
Michael Peppler -||- Data Migrations Inc.
mpeppler@datamig.com -||- http://www.mbay.net/~mpeppler
|