MySQLdb -- any way to get "rows matched"?

Sheila King sheila at spamcop.net
Tue Sep 2 14:49:15 EDT 2003


On Tue, 2 Sep 2003 11:00:58 -0500, Skip Montanaro <skip at pobox.com> wrote in
comp.lang.python in article
<mailman.1062518530.3141.python-list at python.org>:

> 
>     Chris> When issuing updates in mysql (in the console window), mysql will
>     Chris> tell you if any rows matched and how many rows were updated (see
>     Chris> below).  I know how to get number of rows udpated using MySQLdb,
>     Chris> but is there any way to get the number of rows matched?  
> 
> I believe the return value of the cursor's execute() method gives you the
> number of rows which matched.
> 
> Skip

That's not what this says?

http://groups.google.com/groups?selm=mailman.1062375303.22663.python-list%40python.org

Just for confirmation, a little experimentation:

MYSQL at the command line:

mysql> SELECT * from example;
+--------+------+---------+
| name   | AGE  | COUNTRY |
+--------+------+---------+
| sheila |   30 | US      |
| arthur |   23 | NL      |
| bob    |   30 | US      |
+--------+------+---------+
3 rows in set (0.00 sec)

mysql> UPDATE example SET AGE=30 WHERE AGE=30;
Query OK, 0 rows affected (0.00 sec)
ws matched: 2  Changed: 0  Warnings: 0


MySQLdb in Python:

>>> c = conn.cursor()
>>> c.execute("""UPDATE example SET AGE=30 WHERE AGE=30;""")
0L
>>> c.messages
[]
>>> c.info()
''


Being a MySQL and MySQLdb newbie, I'm not sure if there is any way to find
out how many matched, via Python's MySQLdb module. I thought, from the
source code, that .messages or .info() for the cursor attributes/methods
might do it, but apparently not???


I'm using MySQL  3.23.57 and MySQLdb 0.92


-- 
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




More information about the Python-list mailing list