@@ -312,10 +312,10 @@ cursors created by that connection will have their fetch type handling changed.
312312The output type handler is expected to be a function with the following
313313signature::
314314
315- handler(cursor, name, default_type, size, precision, scale )
315+ handler(cursor, metadata )
316316
317- The parameters are the same information as the query column metadata found in
318- :attr: `Cursor.description `.
317+ The metadata parameter is a :ref: ` FetchInfo object<fetchinfoobj> `, which is the
318+ same value found in :attr: `Cursor.description `.
319319
320320The function is called once for each column that is going to be
321321fetched. The function is expected to return a :ref: `variable object <varobj >`
@@ -326,8 +326,8 @@ For example:
326326
327327.. code-block :: python
328328
329- def output_type_handler (cursor , name , default_type , size , precision , scale ):
330- if default_type == oracledb.DB_TYPE_NUMBER :
329+ def output_type_handler (cursor , metadata ):
330+ if metadata.type_code is oracledb.DB_TYPE_NUMBER :
331331 return cursor.var(oracledb.DB_TYPE_VARCHAR , arraysize = cursor.arraysize)
332332
333333 This output type handler is called once for each column in the SELECT query.
@@ -375,15 +375,15 @@ For example:
375375
376376.. code-block :: python
377377
378- def output_type_handler (cursor , name , default_type , size , precision , scale ):
378+ def output_type_handler (cursor , metadata ):
379379
380380 def out_converter (d ):
381381 if isinstance (d, str ):
382382 return f " { d} was a string "
383383 else :
384384 return f " { d} was not a string "
385385
386- if default_type == oracledb.DB_TYPE_NUMBER :
386+ if metadata.type_code is oracledb.DB_TYPE_NUMBER :
387387 return cursor.var(oracledb.DB_TYPE_VARCHAR ,
388388 arraysize = cursor.arraysize, outconverter = out_converter)
389389
@@ -456,15 +456,15 @@ An example showing an :ref:`output type handler <outputtypehandlers>`, an
456456
457457.. code-block :: python
458458
459- def output_type_handler (cursor , name , default_type , size , precision , scale ):
459+ def output_type_handler (cursor , metadata ):
460460
461461 def out_converter (d ):
462462 if type (d) is str :
463463 return f " { d} was a string "
464464 else :
465465 return f " { d} was not a string "
466466
467- if default_type == oracledb.DB_TYPE_NUMBER :
467+ if metadata.type_code is oracledb.DB_TYPE_NUMBER :
468468 return cursor.var(oracledb.DB_TYPE_VARCHAR ,
469469 arraysize = cursor.arraysize, outconverter = out_converter)
470470
@@ -532,8 +532,8 @@ to use an :ref:`output type handler <outputtypehandlers>` do the conversion.
532532
533533 import decimal
534534
535- def number_to_decimal (cursor , name , default_type , size , precision , scale ):
536- if default_type == oracledb.DB_TYPE_NUMBER :
535+ def number_to_decimal (cursor , metadata ):
536+ if metadata.type_code is oracledb.DB_TYPE_NUMBER :
537537 return cursor.var(decimal.Decimal, arraysize = cursor.arraysize)
538538
539539 cursor.outputtypehandler = number_to_decimal
@@ -824,9 +824,8 @@ The following sample demonstrates how to use this feature:
824824 .. code-block :: python
825825
826826 # define output type handler
827- def return_strings_as_bytes (cursor , name , default_type , size ,
828- precision , scale ):
829- if default_type == oracledb.DB_TYPE_VARCHAR :
827+ def return_strings_as_bytes (cursor , metadata ):
828+ if metadata.type_code is oracledb.DB_TYPE_VARCHAR :
830829 return cursor.var(str , arraysize = cursor.arraysize,
831830 bypass_decode = True )
832831
@@ -900,9 +899,10 @@ columns:
900899
901900.. code-block :: python
902901
903- def output_type_handler (cursor , name , default_type , size , precision , scale ):
904- if default_type == oracledb.DB_TYPE_VARCHAR :
905- return cursor.var(default_type, size, arraysize = cursor.arraysize,
902+ def output_type_handler (cursor , metadata ):
903+ if metadata.type_code is oracledb.DB_TYPE_VARCHAR :
904+ return cursor.var(metadata.type_code, size,
905+ arraysize = cursor.arraysize,
906906 encoding_errors = " replace" )
907907
908908 cursor.outputtypehandler = output_type_handler
0 commit comments