|
| 1 | +.. _pipelineobj: |
| 2 | + |
| 3 | +********************* |
| 4 | +API: Pipeline Objects |
| 5 | +********************* |
| 6 | + |
| 7 | +.. note:: |
| 8 | + |
| 9 | + In this release, pipelining support is experimental and subject to change. |
| 10 | + |
| 11 | +See :ref:`pipelining` for more information about pipelining. |
| 12 | + |
| 13 | +.. note:: |
| 14 | + |
| 15 | + True pipelining is only available when connected to Oracle Database 23ai. |
| 16 | + |
| 17 | +.. versionadded:: 2.4.0 |
| 18 | + |
| 19 | +.. _pipelineobjs: |
| 20 | + |
| 21 | +Pipeline Objects |
| 22 | +================ |
| 23 | + |
| 24 | +Pipeline objects represent a pipeline used to execute multiple database |
| 25 | +operations. A Pipeline object is created by calling |
| 26 | +:meth:`oracledb.create_pipeline()`. |
| 27 | + |
| 28 | +.. _pipelinemethods: |
| 29 | + |
| 30 | +Pipeline Methods |
| 31 | +---------------- |
| 32 | + |
| 33 | +.. method:: Pipeline.add_callfunc(name, return_type, parameters=None, keyword_parameters=None) |
| 34 | + |
| 35 | + Adds an operation that calls a stored PL/SQL function with the given |
| 36 | + parameters and return type. When the Pipeline is executed, the |
| 37 | + :ref:`PipelineOpResult object <pipelineopresultobjs>` that is returned for |
| 38 | + this operation will have the :attr:`~PipelineOpResult.return_value` |
| 39 | + attribute populated with the return value of the PL/SQL function if the |
| 40 | + call completes successfully. |
| 41 | + |
| 42 | +.. method:: Pipeline.add_callproc(name, parameters=None, keyword_parameters=None) |
| 43 | + |
| 44 | + Adds an operation that calls a stored procedure with the given parameters. |
| 45 | + |
| 46 | +.. method:: Pipeline.add_commit() |
| 47 | + |
| 48 | + Adds an operation that performs a commit. |
| 49 | + |
| 50 | +.. method:: Pipeline.add_execute(statement, parameters=None) |
| 51 | + |
| 52 | + Adds an operation that executes a statement with the given parameters. |
| 53 | + |
| 54 | + Do not use this for queries that return rows. Instead use |
| 55 | + :meth:`Pipeline.add_fetchall()`, :meth:`Pipeline.add_fetchmany()`, or |
| 56 | + :meth:`Pipeline.add_fetchone()`. |
| 57 | + |
| 58 | +.. method:: Pipeline.add_executemany(statement, parameters) |
| 59 | + |
| 60 | + Adds an operation that executes a statement multiple times with the given |
| 61 | + parameter mappings or sequences found in the sequence parameters. |
| 62 | + |
| 63 | + If there are no parameters, the number of iterations can be specified as an |
| 64 | + integer instead of needing to provide a list of empty mappings or |
| 65 | + sequences. |
| 66 | + |
| 67 | +.. method:: Pipeline.add_fetchall(statement, parameters=None, arraysize=None, rowfactory=None) |
| 68 | + |
| 69 | + Adds an operation that executes a query and returns all of the rows from |
| 70 | + the result set. When the Pipeline is executed, the :ref:`PipelineOpResult |
| 71 | + object <pipelineopresultobjs>` that is returned for this operation will |
| 72 | + have the :attr:`~PipelineOpResult.rows` attribute populated with the list |
| 73 | + of rows returned by the query. |
| 74 | + |
| 75 | + The default value for ``arraysize`` is :attr:`defaults.arraysize`. |
| 76 | + |
| 77 | + Internally, this operation's :attr:`Cursor.prefetchrows` size is set to the |
| 78 | + value of the explicit or default ``arraysize`` parameter value. |
| 79 | + |
| 80 | +.. method:: Pipeline.add_fetchmany(statement, parameters=None, num_rows=None, rowfactory=None) |
| 81 | + |
| 82 | + Adds an operation that executes a query and returns up to the specified |
| 83 | + number of rows from the result set. When the Pipeline is executed, the |
| 84 | + :ref:`PipelineOpResult object <pipelineopresultobjs>` that is returned for |
| 85 | + this operation will have the :attr:`~PipelineOpResult.rows` attribute |
| 86 | + populated with the list of rows returned by the query. |
| 87 | + |
| 88 | + The default value for ``num_rows`` is the value of |
| 89 | + :attr:`defaults.arraysize`. |
| 90 | + |
| 91 | + Internally, this operation's :attr:`Cursor.prefetchrows` size is set to the |
| 92 | + value of the explicit or default ``num_rows`` parameter, allowing all rows |
| 93 | + to be fetched in one :ref:`round-trip <roundtrips>` |
| 94 | + |
| 95 | + Since only one fetch is performed for a query operation, consider adding a |
| 96 | + ``FETCH NEXT`` clause to the statement to prevent the database processing |
| 97 | + rows that will never be fetched, see :ref:`rowlimit`. |
| 98 | + |
| 99 | +.. method:: Pipeline.add_fetchone(statement, parameters=None, rowfactory=None) |
| 100 | + |
| 101 | + Adds an operation that executes a query and returns the first row of the |
| 102 | + result set if one exists. When the Pipeline is executed, the |
| 103 | + :ref:`PipelineOpResult object <pipelineopresultobjs>` that is returned for |
| 104 | + this operation will have the :attr:`~PipelineOpResult.rows` attribute |
| 105 | + populated with this row if the query is performed successfully. |
| 106 | + |
| 107 | + Internally, this operation's :attr:`Cursor.prefetchrows` and |
| 108 | + :attr:`Cursor.arraysize` sizes will be set to 1. |
| 109 | + |
| 110 | + Since only one fetch is performed for a query operation, consider adding a |
| 111 | + ``WHERE`` condition or using a ``FETCH NEXT`` clause in the statement to |
| 112 | + prevent the database processing rows that will never be fetched, see |
| 113 | + :ref:`rowlimit`. |
| 114 | + |
| 115 | +Pipeline Attributes |
| 116 | +------------------- |
| 117 | + |
| 118 | +.. attribute:: Pipeline.operations |
| 119 | + |
| 120 | + This read-only attribute returns the list of operations associated with |
| 121 | + the pipeline. |
| 122 | + |
| 123 | +.. _pipelineopobjs: |
| 124 | + |
| 125 | +PipelineOp Objects |
| 126 | +================== |
| 127 | + |
| 128 | +PipelineOp objects are created by calling the methods in the |
| 129 | +:ref:`Pipeline class <pipelineobjs>`. |
| 130 | + |
| 131 | +PipelineOp Attributes |
| 132 | +--------------------- |
| 133 | + |
| 134 | +.. attribute:: PipelineOp.arraysize |
| 135 | + |
| 136 | + This read-only attribute returns the :ref:`array size <tuningfetch>` that |
| 137 | + will be used when fetching query rows with :meth:`Pipeline.add_fetchall()`. |
| 138 | + For all other operations, the value returned is 0. |
| 139 | + |
| 140 | +.. attribute:: PipelineOp.keyword_parameters |
| 141 | + |
| 142 | + This read-only attribute returns the keyword parameters to the stored |
| 143 | + procedure or function being called by the operation, if applicable. |
| 144 | + |
| 145 | +.. attribute:: PipelineOp.name |
| 146 | + |
| 147 | + This read-only attribute returns the name of the stored procedure or |
| 148 | + function being called by the operation, if applicable. |
| 149 | + |
| 150 | +.. attribute:: PipelineOp.num_rows |
| 151 | + |
| 152 | + This read-only attribute returns the number of rows to fetch when |
| 153 | + performing a query of a specific number of rows. For all other operations, |
| 154 | + the value returned is 0. |
| 155 | + |
| 156 | +.. attribute:: PipelineOp.op_type |
| 157 | + |
| 158 | + This read-only attribute returns the type of operation that is taking |
| 159 | + place. See :ref:`pipeline-operation-types` for types of operations. |
| 160 | + |
| 161 | +.. attribute:: PipelineOp.parameters |
| 162 | + |
| 163 | + This read-only attribute returns the parameters to the stored procedure or |
| 164 | + function or the parameters bound to the statement being executed by the |
| 165 | + operation, if applicable. |
| 166 | + |
| 167 | +.. attribute:: PipelineOp.return_type |
| 168 | + |
| 169 | + This read-only attribute returns the return type of the stored function |
| 170 | + being called by the operation, if applicable. |
| 171 | + |
| 172 | +.. attribute:: PipelineOp.rowfactory |
| 173 | + |
| 174 | + This read-only attribute returns the row factory callable function to be |
| 175 | + used in a query executed by the operation, if applicable. |
| 176 | + |
| 177 | +.. attribute:: PipelineOp.statement |
| 178 | + |
| 179 | + This read-only attribute returns the statement being executed by the |
| 180 | + operation, if applicable. |
| 181 | + |
| 182 | +.. _pipelineopresultobjs: |
| 183 | + |
| 184 | +PipelineOpResult Objects |
| 185 | +======================== |
| 186 | + |
| 187 | +PipelineOpResult objects are returned in list when calling |
| 188 | +:meth:`AsyncConnection.run_pipeline()`. These objects contain the results of |
| 189 | +the executed :ref:`PipelineOp objects <pipelineopobjs>` operations. |
| 190 | + |
| 191 | +PipelineOpResult Attributes |
| 192 | +--------------------------- |
| 193 | + |
| 194 | +.. attribute:: PipelineOpResult.error |
| 195 | + |
| 196 | + This read-only attribute returns the error that occurred when running this |
| 197 | + operation. If no error occurred, then the value None is returned. |
| 198 | + |
| 199 | +.. attribute:: PipelineOpResult.operation |
| 200 | + |
| 201 | + This read-only attribute returns the operation associated with the result. |
| 202 | + |
| 203 | +.. attribute:: PipelineOpResult.return_value |
| 204 | + |
| 205 | + This read-only attribute returns the return value of the called PL/SQL |
| 206 | + function, if a function was called for the operation. |
| 207 | + |
| 208 | +.. attribute:: PipelineOpResult.rows |
| 209 | + |
| 210 | + This read-only attribute returns the rows that were fetched by the |
| 211 | + operation, if a query was executed. |
0 commit comments