Okay, I'm setting up a transaction with my basic eval block. I'm running through several update and insert statements which, along the way, i must compare the rows affected to other select query information. What I've run into is that my select statements always return 0 rows when using the same database connection yet with a seperate connection, it returns properly. Having recently switched from Oraperl to DBI, I wasn't sure if this was as intended or I'm just doing something wrong...sample code follows:
# Begin the SQL Stuff eval { ############################### # Begin stu_drop.updt section # ############################### print "Beginning stu_drop.updt section...\n"; # Open stu_drop.log file open(LOG, ">stu_drop.log") or die "Couldn't open log file: $@\n"; $sql = "UPDATE saturn.sfrstcr SET sfrstcr_rsts_code = 'DB', sfrstcr_error_flag = 'D', sfrstcr_rsts_date = SYSDATE, sfrstcr_activity_date = SYSDATE WHERE sfrstcr_term_code = '$term_code' AND sfrstcr_rsts_code LIKE 'R%' AND sfrstcr_pidm IN (SELECT DISTINCT pidm FROM studrop +)"; $sth = $dbh->prepare($sql); $sth->execute(); $rows_affected = $sth->rows; $sth->finish(); print "Rows affected by stu_drop.updt: $rows_affected\n"; print LOG "$sql\n\nRows affected: $rows_affected\n\n"; $sql = "SELECT count(*) THE_COUNT FROM sfrstcr, spriden WHERE sfrstcr_term_code='$term_code' AND sfrstcr_pidm in ( SELECT pidm FROM studrop ) AND sfrstcr_rsts_code like 'R%' AND sfrstcr_pidm=spriden_pidm AND spriden_change_ind IS NULL AND spriden_entity_ind ='P'"; $sth2 = $dbh2->prepare($sql); $sth2->execute(); print LOG $sql . "\n"; while(@row = $sth2->fetchrow_array) { ($row_count) = @row; print LOG "Rows pulled from stu_drop_list: $row_count\n"; } $sth2->finish(); if ($row_count == $rows_affected) { print "No prob with counts\n"; } else { print "stu_drop_list = $row_count but other = $rows_affect +ed!\n"; $dbh->rollback; $dbh->disconnect(); $dbh2->disconnect(); exit 1; } close(LOG);

Originally posted as a Categorized Question.


In reply to Are 2 database connections neccesary w/DBI? by mculey

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.