473,379 Members | 1,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

mysql "rows affected"

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

How can I tell how many rows were affected ?

Carl K
Apr 26 '07 #1
3 15916
Carl K wrote:
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
Apr 27 '07 #2
John Nagle wrote:
Carl K wrote:
>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
cursor.rowcount - bingo. Thanks a bunch.

Carl K
Apr 27 '07 #3
Dennis Lee Bieber wrote:
On Thu, 26 Apr 2007 18:18:57 -0700, John Nagle <na***@animats.com>
declaimed the following in comp.lang.python:
>Carl K wrote:
>>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

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

rws = cursor.execute(...)
-=-=-=-=-=-=-
>>>help(cr.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
Apr 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Max | last post by:
Hello everybody, I have a problem with javascript. Basically I have a frame that is split with this code: <frameset rows="0,*"> <frame name="top" src="nothing.html"> <frame name="center"...
2
by: Kiki | last post by:
Hi, just a small question. I've just looked at a friends code and he's done this: int rowsAffected = sql.ExecuteNonQuery("stored_procedure", cmdParams); if(rowsAffected < 1) { return false; }...
9
by: jensen bredal | last post by:
I have a dataView and i only want to get the first x rows . Is there a way of doing this without using Foreach? Thanks JB
3
by: Andy Fish | last post by:
Hi, when there are no rows to display in my asp.net datagrid control, I'd like to put in a message saying "No results" or some such Ideally I'd like the message to be centred across all the...
0
by: romancoelho | last post by:
Hey everyone, I know this has to be simple, but can't figure out how to do it. How can I display the grid lines in all rows in the gird. The default behavior of the DataGridView seems to be that it...
17
by: pbd22 | last post by:
Hi. How does one return a range of rows. I know that "Top 5" will return rows 0 - 5 but, how do I get 6 - 10? thanks
3
by: nkoriginal | last post by:
Hi: I want to create an store procedure for an ASP page. I've a form with 100 fields and I want to insert the information in: 1) one table with 100 rows or 2) in 5 tables Now, my idea is...
5
by: maury | last post by:
Hello, I have a DB table with data filled from a weather sensor probe, I have one row every 10 minutes and the data fields is not in DateTime format but in string format: yyyyMMddHHmm So for...
8
by: phub11 | last post by:
Hi - I have a function which appends row(s) to the bottom of a table: function mouseUpHandler() { var table = document.getElementById("mytable"); var rowCount = table.rows.length; var...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.