mysql "rows affected"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carl K

    #1

    mysql "rows affected"

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

    How can I tell how many rows were affected ?

    Carl K
  • John Nagle

    #2
    Re: mysql "rows affected"

    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

    Comment

    • Carl K

      #3
      Re: mysql "rows affected"

      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

      Comment

      • Carl K

        #4
        Re: mysql "rows affected"

        Dennis Lee Bieber wrote:
        On Thu, 26 Apr 2007 18:18:57 -0700, John Nagle <nagle@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

        Comment

        Working...