|
14 | 14 |
|
15 | 15 | #include "cxoModule.h" |
16 | 16 |
|
17 | | -//----------------------------------------------------------------------------- |
18 | | -// functions for the Python type "Cursor" |
19 | | -//----------------------------------------------------------------------------- |
20 | | -static void cxoCursor_free(cxoCursor*); |
21 | | -static PyObject *cxoCursor_getIter(cxoCursor*); |
22 | | -static PyObject *cxoCursor_getNext(cxoCursor*); |
23 | | -static PyObject *cxoCursor_close(cxoCursor*, PyObject*); |
24 | | -static PyObject *cxoCursor_callFunc(cxoCursor*, PyObject*, PyObject*); |
25 | | -static PyObject *cxoCursor_callProc(cxoCursor*, PyObject*, PyObject*); |
26 | | -static PyObject *cxoCursor_execute(cxoCursor*, PyObject*, PyObject*); |
27 | | -static PyObject *cxoCursor_executeMany(cxoCursor*, PyObject*, PyObject*); |
28 | | -static PyObject *cxoCursor_executeManyPrepared(cxoCursor*, PyObject*); |
29 | | -static PyObject *cxoCursor_fetchOne(cxoCursor*, PyObject*); |
30 | | -static PyObject *cxoCursor_fetchMany(cxoCursor*, PyObject*, PyObject*); |
31 | | -static PyObject *cxoCursor_fetchAll(cxoCursor*, PyObject*); |
32 | | -static PyObject *cxoCursor_fetchRaw(cxoCursor*, PyObject*, PyObject*); |
33 | | -static PyObject *cxoCursor_parse(cxoCursor*, PyObject*); |
34 | | -static PyObject *cxoCursor_prepare(cxoCursor*, PyObject*); |
35 | | -static PyObject *cxoCursor_scroll(cxoCursor*, PyObject*, PyObject*); |
36 | | -static PyObject *cxoCursor_setInputSizes(cxoCursor*, PyObject*, PyObject*); |
37 | | -static PyObject *cxoCursor_setOutputSize(cxoCursor*, PyObject*); |
38 | | -static PyObject *cxoCursor_var(cxoCursor*, PyObject*, PyObject*); |
39 | | -static PyObject *cxoCursor_arrayVar(cxoCursor*, PyObject*); |
40 | | -static PyObject *cxoCursor_bindNames(cxoCursor*, PyObject*); |
41 | | -static PyObject *cxoCursor_getDescription(cxoCursor*, void*); |
42 | | -static PyObject *cxoCursor_getLastRowid(cxoCursor*, void*); |
43 | | -static PyObject *cxoCursor_getPrefetchRows(cxoCursor*, void*); |
44 | | -static PyObject *cxoCursor_new(PyTypeObject*, PyObject*, PyObject*); |
45 | | -static int cxoCursor_init(cxoCursor*, PyObject*, PyObject*); |
46 | | -static PyObject *cxoCursor_repr(cxoCursor*); |
47 | | -static PyObject* cxoCursor_getBatchErrors(cxoCursor*); |
48 | | -static PyObject *cxoCursor_getArrayDMLRowCounts(cxoCursor*); |
49 | | -static PyObject *cxoCursor_getImplicitResults(cxoCursor*); |
50 | | -static PyObject *cxoCursor_contextManagerEnter(cxoCursor*, PyObject*); |
51 | | -static PyObject *cxoCursor_contextManagerExit(cxoCursor*, PyObject*); |
52 | | -static int cxoCursor_performDefine(cxoCursor*, uint32_t); |
53 | | -static int cxoCursor_setPrefetchRows(cxoCursor*, PyObject*, void*); |
54 | | - |
55 | | - |
56 | | -//----------------------------------------------------------------------------- |
57 | | -// declaration of methods for Python type |
58 | | -//----------------------------------------------------------------------------- |
59 | | -static PyMethodDef cxoCursorMethods[] = { |
60 | | - { "execute", (PyCFunction) cxoCursor_execute, |
61 | | - METH_VARARGS | METH_KEYWORDS }, |
62 | | - { "fetchall", (PyCFunction) cxoCursor_fetchAll, METH_NOARGS }, |
63 | | - { "fetchone", (PyCFunction) cxoCursor_fetchOne, METH_NOARGS }, |
64 | | - { "fetchmany", (PyCFunction) cxoCursor_fetchMany, |
65 | | - METH_VARARGS | METH_KEYWORDS }, |
66 | | - { "fetchraw", (PyCFunction) cxoCursor_fetchRaw, |
67 | | - METH_VARARGS | METH_KEYWORDS }, |
68 | | - { "prepare", (PyCFunction) cxoCursor_prepare, METH_VARARGS }, |
69 | | - { "parse", (PyCFunction) cxoCursor_parse, METH_O }, |
70 | | - { "setinputsizes", (PyCFunction) cxoCursor_setInputSizes, |
71 | | - METH_VARARGS | METH_KEYWORDS }, |
72 | | - { "executemany", (PyCFunction) cxoCursor_executeMany, |
73 | | - METH_VARARGS | METH_KEYWORDS }, |
74 | | - { "callproc", (PyCFunction) cxoCursor_callProc, |
75 | | - METH_VARARGS | METH_KEYWORDS }, |
76 | | - { "callfunc", (PyCFunction) cxoCursor_callFunc, |
77 | | - METH_VARARGS | METH_KEYWORDS }, |
78 | | - { "executemanyprepared", (PyCFunction) cxoCursor_executeManyPrepared, |
79 | | - METH_VARARGS }, |
80 | | - { "setoutputsize", (PyCFunction) cxoCursor_setOutputSize, METH_VARARGS }, |
81 | | - { "scroll", (PyCFunction) cxoCursor_scroll, METH_VARARGS | METH_KEYWORDS }, |
82 | | - { "var", (PyCFunction) cxoCursor_var, METH_VARARGS | METH_KEYWORDS }, |
83 | | - { "arrayvar", (PyCFunction) cxoCursor_arrayVar, METH_VARARGS }, |
84 | | - { "bindnames", (PyCFunction) cxoCursor_bindNames, METH_NOARGS }, |
85 | | - { "close", (PyCFunction) cxoCursor_close, METH_NOARGS }, |
86 | | - { "getbatcherrors", (PyCFunction) cxoCursor_getBatchErrors, METH_NOARGS }, |
87 | | - { "getarraydmlrowcounts", (PyCFunction) cxoCursor_getArrayDMLRowCounts, |
88 | | - METH_NOARGS }, |
89 | | - { "getimplicitresults", (PyCFunction) cxoCursor_getImplicitResults, |
90 | | - METH_NOARGS }, |
91 | | - { "__enter__", (PyCFunction) cxoCursor_contextManagerEnter, METH_NOARGS }, |
92 | | - { "__exit__", (PyCFunction) cxoCursor_contextManagerExit, METH_VARARGS }, |
93 | | - { NULL, NULL } |
94 | | -}; |
95 | | - |
96 | | - |
97 | | -//----------------------------------------------------------------------------- |
98 | | -// declaration of members for Python type |
99 | | -//----------------------------------------------------------------------------- |
100 | | -static PyMemberDef cxoCursorMembers[] = { |
101 | | - { "arraysize", T_UINT, offsetof(cxoCursor, arraySize), 0 }, |
102 | | - { "bindarraysize", T_UINT, offsetof(cxoCursor, bindArraySize), 0 }, |
103 | | - { "rowcount", T_ULONGLONG, offsetof(cxoCursor, rowCount), READONLY }, |
104 | | - { "statement", T_OBJECT, offsetof(cxoCursor, statement), READONLY }, |
105 | | - { "connection", T_OBJECT_EX, offsetof(cxoCursor, connection), READONLY }, |
106 | | - { "rowfactory", T_OBJECT, offsetof(cxoCursor, rowFactory), 0 }, |
107 | | - { "bindvars", T_OBJECT, offsetof(cxoCursor, bindVariables), READONLY }, |
108 | | - { "fetchvars", T_OBJECT, offsetof(cxoCursor, fetchVariables), READONLY }, |
109 | | - { "inputtypehandler", T_OBJECT, offsetof(cxoCursor, inputTypeHandler), |
110 | | - 0 }, |
111 | | - { "outputtypehandler", T_OBJECT, offsetof(cxoCursor, outputTypeHandler), |
112 | | - 0 }, |
113 | | - { "scrollable", T_BOOL, offsetof(cxoCursor, isScrollable), 0 }, |
114 | | - { NULL } |
115 | | -}; |
116 | | - |
117 | | - |
118 | | -//----------------------------------------------------------------------------- |
119 | | -// declaration of calculated members for Python type |
120 | | -//----------------------------------------------------------------------------- |
121 | | -static PyGetSetDef cxoCursorCalcMembers[] = { |
122 | | - { "description", (getter) cxoCursor_getDescription, 0, 0, 0 }, |
123 | | - { "lastrowid", (getter) cxoCursor_getLastRowid, 0, 0, 0 }, |
124 | | - { "prefetchrows", (getter) cxoCursor_getPrefetchRows, |
125 | | - (setter) cxoCursor_setPrefetchRows, 0, 0 }, |
126 | | - { NULL } |
127 | | -}; |
128 | | - |
129 | | - |
130 | | -//----------------------------------------------------------------------------- |
131 | | -// declaration of Python type "Cursor" |
132 | | -//----------------------------------------------------------------------------- |
133 | | -PyTypeObject cxoPyTypeCursor = { |
134 | | - PyVarObject_HEAD_INIT(NULL, 0) |
135 | | - .tp_name = "cx_Oracle.Cursor", |
136 | | - .tp_basicsize = sizeof(cxoCursor), |
137 | | - .tp_dealloc = (destructor) cxoCursor_free, |
138 | | - .tp_repr = (reprfunc) cxoCursor_repr, |
139 | | - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, |
140 | | - .tp_iter = (getiterfunc) cxoCursor_getIter, |
141 | | - .tp_iternext = (iternextfunc) cxoCursor_getNext, |
142 | | - .tp_methods = cxoCursorMethods, |
143 | | - .tp_members = cxoCursorMembers, |
144 | | - .tp_getset = cxoCursorCalcMembers, |
145 | | - .tp_init = (initproc) cxoCursor_init, |
146 | | - .tp_new = cxoCursor_new |
147 | | -}; |
148 | | - |
149 | | - |
150 | 17 | //----------------------------------------------------------------------------- |
151 | 18 | // cxoCursor_new() |
152 | 19 | // Create a new cursor object. |
@@ -254,41 +121,6 @@ static int cxoCursor_isOpen(cxoCursor *cursor) |
254 | 121 | } |
255 | 122 |
|
256 | 123 |
|
257 | | -//----------------------------------------------------------------------------- |
258 | | -// cxoCursor_verifyFetch() |
259 | | -// Verify that fetching may happen from this cursor. |
260 | | -//----------------------------------------------------------------------------- |
261 | | -static int cxoCursor_verifyFetch(cxoCursor *cursor) |
262 | | -{ |
263 | | - uint32_t numQueryColumns; |
264 | | - |
265 | | - // make sure the cursor is open |
266 | | - if (cxoCursor_isOpen(cursor) < 0) |
267 | | - return -1; |
268 | | - |
269 | | - // fixup REF cursor, if applicable |
270 | | - if (cursor->fixupRefCursor) { |
271 | | - cursor->fetchArraySize = cursor->arraySize; |
272 | | - if (dpiStmt_setFetchArraySize(cursor->handle, |
273 | | - cursor->fetchArraySize) < 0) |
274 | | - return cxoError_raiseAndReturnInt(); |
275 | | - if (dpiStmt_getNumQueryColumns(cursor->handle, &numQueryColumns) < 0) |
276 | | - return cxoError_raiseAndReturnInt(); |
277 | | - if (cxoCursor_performDefine(cursor, numQueryColumns) < 0) |
278 | | - return cxoError_raiseAndReturnInt(); |
279 | | - cursor->fixupRefCursor = 0; |
280 | | - } |
281 | | - |
282 | | - // make sure the cursor is for a query |
283 | | - if (!cursor->fetchVariables) { |
284 | | - cxoError_raiseFromString(cxoInterfaceErrorException, "not a query"); |
285 | | - return -1; |
286 | | - } |
287 | | - |
288 | | - return 0; |
289 | | -} |
290 | | - |
291 | | - |
292 | 124 | //----------------------------------------------------------------------------- |
293 | 125 | // cxoCursor_fetchRow() |
294 | 126 | // Fetch a single row from the cursor. Internally the number of rows left in |
@@ -453,6 +285,41 @@ static int cxoCursor_performDefine(cxoCursor *cursor, uint32_t numQueryColumns) |
453 | 285 | } |
454 | 286 |
|
455 | 287 |
|
| 288 | +//----------------------------------------------------------------------------- |
| 289 | +// cxoCursor_verifyFetch() |
| 290 | +// Verify that fetching may happen from this cursor. |
| 291 | +//----------------------------------------------------------------------------- |
| 292 | +static int cxoCursor_verifyFetch(cxoCursor *cursor) |
| 293 | +{ |
| 294 | + uint32_t numQueryColumns; |
| 295 | + |
| 296 | + // make sure the cursor is open |
| 297 | + if (cxoCursor_isOpen(cursor) < 0) |
| 298 | + return -1; |
| 299 | + |
| 300 | + // fixup REF cursor, if applicable |
| 301 | + if (cursor->fixupRefCursor) { |
| 302 | + cursor->fetchArraySize = cursor->arraySize; |
| 303 | + if (dpiStmt_setFetchArraySize(cursor->handle, |
| 304 | + cursor->fetchArraySize) < 0) |
| 305 | + return cxoError_raiseAndReturnInt(); |
| 306 | + if (dpiStmt_getNumQueryColumns(cursor->handle, &numQueryColumns) < 0) |
| 307 | + return cxoError_raiseAndReturnInt(); |
| 308 | + if (cxoCursor_performDefine(cursor, numQueryColumns) < 0) |
| 309 | + return cxoError_raiseAndReturnInt(); |
| 310 | + cursor->fixupRefCursor = 0; |
| 311 | + } |
| 312 | + |
| 313 | + // make sure the cursor is for a query |
| 314 | + if (!cursor->fetchVariables) { |
| 315 | + cxoError_raiseFromString(cxoInterfaceErrorException, "not a query"); |
| 316 | + return -1; |
| 317 | + } |
| 318 | + |
| 319 | + return 0; |
| 320 | +} |
| 321 | + |
| 322 | + |
456 | 323 | //----------------------------------------------------------------------------- |
457 | 324 | // cxoCursor_itemDescription() |
458 | 325 | // Return a tuple describing the item at the given position. |
@@ -2239,3 +2106,97 @@ static int cxoCursor_setPrefetchRows(cxoCursor* cursor, PyObject *value, |
2239 | 2106 | return cxoError_raiseAndReturnInt(); |
2240 | 2107 | return 0; |
2241 | 2108 | } |
| 2109 | + |
| 2110 | + |
| 2111 | +//----------------------------------------------------------------------------- |
| 2112 | +// declaration of methods for Python type |
| 2113 | +//----------------------------------------------------------------------------- |
| 2114 | +static PyMethodDef cxoMethods[] = { |
| 2115 | + { "execute", (PyCFunction) cxoCursor_execute, |
| 2116 | + METH_VARARGS | METH_KEYWORDS }, |
| 2117 | + { "fetchall", (PyCFunction) cxoCursor_fetchAll, METH_NOARGS }, |
| 2118 | + { "fetchone", (PyCFunction) cxoCursor_fetchOne, METH_NOARGS }, |
| 2119 | + { "fetchmany", (PyCFunction) cxoCursor_fetchMany, |
| 2120 | + METH_VARARGS | METH_KEYWORDS }, |
| 2121 | + { "fetchraw", (PyCFunction) cxoCursor_fetchRaw, |
| 2122 | + METH_VARARGS | METH_KEYWORDS }, |
| 2123 | + { "prepare", (PyCFunction) cxoCursor_prepare, METH_VARARGS }, |
| 2124 | + { "parse", (PyCFunction) cxoCursor_parse, METH_O }, |
| 2125 | + { "setinputsizes", (PyCFunction) cxoCursor_setInputSizes, |
| 2126 | + METH_VARARGS | METH_KEYWORDS }, |
| 2127 | + { "executemany", (PyCFunction) cxoCursor_executeMany, |
| 2128 | + METH_VARARGS | METH_KEYWORDS }, |
| 2129 | + { "callproc", (PyCFunction) cxoCursor_callProc, |
| 2130 | + METH_VARARGS | METH_KEYWORDS }, |
| 2131 | + { "callfunc", (PyCFunction) cxoCursor_callFunc, |
| 2132 | + METH_VARARGS | METH_KEYWORDS }, |
| 2133 | + { "executemanyprepared", (PyCFunction) cxoCursor_executeManyPrepared, |
| 2134 | + METH_VARARGS }, |
| 2135 | + { "setoutputsize", (PyCFunction) cxoCursor_setOutputSize, METH_VARARGS }, |
| 2136 | + { "scroll", (PyCFunction) cxoCursor_scroll, METH_VARARGS | METH_KEYWORDS }, |
| 2137 | + { "var", (PyCFunction) cxoCursor_var, METH_VARARGS | METH_KEYWORDS }, |
| 2138 | + { "arrayvar", (PyCFunction) cxoCursor_arrayVar, METH_VARARGS }, |
| 2139 | + { "bindnames", (PyCFunction) cxoCursor_bindNames, METH_NOARGS }, |
| 2140 | + { "close", (PyCFunction) cxoCursor_close, METH_NOARGS }, |
| 2141 | + { "getbatcherrors", (PyCFunction) cxoCursor_getBatchErrors, METH_NOARGS }, |
| 2142 | + { "getarraydmlrowcounts", (PyCFunction) cxoCursor_getArrayDMLRowCounts, |
| 2143 | + METH_NOARGS }, |
| 2144 | + { "getimplicitresults", (PyCFunction) cxoCursor_getImplicitResults, |
| 2145 | + METH_NOARGS }, |
| 2146 | + { "__enter__", (PyCFunction) cxoCursor_contextManagerEnter, METH_NOARGS }, |
| 2147 | + { "__exit__", (PyCFunction) cxoCursor_contextManagerExit, METH_VARARGS }, |
| 2148 | + { NULL, NULL } |
| 2149 | +}; |
| 2150 | + |
| 2151 | + |
| 2152 | +//----------------------------------------------------------------------------- |
| 2153 | +// declaration of members for Python type |
| 2154 | +//----------------------------------------------------------------------------- |
| 2155 | +static PyMemberDef cxoMembers[] = { |
| 2156 | + { "arraysize", T_UINT, offsetof(cxoCursor, arraySize), 0 }, |
| 2157 | + { "bindarraysize", T_UINT, offsetof(cxoCursor, bindArraySize), 0 }, |
| 2158 | + { "rowcount", T_ULONGLONG, offsetof(cxoCursor, rowCount), READONLY }, |
| 2159 | + { "statement", T_OBJECT, offsetof(cxoCursor, statement), READONLY }, |
| 2160 | + { "connection", T_OBJECT_EX, offsetof(cxoCursor, connection), READONLY }, |
| 2161 | + { "rowfactory", T_OBJECT, offsetof(cxoCursor, rowFactory), 0 }, |
| 2162 | + { "bindvars", T_OBJECT, offsetof(cxoCursor, bindVariables), READONLY }, |
| 2163 | + { "fetchvars", T_OBJECT, offsetof(cxoCursor, fetchVariables), READONLY }, |
| 2164 | + { "inputtypehandler", T_OBJECT, offsetof(cxoCursor, inputTypeHandler), |
| 2165 | + 0 }, |
| 2166 | + { "outputtypehandler", T_OBJECT, offsetof(cxoCursor, outputTypeHandler), |
| 2167 | + 0 }, |
| 2168 | + { "scrollable", T_BOOL, offsetof(cxoCursor, isScrollable), 0 }, |
| 2169 | + { NULL } |
| 2170 | +}; |
| 2171 | + |
| 2172 | + |
| 2173 | +//----------------------------------------------------------------------------- |
| 2174 | +// declaration of calculated members for Python type |
| 2175 | +//----------------------------------------------------------------------------- |
| 2176 | +static PyGetSetDef cxoCalcMembers[] = { |
| 2177 | + { "description", (getter) cxoCursor_getDescription, 0, 0, 0 }, |
| 2178 | + { "lastrowid", (getter) cxoCursor_getLastRowid, 0, 0, 0 }, |
| 2179 | + { "prefetchrows", (getter) cxoCursor_getPrefetchRows, |
| 2180 | + (setter) cxoCursor_setPrefetchRows, 0, 0 }, |
| 2181 | + { NULL } |
| 2182 | +}; |
| 2183 | + |
| 2184 | + |
| 2185 | +//----------------------------------------------------------------------------- |
| 2186 | +// declaration of Python type |
| 2187 | +//----------------------------------------------------------------------------- |
| 2188 | +PyTypeObject cxoPyTypeCursor = { |
| 2189 | + PyVarObject_HEAD_INIT(NULL, 0) |
| 2190 | + .tp_name = "cx_Oracle.Cursor", |
| 2191 | + .tp_basicsize = sizeof(cxoCursor), |
| 2192 | + .tp_dealloc = (destructor) cxoCursor_free, |
| 2193 | + .tp_repr = (reprfunc) cxoCursor_repr, |
| 2194 | + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, |
| 2195 | + .tp_iter = (getiterfunc) cxoCursor_getIter, |
| 2196 | + .tp_iternext = (iternextfunc) cxoCursor_getNext, |
| 2197 | + .tp_methods = cxoMethods, |
| 2198 | + .tp_members = cxoMembers, |
| 2199 | + .tp_getset = cxoCalcMembers, |
| 2200 | + .tp_init = (initproc) cxoCursor_init, |
| 2201 | + .tp_new = cxoCursor_new |
| 2202 | +}; |
0 commit comments