22.API: Pipeline Objects

Pipelining is only supported in python-oracledb Thin mode withasyncio. SeePipelining Database Operations for moreinformation about pipelining.

Note

True pipelining is only available when connected to Oracle Database 23ai.

Added in version 2.4.0.

22.1.Pipeline Objects

Pipeline objects represent a pipeline used to execute multiple databaseoperations. A Pipeline object is created by callingoracledb.create_pipeline().

22.1.1.Pipeline Methods

Pipeline.add_callfunc(name,return_type,parameters=None,keyword_parameters=None)

Adds an operation to the pipeline that calls a stored PL/SQL function withthe given parameters and return type. The createdPipelineOp object is also returned from thisfunction.PipelineOp Attributes can be used to examine the operation, ifneeded.

When the Pipeline is executed, thePipelineOpResult object that is returned forthis operation will have thereturn_valueattribute populated with the return value of the PL/SQL function if thecall completes successfully.

Pipeline.add_callproc(name,parameters=None,keyword_parameters=None)

Adds an operation that calls a stored procedure with the given parameters.The createdPipelineOp object is also returnedfrom this function.PipelineOp Attributes can be used to examine theoperation, if needed.

Pipeline.add_commit()

Adds an operation that performs a commit.

Pipeline.add_execute(statement,parameters=None)

Adds an operation that executes a statement with the given parameters.The createdPipelineOp object is also returnedfrom this function.PipelineOp Attributes can be used to examine theoperation, if needed.

Do not use this for queries that return rows. Instead usePipeline.add_fetchall(),Pipeline.add_fetchmany(), orPipeline.add_fetchone().

Pipeline.add_executemany(statement,parameters)

Adds an operation that executes a SQL statement once using all bind valuemappings or sequences found in the sequence parameters. This can be used toinsert, update, or delete multiple rows in a table. It can also invoke aPL/SQL procedure multiple times. SeeBatch Statement and Bulk Copy Operations.

The createdPipelineOp object is also returned fromthis function.PipelineOp Attributes can be used to examine the operation,if needed.

Theparameters parameter can be a list of tuples, where each tuple itemmaps to one bind variable placeholder instatement. It can also be alist of dictionaries, where the keys match the bind variable placeholdernames instatement. If there are no bind values, or values havepreviously been bound, theparameters value can be an integerspecifying the number of iterations.

Pipeline.add_fetchall(statement,parameters=None,arraysize=None,rowfactory=None)

Adds an operation that executes a query and returns all of the rows fromthe result set. The createdPipelineOp object isalso returned from this function.PipelineOp Attributes can be used toexamine the operation, if needed.

When the Pipeline is executed, thePipelineOpResultobject that is returned for this operation willhave therows attribute populated with the listof rows returned by the query.

The default value forarraysize isdefaults.arraysize.

Internally, this operation’sCursor.prefetchrows size is set to thevalue of the explicit or defaultarraysize parameter value.

Pipeline.add_fetchmany(statement,parameters=None,num_rows=None,rowfactory=None)

Adds an operation that executes a query and returns up to the specifiednumber of rows from the result set. The createdPipelineOp object is also returned from thisfunction.PipelineOp Attributes can be used to examine the operation, ifneeded.

When the Pipeline is executed, thePipelineOpResult object that is returned forthis operation will have therows attributepopulated with the list of rows returned by the query.

The default value fornum_rows is the value ofdefaults.arraysize.

Internally, this operation’sCursor.prefetchrows size is set to thevalue of the explicit or defaultnum_rows parameter, allowing all rowsto be fetched in oneround-trip

Since only one fetch is performed for a query operation, consider adding aFETCHNEXT clause to the statement to prevent the database processingrows that will never be fetched, seeLimiting Rows.

Pipeline.add_fetchone(statement,parameters=None,rowfactory=None)

Adds an operation that executes a query and returns the first row of theresult set if one exists. The createdPipelineOp object is also returned from thisfunction.PipelineOp Attributes can be used to examine the operation, ifneeded.

When the Pipeline is executed, thePipelineOpResult object that is returned forthis operation will have therows attributepopulated with this row if the query is performed successfully.

Internally, this operation’sCursor.prefetchrows andCursor.arraysize sizes will be set to 1.

Since only one fetch is performed for a query operation, consider adding aWHERE condition or using aFETCHNEXT clause in the statement toprevent the database processing rows that will never be fetched, seeLimiting Rows.

22.1.2.Pipeline Attributes

Pipeline.operations

This read-only attribute returns the list of operations associated withthe pipeline.

22.2.PipelineOp Objects

PipelineOp objects are created by calling the methods in thePipeline class.

22.2.1.PipelineOp Attributes

PipelineOp.arraysize

This read-only attribute returns thearray size thatwill be used when fetching query rows withPipeline.add_fetchall().For all other operations, the value returned is0.

PipelineOp.keyword_parameters

This read-only attribute returns the keyword parameters to the storedprocedure or function being called by the operation, if applicable.

PipelineOp.name

This read-only attribute returns the name of the stored procedure orfunction being called by the operation, if applicable.

PipelineOp.num_rows

This read-only attribute returns the number of rows to fetch whenperforming a query of a specific number of rows. For all other operations,the value returned is0.

PipelineOp.op_type

This read-only attribute returns the type of operation that is takingplace. SeePipeline Operation Types for types of operations.

PipelineOp.parameters

This read-only attribute returns the parameters to the stored procedure orfunction or the parameters bound to the statement being executed by theoperation, if applicable.

PipelineOp.return_type

This read-only attribute returns the return type of the stored functionbeing called by the operation, if applicable.

PipelineOp.rowfactory

This read-only attribute returns the row factory callable function to beused in a query executed by the operation, if applicable.

PipelineOp.statement

This read-only attribute returns the statement being executed by theoperation, if applicable.

22.3.PipelineOpResult Objects

WhenAsyncConnection.run_pipeline() is called, it returns a list ofPipelineOpResult objects. These objects contain the results of the executedPipelineOp objects operations.

22.3.1.PipelineOpResult Attributes

PipelineOpResult.columns

This read-only attribute is a list ofFetchInfoobjects. This attribute will beNone for operations that do not returnrows.

Added in version 2.5.0.

PipelineOpResult.error

This read-only attribute returns the error that occurred when running thisoperation. If no error occurred, then the valueNone is returned.

PipelineOpResult.operation

This read-only attribute returns thePipelineOpoperation object that generated the result.

PipelineOpResult.return_value

This read-only attribute returns the return value of the called PL/SQLfunction, if a function was called for the operation.

PipelineOpResult.rows

This read-only attribute returns the rows that were fetched by theoperation, if a query was executed.

PipelineOpResult.warning

This read-only attribute returns any warning that was encountered whenrunning this operation. If no warning was encountered, then the valueNone is returned. SeePL/SQL Compilation Warnings.

Added in version 2.5.0.