Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I ran this code and ->rows was never zero. I ran it on the data that is at the bottom.
use DBI; my $db = 'Pg'; my $database = 'test'; my $user = 'test'; my $password = 'test'; my $dbh = DBI->connect( "DBI:${db}:database=" . $database . ";", $user, $password, { RaiseError => 1, PrintError => 1, PrintWarn => 1, # AutoCommit => 0, } ); $dbh->begin_work; my $st = $dbh->prepare('delete from test where inc = ?'); for my $x (2, 4, 6) { my $ra = $st->execute($x); print $st->rows, "\n"; } $dbh->rollback;
The output of this is:
1
1
1

Here is the a dump of the database that I used.

-- -- PostgreSQL database dump -- SET client_encoding = 'UTF8'; SET check_function_bodies = false; SET client_min_messages = warning; -- -- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: postgres -- COMMENT ON SCHEMA public IS 'Standard public schema'; CREATE USER test WITH PASSWORD 'test'; SET search_path = public, pg_catalog; SET default_tablespace = ''; SET default_with_oids = false; -- -- Name: test; Type: TABLE; Schema: public; Owner: test; Tablespace: -- CREATE TABLE test ( inc integer, test character varying(40) ); ALTER TABLE public.test OWNER TO test; -- -- Data for Name: test; Type: TABLE DATA; Schema: public; Owner: test -- COPY test (inc, test) FROM stdin; 1 a 2 b 3 b 4 b 5 b 6 c \. GRANT ALL ON TABLE test TO test;

You might want to run a simple test like this to check that the problem is in DBI and not in your logic.

-- gam3
A picture is worth a thousand words, but takes 200K.

In reply to Re: rows affected inside a transaction by gam3
in thread rows affected inside a transaction by x5150

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (7)
    As of 2014-07-11 08:53 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (222 votes), past polls