mysql "rows affected"

C

Carl K

using MySQLdb, I do cursor.execute("update...")

How can I tell how many rows were affected ?

Carl K
 
J

John Nagle

Carl said:
using MySQLdb, I do cursor.execute("update...")

How can I tell how many rows were affected ?

Carl K

cursor = db.cursor() # get cursor
cursor.execute(sqlstatement, argtuple) # do command
rowsaffected = cursor.rowcount # get count of rows affected
cursor.close() # close cursor
db.commit() # commit transaction

John Nagle
 
C

Carl K

John said:
cursor = db.cursor() # get cursor
cursor.execute(sqlstatement, argtuple) # do command
rowsaffected = cursor.rowcount # get count of rows affected
cursor.close() # close cursor
db.commit() # commit transaction

John Nagle

cursor.rowcount - bingo. Thanks a bunch.

Carl K
 
D

Dennis Lee Bieber

cursor = db.cursor() # get cursor
cursor.execute(sqlstatement, argtuple) # do command

According to the documentation, it may be possible to get the result
with

rws = cursor.execute(...)


-=-=-=-=-=-=-Help on method execute in module MySQLdb.cursors:

execute(self, query, args=None) method of MySQLdb.cursors.Cursor
instance
Execute a query.

query -- string, query to execute on server
args -- optional sequence or mapping, parameters to use with query.

Note: If args is a sequence, then %s must be used as the
parameter placeholder in the query. If a mapping is used,
%(key)s must be used as the placeholder.

Returns long integer rows affected, if any
-=-=-=-=-=-=-
rowsaffected = cursor.rowcount # get count of rows affected
cursor.close() # close cursor
db.commit() # commit transaction

John Nagle
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
C

Carl K

Dennis said:
According to the documentation, it may be possible to get the result
with

rws = cursor.execute(...)


-=-=-=-=-=-=-
Help on method execute in module MySQLdb.cursors:

execute(self, query, args=None) method of MySQLdb.cursors.Cursor
instance
Execute a query.

query -- string, query to execute on server
args -- optional sequence or mapping, parameters to use with query.

Note: If args is a sequence, then %s must be used as the
parameter placeholder in the query. If a mapping is used,
%(key)s must be used as the placeholder.

Returns long integer rows affected, if any

-=-=-=-=-=-=-

hey look at that. Thanks.

Carl K
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top