Cursor.find
此方法使用指定的索引 idx 和键值在数据库中查找对象。如果找到则返回对象实例,否则返回 None。
Cursor.find(cls, idx, value)
参数
cls
要搜索的类。
idx
用于搜索的索引名称。
value
要查找的值(如果索引是复合索引,则将索引组件的所有值作为元组传递)。
返回
Object
(如果搜索成功)指定类的对象。
无
未找到与指定值相对应的对象。
An object of specified class (if search is successful) | |
---|---|
No object found corresponding to the specified value |
示例
conn = db.connect()
conn.startTransaction(exdb.Transaction.MCO_READ_WRITE)
# Perform simple index search: locate Record by id
cursor = conn.cursor()
# find record to update
rec = cursor.find("Record", "by_i4", 2)
# update object
rec.str = "Updated string"
cursor.close() #release cursor
conn.commit() # commit changes