Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

DBI on windows problem

by txtoolman (Initiate)
on Nov 01, 2007 at 02:00 UTC ( #648420=perlquestion: print w/replies, xml ) Need Help??
txtoolman has asked for the wisdom of the Perl Monks concerning the following question:

Please remember this is all on a windows platform. I'm using an update statement (setting a flag), then a delete statement through DBI (& DBD::ODBC). When I have it report the number of rows deleted, the deleted rows are coming up less than the number of updated rows. Is there a known bug here? If I do the SQL statements in query SQL Management studio, the SQL runs as it should (and returns the correct number of rows affected. Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: DBI on windows problem
by jZed (Prior) on Nov 01, 2007 at 03:50 UTC
    Please show us a small portion of the code that illustrates the problem. While it's conceivable there is a bug in the software, it's much more likely that there's a bug in your code. The situation you describe sounds like it would be a fertile place for race conditions to grow.
      11-1-2007 -- The DELETE line is where the problem lies. Here is the code:

      use DBI;

      $dbh = DBI->connect('dbi:ODBC:Tradchem2005');
      #--select * from xcontacts
      $sql1 =
      "UPDATE xcontacts
      SET NEWCOLUMN8 = 'X'
      where sysparentid in (select sysrowid from clients where loaddate >= (GETDATE()-7)) and contactname <> '' ";

      $sql2 = "delete from contacts where sysrowid in (select sysrowid from Xcontacts where newcolumn8 = 'X') ";

      $sql2a = "
      Insert Contacts Select Address4, AddInterests, Child1Birthday, Child1info, Child1Name, Child2Birthday, Child2Info, Child2Name,
      SysRowID, SysRoute, SysParentID, SysDateAdded, SysDateUpdated, Address1, Address2, Address3, CallWhen, City, ColComment,
      CustomerName, ContactName, Country, county, Division, EmailAddress, Ext1, Ext2, GoalofCall, HotButton, LastCalled, Leadstatus,
      Birthday, PersonalData, PersonalIntr, ZipCode, ReportsTo, Salutation, Specialty, State, Phone1, Phone2, FAXnumber, Title, TypeUpdate,
      cellPhone, Pager, SysParentTable, ReportsToID, Child3Birthday, Child3Info, Child3Name, Department, Hobbies, MoveDate, MoveTo,
      NewColumn1, NewColumn2, NewColumn3, NewColumn4, NewColumn5, NewColumn6, NewColumn7, NewColumn8, OrphanContact,
      Spouse, Spousebd, SpouseInfo, WedAnniv, QBType, PhoneType, ContactIDnumber, ContactNumber, ContactPurpose, CountryPhoneCode,
      FirstName, LastName, YearStarted, CorpID, ContactNameOldSys

      from Xcontacts where newcolumn8 = 'X'";

      $sql3 = "
      UPDATE Xcontacts
      WHERE NEWCOLUMN8 = 'X' ";

      $sql4 = "
      UPDATE contacts
      WHERE NEWCOLUMN8 = 'X' ";

      $getinfo = $dbh->prepare($sql1);
      $rcount1 = $getinfo->rows;
      print OUTFILE ("SQL1 execute finished -- $rcount1 \n");

      $getinfo = $dbh->prepare($sql2);
      $rcount2 = $getinfo->rows;
      print OUTFILE ("SQL2 execute finished -- $rcount2\n");

      $getinfo = $dbh->prepare($sql2a);
      $rcount2a = $getinfo->rows;
      print OUTFILE ("SQL2a execute finished -- $rcount2a\n");

      $getinfo = $dbh->prepare($sql3);
      $rcount3 = $getinfo->rows;
      print OUTFILE ("SQL3 execute finished -- $rcount3\n");

      $getinfo = $dbh->prepare($sql4);
      $rcount4 = $getinfo->rows;
      print OUTFILE ("SQL4 execute finished -- $rcount4\n");

      close (OUTFILE);
        Nothing in that jumps out at me as wrong (on the Perl side) except that you don't set RaiseError, warnings, or strict. Perhaps adding those will give you some more information.

        On the off-chance that there's a bug in your version of DBD::ODBC's rows(), you could see if the results are any different with just $rcount2 = $getinfo->execute() which should also return the rows affected for non-SELECT statements.

Re: DBI on windows problem
by Gangabass (Vicar) on Nov 01, 2007 at 04:05 UTC

    Please, show your code (and maybe SQL-code for table creation).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://648420]
Approved by GrandFather
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2018-01-24 08:42 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (256 votes). Check out past polls.