Okay, good idea, graff. Here's what I did:

use strict; use warnings; use DBI; use Try::Tiny; $|=1; my $redo; my $dbh; print 'mysql username: '; chomp(my $username=<STDIN>); print 'mysql password: '; system('stty','-echo');chomp(my $pw=<STDIN>);system('stty','echo'); print $/; sub reconn { $dbh = DBI->connect('dbi:mysql:scratch;mysql_enable_utf8=1',$usernam +e,$pw,{mysql_auto_reconnect => 1}) or die $DBI::errstr; } reconn; my $sth; # MariaDB [scratch]> create table foo(bar int,baz int,primary key(bar) +); # Query OK, 0 rows affected (0.02 sec) # # MariaDB [scratch]> insert foo(bar)value(1); # Query OK, 1 row affected (0.01 sec) # # MariaDB [scratch]> desc foo; # +-------+---------+------+-----+---------+-------+ # | Field | Type | Null | Key | Default | Extra | # +-------+---------+------+-----+---------+-------+ # | bar | int(11) | NO | PRI | 0 | | # | baz | int(11) | YES | | NULL | | # +-------+---------+------+-----+---------+-------+ # 2 rows in set (0.00 sec) # # # MariaDB [scratch]> select * from foo; # +-----+------+ # | bar | baz | # +-----+------+ # | 1 | NULL | # +-----+------+ # 1 row in set (0.00 sec) $\=$/; my $rows; $dbh->ping or reconn; $sth = $dbh->prepare("insert foo(bar)value(2);"); $redo = 1; while ($redo) {$redo=0; try {$rows=$sth->execute();} catch +{$redo = /deadlock found/i;}} print "new: $rows"; undef $rows; $dbh->ping or reconn; $sth = $dbh->prepare("insert ignore foo(bar)value(1);"); $redo = 1; while ($redo) {$redo=0; try {$rows=$sth->execute();} catch +{$redo = /deadlock found/i;}} print "old ignore: $rows"; undef $rows; $dbh->ping or reconn; $sth = $dbh->prepare("insert foo(bar)value(1) on duplicate key update +baz=1;"); $redo = 1; while ($redo) {$redo=0; try {$rows=$sth->execute();} catch +{$redo = /deadlock found/i;}} print "old on duplicate key update: $rows";

And the results were:

new: 1 old ignore: 0E0 old on duplicate key update: 2

And row_count gives the same numbers (in these cases):

# MariaDB [scratch]> select * from foo; # +-----+------+ # | bar | baz | # +-----+------+ # | 1 | NULL | # +-----+------+ # 1 row in set (0.00 sec) # # MariaDB [scratch]> insert foo(bar)value(2); # Query OK, 1 row affected (0.00 sec) # # MariaDB [scratch]> select row_count(); # +-------------+ # | row_count() | # +-------------+ # | 1 | # +-------------+ # 1 row in set (0.00 sec) # # MariaDB [scratch]> insert ignore foo(bar)value(1); # Query OK, 0 rows affected, 1 warning (0.00 sec) # # MariaDB [scratch]> select row_count(); # +-------------+ # | row_count() | # +-------------+ # | 0 | # +-------------+ # 1 row in set (0.01 sec) # # MariaDB [scratch]> insert foo(bar)value(1) on duplicate key update b +az=1; # Query OK, 2 rows affected (0.00 sec) # # MariaDB [scratch]> select row_count(); # +-------------+ # | row_count() | # +-------------+ # | 2 | # +-------------+ # 1 row in set (0.00 sec)
$_="msh210";$"=$\;@_=@{[split//,uc]}[2,0];$_="@_$\1";$\=$/;++$_[0]for$...1;print lc substr crypt($_,"@_"),1,6

In reply to Re^2: MySQL row_count and DBI by msh210
in thread MySQL row_count and DBI by msh210

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.