Hi all, I'm trying to load multiple rows into table A and table B in an mssqlserver database. i use pseudocode below because the details are not at all important. the below also assumes i have connected to a database successfully:
eval { #table A foreach line (...) { prepare, execute, commit } #table B prepare, execute, commit } if ( $@ ) { rollback; }
i have two questions regarding the above pseudocode:

1) after loading 1552 rows into table A, sqlserver generates a "String or binary data would be truncated" error. The code jumps out of the eval block and hits the rollback statement. the end result is that table A has 1552 rows and table B has 0 rows. Shouldn't table A be rolled back to 0? this leads me to question #2

2) Should the pseudocode look more like below:

eval { #table A foreach line (...) { prepare, execute } #table B prepare, execute } if ( $@ ) { rollback } else { commit; }
iow, should i be committing after each execute or after performing all executes? The latter seems like it would be alot more efficient, but is it possible?

In reply to DBI and transactions by Anonymous Monk

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.