dbapi.py
branchstable
changeset 5307 228932b4f8c5
parent 5100 04c71ebf38a5
child 5328 c51e8f62652a
child 5345 dc9afabbb45b
equal deleted inserted replaced
5306:763319a51e72 5307:228932b4f8c5
   662 
   662 
   663 
   663 
   664 # cursor object ###############################################################
   664 # cursor object ###############################################################
   665 
   665 
   666 class Cursor(object):
   666 class Cursor(object):
   667     """These objects represent a database cursor, which is used to manage the
   667     """This represents a database cursor, which is used to manage the
   668     context of a fetch operation. Cursors created from the same connection are
   668     context of a fetch operation. Cursors created from the same connection are
   669     not isolated, i.e., any changes done to the database by a cursor are
   669     not isolated, i.e., any changes done to the database by a cursor are
   670     immediately visible by the other cursors. Cursors created from different
   670     immediately visible by the other cursors. Cursors created from different
   671     connections can or can not be isolated, depending on how the transaction
   671     connections can or can not be isolated, depending on how the transaction
   672     support is implemented (see also the connection's rollback() and commit()
   672     support is implemented (see also the connection's rollback() and commit()
   673     methods.)
   673     methods.)
   674     """
   674     """
   675 
   675 
   676     def __init__(self, connection, repo, req=None):
   676     def __init__(self, connection, repo, req=None):
   677         """This read-only attribute return a reference to the Connection
   677         # This read-only attribute returns a reference to the Connection
   678         object on which the cursor was created.
   678         # object on which the cursor was created.
   679         """
       
   680         self.connection = connection
   679         self.connection = connection
   681         """optionnal issuing request instance"""
   680         # optionnal issuing request instance
   682         self.req = req
   681         self.req = req
   683 
   682 
   684         """This read/write attribute specifies the number of rows to fetch at a
   683         # This read/write attribute specifies the number of rows to fetch at a
   685         time with fetchmany(). It defaults to 1 meaning to fetch a single row
   684         # time with fetchmany(). It defaults to 1 meaning to fetch a single row
   686         at a time.
   685         # at a time.
   687 
   686         # Implementations must observe this value with respect to the fetchmany()
   688         Implementations must observe this value with respect to the fetchmany()
   687         # method, but are free to interact with the database a single row at a
   689         method, but are free to interact with the database a single row at a
   688         # time. It may also be used in the implementation of executemany().
   690         time. It may also be used in the implementation of executemany().
       
   691         """
       
   692         self.arraysize = 1
   689         self.arraysize = 1
   693 
   690 
   694         self._repo = repo
   691         self._repo = repo
   695         self._sessid = connection.sessionid
   692         self._sessid = connection.sessionid
   696         self._res = None
   693         self._res = None
   697         self._closed = None
   694         self._closed = None
   698         self._index = 0
   695         self._index = 0
   699 
       
   700 
   696 
   701     def close(self):
   697     def close(self):
   702         """Close the cursor now (rather than whenever __del__ is called).  The
   698         """Close the cursor now (rather than whenever __del__ is called).  The
   703         cursor will be unusable from this point forward; an Error (or subclass)
   699         cursor will be unusable from this point forward; an Error (or subclass)
   704         exception will be raised if any operation is attempted with the cursor.
   700         exception will be raised if any operation is attempted with the cursor.
   865         tstart, cstart = time(), clock()
   861         tstart, cstart = time(), clock()
   866         rset = Cursor.execute(self, operation, parameters, eid_key, build_descr)
   862         rset = Cursor.execute(self, operation, parameters, eid_key, build_descr)
   867         self.connection.executed_queries.append((operation, parameters,
   863         self.connection.executed_queries.append((operation, parameters,
   868                                                  time() - tstart, clock() - cstart))
   864                                                  time() - tstart, clock() - cstart))
   869         return rset
   865         return rset
   870