473,785 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 16001
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.pytho n:
>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.exec ute)
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
2088
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" src="page.html"> </frameset>
2
4309
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; } else {.......
9
24975
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
3874
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 columns, but I'd settle for the message appearing in a single cell, or header/footer line. maybe there's a way to make the whole control invisible when there are no rows in the data source.
0
2226
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 only shows grid lines around rows that have data in it. If there are not enough rows to fill the height of the grid, then the grid lines don't show up around the "empty rows" I say "empty rows" because there actually a row there. So it seems...
17
4586
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
2083
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 create an store procedure for insert BUT if tomorrow I need to add more fields and rows in sql, I would like not touch nothing in my code.
5
3875
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 example I have 200804140340 200804140350 200804140400 200804140410
8
2757
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 addRow = table.insertRow(rowCount); addRow.id = cnt; var addCell = addRow.insertCell(1); addCell.id = cnt;
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.