fetchone([uselob]) Method

Fetches the next row of a result set.

Syntax

cursor.fetchone([uselob])

Parameters

Recommended Type Name Description
Boolean uselob

Controls how LOB data is returned. If uselob is set to TRUE, then objects of the LOB class are returned in the result set for CLOBs/NCLOBs/BLOBs instead of the actual values. If you do not specify uselob as TRUE, it leads to a cut-off of the actual value which results in application errors.

The following example displays an out-of-date application code that must be updated to match an underlying CLOB column that contains very large JSON-formatted values:

params = controlTenantCur.fetchone()
paramDict = json.loads(params[0])

The following example displays the updated application code:

params = controlTenantCur.fetchone(uselob=TRUE)
paramDict = json.loads(params[0].read())

The uselob parameter is not defined in PEP 249.

Returns

Returns the next row, or None when there is no further data available.

Remarks

An error is returned if the previous call to the execute method did not produce a result set or if a call has not been issued yet.

Example

Fetch a single row.

id = 2
sql = 'SELECT * FROM T1 WHERE ID = :id'
cursor = conn.cursor()
cursor.execute(sql, {"id": id})
row = cursor.fetchone()
print(row)
(2, 'hello again')