Connection.cursor

Create a cursor for retrieving data on this connection.

For an overview see page Python Connection Class

Prototype

 
    Connection.cursor()
     
    or
        
     
    Connection.cursor(cls, idx)
 

Arguments

cls

When specified it creates an “iteration” cursor, which will iterate over all objects of the class cls

idx

When specified the “iteration” cursor will use index idx to iterate over all objects of the class cls; if not specified an autoid or list index will be used or, if no autoid or list is defined for this class, an error will be thrown

Description

This method has 2 different usage variants:

1) Calling cursor() without arguments creates a DB-API style cursor usable for operations like find(), search(), execute(), execute_many(), etc.

2) If a class cls and index idx are specified, it creates an “iteration” cursor, which will iterate over all objects of the specified class using the specified index. If an index is not provided, an autoid or list index will be used. If no autoid or list are defined for this class, an error will be thrown. The class and index may be specified as strings as declared in the schema, or passed as objects taken from the database dictionary. For example, the following two calls are equivalent:

 
    >>>c = conn.cursor(‘myclass’, ‘idx’)
 
    >>>c = conn.cursor(dict.classes[‘myclass’],dict.indexes[’idx’])
 

Returns

cursor The cursor object was instantiated successfully
Exception An exception is thrown with the appropriate error message

Example

     
    conn = db.connect()
    conn.startTransaction(exdb.Transaction.MCO_READ_ONLY)
    cursor = conn.cursor("Record", "by_i4");
    for rec in cursor:
        print 'i4=%s,str="%s"' % (rec.i4, rec.str)
     
    cursor.close(); # close cursor
    conn.rollback(); # end transaction