Connection.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736
  1. //-----------------------------------------------------------------------------
  2. // Connection.c
  3. // Definition of the Python type OracleConnection.
  4. //-----------------------------------------------------------------------------
  5. //-----------------------------------------------------------------------------
  6. // structure for the Python type "Connection"
  7. //-----------------------------------------------------------------------------
  8. typedef struct {
  9. PyObject_HEAD
  10. OCISvcCtx *handle;
  11. OCIServer *serverHandle;
  12. OCISession *sessionHandle;
  13. udt_Environment *environment;
  14. udt_SessionPool *sessionPool;
  15. PyObject *inputTypeHandler;
  16. PyObject *outputTypeHandler;
  17. PyObject *username;
  18. PyObject *dsn;
  19. PyObject *version;
  20. ub4 commitMode;
  21. int autocommit;
  22. int release;
  23. int attached;
  24. } udt_Connection;
  25. //-----------------------------------------------------------------------------
  26. // constants for the OCI attributes
  27. //-----------------------------------------------------------------------------
  28. static ub4 gc_ClientIdentifierAttribute = OCI_ATTR_CLIENT_IDENTIFIER;
  29. static ub4 gc_ModuleAttribute = OCI_ATTR_MODULE;
  30. static ub4 gc_ActionAttribute = OCI_ATTR_ACTION;
  31. static ub4 gc_ClientInfoAttribute = OCI_ATTR_CLIENT_INFO;
  32. #if ORACLE_VERSION_HEX >= ORACLE_VERSION(10, 2)
  33. static ub4 gc_CurrentSchemaAttribute = OCI_ATTR_CURRENT_SCHEMA;
  34. #endif
  35. //-----------------------------------------------------------------------------
  36. // functions for the Python type "Connection"
  37. //-----------------------------------------------------------------------------
  38. static void Connection_Free(udt_Connection*);
  39. static PyObject *Connection_New(PyTypeObject*, PyObject*, PyObject*);
  40. static int Connection_Init(udt_Connection*, PyObject*, PyObject*);
  41. static PyObject *Connection_Repr(udt_Connection*);
  42. static PyObject *Connection_Close(udt_Connection*, PyObject*);
  43. static PyObject *Connection_Commit(udt_Connection*, PyObject*);
  44. static PyObject *Connection_Begin(udt_Connection*, PyObject*);
  45. static PyObject *Connection_Prepare(udt_Connection*, PyObject*);
  46. static PyObject *Connection_Rollback(udt_Connection*, PyObject*);
  47. static PyObject *Connection_NewCursor(udt_Connection*, PyObject*);
  48. static PyObject *Connection_Cancel(udt_Connection*, PyObject*);
  49. static PyObject *Connection_RegisterCallback(udt_Connection*, PyObject*);
  50. static PyObject *Connection_UnregisterCallback(udt_Connection*, PyObject*);
  51. static PyObject *Connection_GetVersion(udt_Connection*, void*);
  52. static PyObject *Connection_GetEncoding(udt_Connection*, void*);
  53. static PyObject *Connection_GetNationalEncoding(udt_Connection*, void*);
  54. static PyObject *Connection_GetMaxBytesPerCharacter(udt_Connection*, void*);
  55. static PyObject *Connection_ContextManagerEnter(udt_Connection*, PyObject*);
  56. static PyObject *Connection_ContextManagerExit(udt_Connection*, PyObject*);
  57. static PyObject *Connection_ChangePasswordExternal(udt_Connection*, PyObject*);
  58. static PyObject *Connection_GetStmtCacheSize(udt_Connection*, void*);
  59. static int Connection_SetStmtCacheSize(udt_Connection*, PyObject*, void*);
  60. #if ORACLE_VERSION_HEX >= ORACLE_VERSION(10, 2)
  61. static PyObject *Connection_GetOCIAttr(udt_Connection*, ub4*);
  62. #endif
  63. static int Connection_SetOCIAttr(udt_Connection*, PyObject*, ub4*);
  64. #if ORACLE_VERSION_HEX >= ORACLE_VERSION(10, 2)
  65. #if !defined(AIX5) || ORACLE_VERSION_HEX >= ORACLE_VERSION(11, 1)
  66. static PyObject *Connection_Ping(udt_Connection*, PyObject*);
  67. #endif
  68. static PyObject *Connection_Shutdown(udt_Connection*, PyObject*, PyObject*);
  69. static PyObject *Connection_Startup(udt_Connection*, PyObject*, PyObject*);
  70. static PyObject *Connection_Subscribe(udt_Connection*, PyObject*, PyObject*);
  71. #endif
  72. //-----------------------------------------------------------------------------
  73. // declaration of methods for Python type "Connection"
  74. //-----------------------------------------------------------------------------
  75. static PyMethodDef g_ConnectionMethods[] = {
  76. { "cursor", (PyCFunction) Connection_NewCursor, METH_NOARGS },
  77. { "commit", (PyCFunction) Connection_Commit, METH_NOARGS },
  78. { "rollback", (PyCFunction) Connection_Rollback, METH_NOARGS },
  79. { "begin", (PyCFunction) Connection_Begin, METH_VARARGS },
  80. { "prepare", (PyCFunction) Connection_Prepare, METH_NOARGS },
  81. { "close", (PyCFunction) Connection_Close, METH_NOARGS },
  82. { "cancel", (PyCFunction) Connection_Cancel, METH_NOARGS },
  83. { "register", (PyCFunction) Connection_RegisterCallback, METH_VARARGS },
  84. { "unregister", (PyCFunction) Connection_UnregisterCallback, METH_VARARGS },
  85. { "__enter__", (PyCFunction) Connection_ContextManagerEnter, METH_NOARGS },
  86. { "__exit__", (PyCFunction) Connection_ContextManagerExit, METH_VARARGS },
  87. #if ORACLE_VERSION_HEX >= ORACLE_VERSION(10, 2)
  88. #if !defined(AIX5) || ORACLE_VERSION_HEX >= ORACLE_VERSION(11, 1)
  89. { "ping", (PyCFunction) Connection_Ping, METH_NOARGS },
  90. #endif
  91. { "shutdown", (PyCFunction) Connection_Shutdown,
  92. METH_VARARGS | METH_KEYWORDS},
  93. { "startup", (PyCFunction) Connection_Startup,
  94. METH_VARARGS | METH_KEYWORDS},
  95. { "subscribe", (PyCFunction) Connection_Subscribe,
  96. METH_VARARGS | METH_KEYWORDS},
  97. #endif
  98. { "changepassword", (PyCFunction) Connection_ChangePasswordExternal,
  99. METH_VARARGS },
  100. { NULL }
  101. };
  102. //-----------------------------------------------------------------------------
  103. // declaration of members for Python type "Connection"
  104. //-----------------------------------------------------------------------------
  105. static PyMemberDef g_ConnectionMembers[] = {
  106. { "username", T_OBJECT, offsetof(udt_Connection, username), READONLY },
  107. { "dsn", T_OBJECT, offsetof(udt_Connection, dsn), READONLY },
  108. { "tnsentry", T_OBJECT, offsetof(udt_Connection, dsn), READONLY },
  109. { "autocommit", T_INT, offsetof(udt_Connection, autocommit), 0 },
  110. { "inputtypehandler", T_OBJECT,
  111. offsetof(udt_Connection, inputTypeHandler), 0 },
  112. { "outputtypehandler", T_OBJECT,
  113. offsetof(udt_Connection, outputTypeHandler), 0 },
  114. { NULL }
  115. };
  116. //-----------------------------------------------------------------------------
  117. // declaration of calculated members for Python type "Connection"
  118. //-----------------------------------------------------------------------------
  119. static PyGetSetDef g_ConnectionCalcMembers[] = {
  120. { "version", (getter) Connection_GetVersion, 0, 0, 0 },
  121. { "encoding", (getter) Connection_GetEncoding, 0, 0, 0 },
  122. { "nencoding", (getter) Connection_GetNationalEncoding, 0, 0, 0 },
  123. { "maxBytesPerCharacter", (getter) Connection_GetMaxBytesPerCharacter,
  124. 0, 0, 0 },
  125. { "stmtcachesize", (getter) Connection_GetStmtCacheSize,
  126. (setter) Connection_SetStmtCacheSize, 0, 0 },
  127. { "module", 0, (setter) Connection_SetOCIAttr, 0, &gc_ModuleAttribute },
  128. { "action", 0, (setter) Connection_SetOCIAttr, 0, &gc_ActionAttribute },
  129. { "clientinfo", 0, (setter) Connection_SetOCIAttr, 0,
  130. &gc_ClientInfoAttribute },
  131. { "client_identifier", 0, (setter) Connection_SetOCIAttr, 0,
  132. &gc_ClientIdentifierAttribute },
  133. #if ORACLE_VERSION_HEX >= ORACLE_VERSION(10, 2)
  134. { "current_schema", (getter) Connection_GetOCIAttr,
  135. (setter) Connection_SetOCIAttr, 0, &gc_CurrentSchemaAttribute },
  136. #endif
  137. { NULL }
  138. };
  139. //-----------------------------------------------------------------------------
  140. // declaration of Python type "Connection"
  141. //-----------------------------------------------------------------------------
  142. static PyTypeObject g_ConnectionType = {
  143. PyVarObject_HEAD_INIT(NULL, 0)
  144. "cx_Oracle.Connection", // tp_name
  145. sizeof(udt_Connection), // tp_basicsize
  146. 0, // tp_itemsize
  147. (destructor) Connection_Free, // tp_dealloc
  148. 0, // tp_print
  149. 0, // tp_getattr
  150. 0, // tp_setattr
  151. 0, // tp_compare
  152. (reprfunc) Connection_Repr, // tp_repr
  153. 0, // tp_as_number
  154. 0, // tp_as_sequence
  155. 0, // tp_as_mapping
  156. 0, // tp_hash
  157. 0, // tp_call
  158. 0, // tp_str
  159. 0, // tp_getattro
  160. 0, // tp_setattro
  161. 0, // tp_as_buffer
  162. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
  163. // tp_flags
  164. 0, // tp_doc
  165. 0, // tp_traverse
  166. 0, // tp_clear
  167. 0, // tp_richcompare
  168. 0, // tp_weaklistoffset
  169. 0, // tp_iter
  170. 0, // tp_iternext
  171. g_ConnectionMethods, // tp_methods
  172. g_ConnectionMembers, // tp_members
  173. g_ConnectionCalcMembers, // tp_getset
  174. 0, // tp_base
  175. 0, // tp_dict
  176. 0, // tp_descr_get
  177. 0, // tp_descr_set
  178. 0, // tp_dictoffset
  179. (initproc) Connection_Init, // tp_init
  180. 0, // tp_alloc
  181. (newfunc) Connection_New, // tp_new
  182. 0, // tp_free
  183. 0, // tp_is_gc
  184. 0 // tp_bases
  185. };
  186. //-----------------------------------------------------------------------------
  187. // Connection_IsConnected()
  188. // Determines if the connection object is connected to the database. If not,
  189. // a Python exception is raised.
  190. //-----------------------------------------------------------------------------
  191. static int Connection_IsConnected(
  192. udt_Connection *self) // connection to check
  193. {
  194. if (!self->handle) {
  195. PyErr_SetString(g_InterfaceErrorException, "not connected");
  196. return -1;
  197. }
  198. return 0;
  199. }
  200. //-----------------------------------------------------------------------------
  201. // Connection_GetConnection()
  202. // Get a connection using the OCISessionGet() interface rather than using
  203. // the low level interface for connecting.
  204. //-----------------------------------------------------------------------------
  205. static int Connection_GetConnection(
  206. udt_Connection *self, // connection
  207. udt_SessionPool *pool, // pool to acquire connection from
  208. PyObject *passwordObj, // password
  209. PyObject *cclassObj, // connection class (DRCP)
  210. ub4 purity) // purity (DRCP)
  211. {
  212. udt_Environment *environment;
  213. int externalAuth, proxyAuth;
  214. udt_Buffer buffer;
  215. OCIAuthInfo *authInfo;
  216. PyObject *dbNameObj;
  217. boolean found;
  218. sword status;
  219. ub4 mode;
  220. // set things up for the call to acquire a session
  221. authInfo = NULL;
  222. externalAuth = proxyAuth = 0;
  223. if (pool) {
  224. environment = pool->environment;
  225. dbNameObj = pool->name;
  226. mode = OCI_SESSGET_SPOOL;
  227. externalAuth = pool->externalAuth;
  228. if (!pool->homogeneous && pool->username && self->username) {
  229. proxyAuth = PyObject_RichCompareBool(self->username,
  230. pool->username, Py_NE);
  231. if (proxyAuth < 0)
  232. return -1;
  233. mode = mode | OCI_SESSGET_CREDPROXY;
  234. }
  235. } else {
  236. environment = self->environment;
  237. dbNameObj = self->dsn;
  238. mode = OCI_SESSGET_STMTCACHE;
  239. }
  240. // set up authorization handle, if needed
  241. if (!pool || cclassObj || proxyAuth) {
  242. // create authorization handle
  243. status = OCIHandleAlloc(environment->handle, (dvoid*) &authInfo,
  244. OCI_HTYPE_AUTHINFO, 0, NULL);
  245. if (Environment_CheckForError(environment, status,
  246. "Connection_GetConnection(): allocate handle") < 0)
  247. return -1;
  248. // set the user name, if applicable
  249. externalAuth = 1;
  250. if (cxBuffer_FromObject(&buffer, self->username,
  251. self->environment->encoding) < 0)
  252. return -1;
  253. if (buffer.size > 0) {
  254. externalAuth = 0;
  255. status = OCIAttrSet(authInfo, OCI_HTYPE_AUTHINFO,
  256. (text*) buffer.ptr, buffer.size, OCI_ATTR_USERNAME,
  257. environment->errorHandle);
  258. if (Environment_CheckForError(environment, status,
  259. "Connection_GetConnection(): set user name") < 0) {
  260. cxBuffer_Clear(&buffer);
  261. return -1;
  262. }
  263. }
  264. cxBuffer_Clear(&buffer);
  265. // set the password, if applicable
  266. if (cxBuffer_FromObject(&buffer, passwordObj,
  267. self->environment->encoding) < 0)
  268. return -1;
  269. if (buffer.size > 0) {
  270. externalAuth = 0;
  271. status = OCIAttrSet(authInfo, OCI_HTYPE_AUTHINFO,
  272. (text*) buffer.ptr, buffer.size, OCI_ATTR_PASSWORD,
  273. environment->errorHandle);
  274. if (Environment_CheckForError(environment, status,
  275. "Connection_GetConnection(): set password") < 0) {
  276. cxBuffer_Clear(&buffer);
  277. return -1;
  278. }
  279. }
  280. cxBuffer_Clear(&buffer);
  281. #if ORACLE_VERSION_HEX >= ORACLE_VERSION(11, 1)
  282. // set the connection class, if applicable
  283. if (cxBuffer_FromObject(&buffer, cclassObj,
  284. self->environment->encoding) < 0)
  285. return -1;
  286. if (buffer.size > 0) {
  287. status = OCIAttrSet(authInfo, OCI_HTYPE_AUTHINFO,
  288. (text*) buffer.ptr, buffer.size, OCI_ATTR_CONNECTION_CLASS,
  289. environment->errorHandle);
  290. if (Environment_CheckForError(environment, status,
  291. "Connection_GetConnection(): set connection class") < 0) {
  292. cxBuffer_Clear(&buffer);
  293. return -1;
  294. }
  295. }
  296. cxBuffer_Clear(&buffer);
  297. // set the purity, if applicable
  298. if (purity != OCI_ATTR_PURITY_DEFAULT) {
  299. status = OCIAttrSet(authInfo, OCI_HTYPE_AUTHINFO, &purity,
  300. sizeof(purity), OCI_ATTR_PURITY,
  301. environment->errorHandle);
  302. if (Environment_CheckForError(environment, status,
  303. "Connection_GetConnection(): set purity") < 0)
  304. return -1;
  305. }
  306. #endif
  307. }
  308. // external auth requested (no username/password or specified via pool)
  309. if (externalAuth)
  310. mode |= OCI_SESSGET_CREDEXT;
  311. // acquire the new session
  312. if (cxBuffer_FromObject(&buffer, dbNameObj,
  313. self->environment->encoding) < 0)
  314. return -1;
  315. Py_BEGIN_ALLOW_THREADS
  316. status = OCISessionGet(environment->handle, environment->errorHandle,
  317. &self->handle, authInfo, (text*) buffer.ptr, buffer.size, NULL, 0,
  318. NULL, NULL, &found, mode);
  319. Py_END_ALLOW_THREADS
  320. cxBuffer_Clear(&buffer);
  321. if (Environment_CheckForError(environment, status,
  322. "Connection_GetConnection(): get connection") < 0)
  323. return -1;
  324. // eliminate the authorization handle immediately, if applicable
  325. if (authInfo)
  326. OCIHandleFree(authInfo, OCI_HTYPE_AUTHINFO);
  327. // copy members in the case where a pool is being used
  328. if (pool) {
  329. if (!proxyAuth) {
  330. Py_INCREF(pool->username);
  331. self->username = pool->username;
  332. }
  333. Py_INCREF(pool->dsn);
  334. self->dsn = pool->dsn;
  335. Py_INCREF(pool);
  336. self->sessionPool = pool;
  337. }
  338. self->release = 1;
  339. return 0;
  340. }
  341. #if ORACLE_VERSION_HEX >= ORACLE_VERSION(10, 2)
  342. //-----------------------------------------------------------------------------
  343. // Connection_GetOCIAttr()
  344. // Get the value of the OCI attribute.
  345. //-----------------------------------------------------------------------------
  346. static PyObject *Connection_GetOCIAttr(
  347. udt_Connection *self, // connection to set
  348. ub4 *attribute) // OCI attribute type
  349. {
  350. OCISession *sessionHandle;
  351. udt_Buffer buffer;
  352. ub4 bufferSize;
  353. sword status;
  354. // make sure connection is connected
  355. if (Connection_IsConnected(self) < 0)
  356. return NULL;
  357. // acquire the session handle
  358. status = OCIAttrGet(self->handle, OCI_HTYPE_SVCCTX,
  359. (dvoid**) &sessionHandle, 0, OCI_ATTR_SESSION,
  360. self->environment->errorHandle);
  361. if (Environment_CheckForError(self->environment, status,
  362. "Connection_GetOCIAttr(): determine session handle") < 0)
  363. return NULL;
  364. // get the value from the OCI
  365. status = OCIAttrGet(sessionHandle, OCI_HTYPE_SESSION,
  366. (text**) &buffer.ptr, &bufferSize, *attribute,
  367. self->environment->errorHandle);
  368. if (Environment_CheckForError(self->environment, status,
  369. "Connection_GetOCIAttr()") < 0)
  370. return NULL;
  371. buffer.size = bufferSize;
  372. return cxString_FromEncodedString(buffer.ptr, buffer.size,
  373. self->environment->encoding);
  374. }
  375. #endif
  376. //-----------------------------------------------------------------------------
  377. // Connection_SetOCIAttr()
  378. // Set the value of the OCI attribute.
  379. //-----------------------------------------------------------------------------
  380. static int Connection_SetOCIAttr(
  381. udt_Connection *self, // connection to set
  382. PyObject *value, // value to set
  383. ub4 *attribute) // OCI attribute type
  384. {
  385. OCISession *sessionHandle;
  386. udt_Buffer buffer;
  387. sword status;
  388. // make sure connection is connected
  389. if (Connection_IsConnected(self) < 0)
  390. return -1;
  391. // acquire the session handle
  392. status = OCIAttrGet(self->handle, OCI_HTYPE_SVCCTX,
  393. (dvoid**) &sessionHandle, 0, OCI_ATTR_SESSION,
  394. self->environment->errorHandle);
  395. if (Environment_CheckForError(self->environment, status,
  396. "Connection_SetOCIAttr(): determine session handle") < 0)
  397. return -1;
  398. // set the value in the OCI
  399. if (cxBuffer_FromObject(&buffer, value, self->environment->encoding))
  400. return -1;
  401. status = OCIAttrSet(sessionHandle, OCI_HTYPE_SESSION, (text*) buffer.ptr,
  402. buffer.size, *attribute, self->environment->errorHandle);
  403. cxBuffer_Clear(&buffer);
  404. if (Environment_CheckForError(self->environment, status,
  405. "Connection_SetOCIAttr(): set value") < 0)
  406. return -1;
  407. return 0;
  408. }
  409. //-----------------------------------------------------------------------------
  410. // Connection_Attach()
  411. // Attach to an existing connection.
  412. //-----------------------------------------------------------------------------
  413. static int Connection_Attach(
  414. udt_Connection *self, // connection
  415. OCISvcCtx *handle) // handle of connection to attach to
  416. {
  417. OCISession *sessionHandle;
  418. OCIServer *serverHandle;
  419. sword status;
  420. // acquire the server handle
  421. status = OCIAttrGet(handle, OCI_HTYPE_SVCCTX, (dvoid**) &serverHandle, 0,
  422. OCI_ATTR_SERVER, self->environment->errorHandle);
  423. if (Environment_CheckForError(self->environment, status,
  424. "Connection_Attach(): determine server handle") < 0)
  425. return -1;
  426. // acquire the session handle
  427. status = OCIAttrGet(handle, OCI_HTYPE_SVCCTX, (dvoid**) &sessionHandle, 0,
  428. OCI_ATTR_SESSION, self->environment->errorHandle);
  429. if (Environment_CheckForError(self->environment, status,
  430. "Connection_Attach(): determine session handle") < 0)
  431. return -1;
  432. // allocate the service context handle
  433. status = OCIHandleAlloc(self->environment->handle,
  434. (dvoid*) &self->handle, OCI_HTYPE_SVCCTX, 0, 0);
  435. if (Environment_CheckForError(self->environment, status,
  436. "Connection_Attach(): allocate service context handle") < 0)
  437. return -1;
  438. // set attribute for server handle
  439. status = OCIAttrSet(self->handle, OCI_HTYPE_SVCCTX, serverHandle, 0,
  440. OCI_ATTR_SERVER, self->environment->errorHandle);
  441. if (Environment_CheckForError(self->environment, status,
  442. "Connection_Attach(): set server handle") < 0)
  443. return -1;
  444. // set attribute for session handle
  445. status = OCIAttrSet(self->handle, OCI_HTYPE_SVCCTX, sessionHandle, 0,
  446. OCI_ATTR_SESSION, self->environment->errorHandle);
  447. if (Environment_CheckForError(self->environment, status,
  448. "Connection_Attach(): set session handle") < 0)
  449. return -1;
  450. self->attached = 1;
  451. return 0;
  452. }
  453. //-----------------------------------------------------------------------------
  454. // Connection_ChangePassword()
  455. // Change the password for the given connection.
  456. //-----------------------------------------------------------------------------
  457. static int Connection_ChangePassword(
  458. udt_Connection *self, // connection
  459. PyObject *oldPasswordObj, // old password
  460. PyObject *newPasswordObj) // new password
  461. {
  462. udt_Buffer usernameBuffer, oldPasswordBuffer, newPasswordBuffer;
  463. sword status;
  464. if (cxBuffer_FromObject(&usernameBuffer, self->username,
  465. self->environment->encoding) < 0)
  466. return -1;
  467. if (cxBuffer_FromObject(&oldPasswordBuffer, oldPasswordObj,
  468. self->environment->encoding) < 0) {
  469. cxBuffer_Clear(&usernameBuffer);
  470. return -1;
  471. }
  472. if (cxBuffer_FromObject(&newPasswordBuffer, newPasswordObj,
  473. self->environment->encoding) < 0) {
  474. cxBuffer_Clear(&usernameBuffer);
  475. cxBuffer_Clear(&oldPasswordBuffer);
  476. return -1;
  477. }
  478. // begin the session
  479. Py_BEGIN_ALLOW_THREADS
  480. status = OCIPasswordChange(self->handle, self->environment->errorHandle,
  481. (text*) usernameBuffer.ptr, usernameBuffer.size,
  482. (text*) oldPasswordBuffer.ptr, oldPasswordBuffer.size,
  483. (text*) newPasswordBuffer.ptr, newPasswordBuffer.size,
  484. OCI_AUTH);
  485. Py_END_ALLOW_THREADS
  486. cxBuffer_Clear(&usernameBuffer);
  487. cxBuffer_Clear(&oldPasswordBuffer);
  488. cxBuffer_Clear(&newPasswordBuffer);
  489. if (Environment_CheckForError(self->environment, status,
  490. "Connection_ChangePassword(): change password") < 0)
  491. return -1;
  492. return 0;
  493. }
  494. //-----------------------------------------------------------------------------
  495. // Connection_ChangePasswordExternal()
  496. // Change the password for the given connection.
  497. //-----------------------------------------------------------------------------
  498. static PyObject *Connection_ChangePasswordExternal(
  499. udt_Connection *self, // connection
  500. PyObject *args) // arguments
  501. {
  502. PyObject *oldPasswordObj, *newPasswordObj;
  503. // parse the arguments
  504. if (!PyArg_ParseTuple(args, "O!O!", cxString_Type, &oldPasswordObj,
  505. cxString_Type, &newPasswordObj))
  506. return NULL;
  507. if (Connection_ChangePassword(self, oldPasswordObj, newPasswordObj) < 0)
  508. return NULL;
  509. Py_INCREF(Py_None);
  510. return Py_None;
  511. }
  512. //-----------------------------------------------------------------------------
  513. // Connection_Connect()
  514. // Create a new connection object by connecting to the database.
  515. //-----------------------------------------------------------------------------
  516. static int Connection_Connect(
  517. udt_Connection *self, // connection
  518. ub4 mode, // mode to connect as
  519. int twophase, // allow two phase commit?
  520. PyObject *passwordObj, // password
  521. PyObject *newPasswordObj, // new password (if desired)
  522. PyObject *moduleObj, // session "module" value
  523. PyObject *actionObj, // session "action" value
  524. PyObject *clientinfoObj) // session "clientinfo" value
  525. {
  526. ub4 credentialType = OCI_CRED_EXT;
  527. udt_Buffer buffer;
  528. sword status;
  529. // allocate the server handle
  530. status = OCIHandleAlloc(self->environment->handle,
  531. (dvoid**) &self->serverHandle, OCI_HTYPE_SERVER, 0, 0);
  532. if (Environment_CheckForError(self->environment, status,
  533. "Connection_Connect(): allocate server handle") < 0)
  534. return -1;
  535. // attach to the server
  536. if (cxBuffer_FromObject(&buffer, self->dsn,
  537. self->environment->encoding) < 0)
  538. return -1;
  539. Py_BEGIN_ALLOW_THREADS
  540. status = OCIServerAttach(self->serverHandle,
  541. self->environment->errorHandle, (text*) buffer.ptr, buffer.size,
  542. OCI_DEFAULT);
  543. Py_END_ALLOW_THREADS
  544. cxBuffer_Clear(&buffer);
  545. if (Environment_CheckForError(self->environment, status,
  546. "Connection_Connect(): server attach") < 0)
  547. return -1;
  548. // allocate the service context handle
  549. status = OCIHandleAlloc(self->environment->handle,
  550. (dvoid**) &self->handle, OCI_HTYPE_SVCCTX, 0, 0);
  551. if (Environment_CheckForError(self->environment, status,
  552. "Connection_Connect(): allocate service context handle") < 0)
  553. return -1;
  554. // set attribute for server handle
  555. status = OCIAttrSet(self->handle, OCI_HTYPE_SVCCTX, self->serverHandle, 0,
  556. OCI_ATTR_SERVER, self->environment->errorHandle);
  557. if (Environment_CheckForError(self->environment, status,
  558. "Connection_Connect(): set server handle") < 0)
  559. return -1;
  560. // set the internal and external names; these are needed for global
  561. // transactions but are limited in terms of the lengths of the strings
  562. if (twophase) {
  563. status = OCIAttrSet(self->serverHandle, OCI_HTYPE_SERVER,
  564. (dvoid*) "cx_Oracle", 0, OCI_ATTR_INTERNAL_NAME,
  565. self->environment->errorHandle);
  566. if (Environment_CheckForError(self->environment, status,
  567. "Connection_Connect(): set internal name") < 0)
  568. return -1;
  569. status = OCIAttrSet(self->serverHandle, OCI_HTYPE_SERVER,
  570. (dvoid*) "cx_Oracle", 0, OCI_ATTR_EXTERNAL_NAME,
  571. self->environment->errorHandle);
  572. if (Environment_CheckForError(self->environment, status,
  573. "Connection_Connect(): set external name") < 0)
  574. return -1;
  575. }
  576. // allocate the session handle
  577. status = OCIHandleAlloc(self->environment->handle,
  578. (dvoid**) &self->sessionHandle, OCI_HTYPE_SESSION, 0, 0);
  579. if (Environment_CheckForError(self->environment, status,
  580. "Connection_Connect(): allocate session handle") < 0)
  581. return -1;
  582. // set user name in session handle
  583. if (cxBuffer_FromObject(&buffer, self->username,
  584. self->environment->encoding) < 0)
  585. return -1;
  586. if (buffer.size > 0) {
  587. credentialType = OCI_CRED_RDBMS;
  588. status = OCIAttrSet(self->sessionHandle, OCI_HTYPE_SESSION,
  589. (text*) buffer.ptr, buffer.size, OCI_ATTR_USERNAME,
  590. self->environment->errorHandle);
  591. if (Environment_CheckForError(self->environment, status,
  592. "Connection_Connect(): set user name") < 0) {
  593. cxBuffer_Clear(&buffer);
  594. return -1;
  595. }
  596. }
  597. cxBuffer_Clear(&buffer);
  598. // set password in session handle
  599. if (cxBuffer_FromObject(&buffer, passwordObj,
  600. self->environment->encoding) < 0)
  601. return -1;
  602. if (buffer.size > 0) {
  603. credentialType = OCI_CRED_RDBMS;
  604. status = OCIAttrSet(self->sessionHandle, OCI_HTYPE_SESSION,
  605. (text*) buffer.ptr, buffer.size, OCI_ATTR_PASSWORD,
  606. self->environment->errorHandle);
  607. if (Environment_CheckForError(self->environment, status,
  608. "Connection_Connect(): set password") < 0) {
  609. cxBuffer_Clear(&buffer);
  610. return -1;
  611. }
  612. }
  613. cxBuffer_Clear(&buffer);
  614. #if ORACLE_VERSION_HEX >= ORACLE_VERSION(11,1)
  615. status = OCIAttrSet(self->sessionHandle, OCI_HTYPE_SESSION,
  616. (text*) DRIVER_NAME, strlen(DRIVER_NAME), OCI_ATTR_DRIVER_NAME,
  617. self->environment->errorHandle);
  618. if (Environment_CheckForError(self->environment, status,
  619. "Connection_Connect(): set driver name") < 0)
  620. return -1;
  621. #endif
  622. // set the session handle on the service context handle
  623. status = OCIAttrSet(self->handle, OCI_HTYPE_SVCCTX,
  624. self->sessionHandle, 0, OCI_ATTR_SESSION,
  625. self->environment->errorHandle);
  626. if (Environment_CheckForError(self->environment, status,
  627. "Connection_Connect(): set session handle") < 0)
  628. return -1;
  629. if (moduleObj) {
  630. if (cxBuffer_FromObject(&buffer, moduleObj,
  631. self->environment->encoding))
  632. return -1;
  633. status = OCIAttrSet(self->sessionHandle, OCI_HTYPE_SESSION,
  634. (text*) buffer.ptr, buffer.size, OCI_ATTR_MODULE,
  635. self->environment->errorHandle);
  636. cxBuffer_Clear(&buffer);
  637. if (Environment_CheckForError(self->environment, status,
  638. "Connection_Connect(): set module") < 0)
  639. return -1;
  640. }
  641. if (actionObj) {
  642. if (cxBuffer_FromObject(&buffer, actionObj,
  643. self->environment->encoding))
  644. return -1;
  645. status = OCIAttrSet(self->sessionHandle, OCI_HTYPE_SESSION,
  646. (text*) buffer.ptr, buffer.size, OCI_ATTR_ACTION,
  647. self->environment->errorHandle);
  648. cxBuffer_Clear(&buffer);
  649. if (Environment_CheckForError(self->environment, status,
  650. "Connection_Connect(): set action") < 0)
  651. return -1;
  652. }
  653. if (clientinfoObj) {
  654. if (cxBuffer_FromObject(&buffer, clientinfoObj,
  655. self->environment->encoding))
  656. return -1;
  657. status = OCIAttrSet(self->sessionHandle, OCI_HTYPE_SESSION,
  658. (text*) buffer.ptr, buffer.size, OCI_ATTR_CLIENT_INFO,
  659. self->environment->errorHandle);
  660. cxBuffer_Clear(&buffer);
  661. if (Environment_CheckForError(self->environment, status,
  662. "Connection_Connect(): set clientinfo") < 0)
  663. return -1;
  664. }
  665. // if a new password has been specified, change it which will also
  666. // establish the session
  667. if (newPasswordObj)
  668. return Connection_ChangePassword(self, passwordObj, newPasswordObj);
  669. // begin the session
  670. Py_BEGIN_ALLOW_THREADS
  671. status = OCISessionBegin(self->handle, self->environment->errorHandle,
  672. self->sessionHandle, credentialType, mode);
  673. Py_END_ALLOW_THREADS
  674. if (Environment_CheckForError(self->environment, status,
  675. "Connection_Connect(): begin session") < 0) {
  676. self->sessionHandle = NULL;
  677. return -1;
  678. }
  679. return 0;
  680. }
  681. #include "Cursor.c"
  682. #include "Callback.c"
  683. #if ORACLE_VERSION_HEX >= ORACLE_VERSION(10, 2)
  684. #include "Subscription.c"
  685. #endif
  686. //-----------------------------------------------------------------------------
  687. // Connection_New()
  688. // Create a new connection object and return it.
  689. //-----------------------------------------------------------------------------
  690. static PyObject* Connection_New(
  691. PyTypeObject *type, // type object
  692. PyObject *args, // arguments
  693. PyObject *keywordArgs) // keyword arguments
  694. {
  695. udt_Connection *self;
  696. // create the object
  697. self = (udt_Connection*) type->tp_alloc(type, 0);
  698. if (!self)
  699. return NULL;
  700. self->commitMode = OCI_DEFAULT;
  701. self->environment = NULL;
  702. return (PyObject*) self;
  703. }
  704. //-----------------------------------------------------------------------------
  705. // Connection_SplitComponent()
  706. // Split the component out of the source and replace the source with the
  707. // characters up to the split string and put the characters after the split
  708. // string in to the target.
  709. //-----------------------------------------------------------------------------
  710. static int Connection_SplitComponent(
  711. PyObject **sourceObj, // source object to split
  712. PyObject **targetObj, // target object (for component)
  713. const char *splitString) // split string (assume one character)
  714. {
  715. PyObject *temp, *posObj;
  716. Py_ssize_t size, pos;
  717. if (!*sourceObj || *targetObj)
  718. return 0;
  719. posObj = PyObject_CallMethod(*sourceObj, "find", "s", splitString);
  720. if (!posObj)
  721. return -1;
  722. pos = PyInt_AsLong(posObj);
  723. Py_DECREF(posObj);
  724. if (PyErr_Occurred())
  725. return -1;
  726. if (pos >= 0) {
  727. size = PySequence_Size(*sourceObj);
  728. if (PyErr_Occurred())
  729. return -1;
  730. *targetObj = PySequence_GetSlice(*sourceObj, pos + 1, size);
  731. if (!*targetObj)
  732. return -1;
  733. temp = PySequence_GetSlice(*sourceObj, 0, pos);
  734. if (!temp)
  735. return -1;
  736. *sourceObj = temp;
  737. }
  738. return 0;
  739. }
  740. //-----------------------------------------------------------------------------
  741. // Connection_Init()
  742. // Initialize the connection members.
  743. //-----------------------------------------------------------------------------
  744. static int Connection_Init(
  745. udt_Connection *self, // connection
  746. PyObject *args, // arguments
  747. PyObject *keywordArgs) // keyword arguments
  748. {
  749. PyObject *threadedObj, *twophaseObj, *eventsObj, *newPasswordObj;
  750. PyObject *usernameObj, *passwordObj, *dsnObj, *cclassObj;
  751. PyObject *moduleObj, *actionObj, *clientinfoObj;
  752. int threaded, twophase, events;
  753. char *encoding, *nencoding;
  754. ub4 connectMode, purity;
  755. udt_SessionPool *pool;
  756. OCISvcCtx *handle;
  757. // define keyword arguments
  758. static char *keywordList[] = { "user", "password", "dsn", "mode",
  759. "handle", "pool", "threaded", "twophase", "events", "cclass",
  760. "purity", "newpassword", "encoding", "nencoding", "module",
  761. "action", "clientinfo", NULL };
  762. // parse arguments
  763. pool = NULL;
  764. handle = NULL;
  765. connectMode = OCI_DEFAULT;
  766. usernameObj = passwordObj = dsnObj = cclassObj = NULL;
  767. threadedObj = twophaseObj = eventsObj = newPasswordObj = NULL;
  768. moduleObj = actionObj = clientinfoObj = NULL;
  769. threaded = twophase = events = purity = 0;
  770. encoding = nencoding = NULL;
  771. #if ORACLE_VERSION_HEX >= ORACLE_VERSION(11, 1)
  772. purity = OCI_ATTR_PURITY_DEFAULT;
  773. #endif
  774. if (!PyArg_ParseTupleAndKeywords(args, keywordArgs,
  775. "|OOOiiO!OOOOiOssOOO", keywordList, &usernameObj, &passwordObj,
  776. &dsnObj, &connectMode, &handle, &g_SessionPoolType, &pool,
  777. &threadedObj, &twophaseObj, &eventsObj, &cclassObj, &purity,
  778. &newPasswordObj, &encoding, &nencoding, &moduleObj, &actionObj,
  779. &clientinfoObj))
  780. return -1;
  781. if (threadedObj) {
  782. threaded = PyObject_IsTrue(threadedObj);
  783. if (threaded < 0)
  784. return -1;
  785. }
  786. if (twophaseObj) {
  787. twophase = PyObject_IsTrue(twophaseObj);
  788. if (twophase < 0)
  789. return -1;
  790. }
  791. if (eventsObj) {
  792. events = PyObject_IsTrue(eventsObj);
  793. if (events < 0)
  794. return -1;
  795. }
  796. // set up the environment
  797. if (pool)
  798. self->environment = Environment_Clone(pool->environment);
  799. else self->environment = Environment_NewFromScratch(threaded, events,
  800. encoding, nencoding);
  801. if (!self->environment)
  802. return -1;
  803. // keep a copy of the credentials
  804. Py_XINCREF(usernameObj);
  805. self->username = usernameObj;
  806. Py_XINCREF(dsnObj);
  807. self->dsn = dsnObj;
  808. // perform some parsing, if necessary
  809. if (Connection_SplitComponent(&self->username, &passwordObj, "/") < 0)
  810. return -1;
  811. if (Connection_SplitComponent(&passwordObj, &self->dsn, "@") < 0)
  812. return -1;
  813. // handle the different ways of initializing the connection
  814. if (handle)
  815. return Connection_Attach(self, handle);
  816. if (pool || cclassObj)
  817. return Connection_GetConnection(self, pool, passwordObj, cclassObj,
  818. purity);
  819. return Connection_Connect(self, connectMode, twophase, passwordObj,
  820. newPasswordObj, moduleObj, actionObj, clientinfoObj);
  821. }
  822. //-----------------------------------------------------------------------------
  823. // Connection_Free()
  824. // Deallocate the connection, disconnecting from the database if necessary.
  825. //-----------------------------------------------------------------------------
  826. static void Connection_Free(
  827. udt_Connection *self) // connection object
  828. {
  829. if (self->release) {
  830. Py_BEGIN_ALLOW_THREADS
  831. OCITransRollback(self->handle, self->environment->errorHandle,
  832. OCI_DEFAULT);
  833. OCISessionRelease(self->handle, self->environment->errorHandle, NULL,
  834. 0, OCI_DEFAULT);
  835. Py_END_ALLOW_THREADS
  836. } else if (!self->attached) {
  837. if (self->sessionHandle) {
  838. Py_BEGIN_ALLOW_THREADS
  839. OCITransRollback(self->handle, self->environment->errorHandle,
  840. OCI_DEFAULT);
  841. OCISessionEnd(self->handle, self->environment->errorHandle,
  842. self->sessionHandle, OCI_DEFAULT);
  843. Py_END_ALLOW_THREADS
  844. }
  845. if (self->serverHandle)
  846. OCIServerDetach(self->serverHandle,
  847. self->environment->errorHandle, OCI_DEFAULT);
  848. }
  849. Py_CLEAR(self->environment);
  850. Py_CLEAR(self->sessionPool);
  851. Py_CLEAR(self->username);
  852. Py_CLEAR(self->dsn);
  853. Py_CLEAR(self->version);
  854. Py_CLEAR(self->inputTypeHandler);
  855. Py_CLEAR(self->outputTypeHandler);
  856. Py_TYPE(self)->tp_free((PyObject*) self);
  857. }
  858. //-----------------------------------------------------------------------------
  859. // Connection_Repr()
  860. // Return a string representation of the connection.
  861. //-----------------------------------------------------------------------------
  862. static PyObject *Connection_Repr(
  863. udt_Connection *connection) // connection to return the string for
  864. {
  865. PyObject *module, *name, *result, *format, *formatArgs = NULL;
  866. if (GetModuleAndName(Py_TYPE(connection), &module, &name) < 0)
  867. return NULL;
  868. if (connection->username && connection->username != Py_None &&
  869. connection->dsn && connection->dsn != Py_None) {
  870. format = cxString_FromAscii("<%s.%s to %s@%s>");
  871. if (format)
  872. formatArgs = PyTuple_Pack(4, module, name, connection->username,
  873. connection->dsn);
  874. } else if (connection->username && connection->username != Py_None) {
  875. format = cxString_FromAscii("<%s.%s to user %s@local>");
  876. if (format)
  877. formatArgs = PyTuple_Pack(3, module, name, connection->username);
  878. } else {
  879. format = cxString_FromAscii("<%s.%s to externally identified user>");
  880. if (format)
  881. formatArgs = PyTuple_Pack(2, module, name);
  882. }
  883. Py_DECREF(module);
  884. Py_DECREF(name);
  885. if (!format)
  886. return NULL;
  887. if (!formatArgs) {
  888. Py_DECREF(format);
  889. return NULL;
  890. }
  891. result = cxString_Format(format, formatArgs);
  892. Py_DECREF(format);
  893. Py_DECREF(formatArgs);
  894. return result;
  895. }
  896. //-----------------------------------------------------------------------------
  897. // Connection_GetStmtCacheSize()
  898. // Return the Oracle statement cache size.
  899. //-----------------------------------------------------------------------------
  900. static PyObject *Connection_GetStmtCacheSize(
  901. udt_Connection* self, // connection object
  902. void* arg) // optional argument (ignored)
  903. {
  904. ub4 cacheSize;
  905. sword status;
  906. if (Connection_IsConnected(self) < 0)
  907. return NULL;
  908. status = OCIAttrGet(self->handle, OCI_HTYPE_SVCCTX,
  909. (dvoid**) &cacheSize, 0, OCI_ATTR_STMTCACHESIZE,
  910. self->environment->errorHandle);
  911. if (Environment_CheckForError(self->environment, status,
  912. "Connection_GetStmtCacheSize()") < 0)
  913. return NULL;
  914. return PyInt_FromLong(cacheSize);
  915. }
  916. //-----------------------------------------------------------------------------
  917. // Connection_SetStmtCacheSize()
  918. // Set the Oracle statement cache size.
  919. //-----------------------------------------------------------------------------
  920. static int Connection_SetStmtCacheSize(
  921. udt_Connection* self, // connection object
  922. PyObject *value, // value to set it to
  923. void* arg) // optional argument (ignored)
  924. {
  925. ub4 valueToSet;
  926. sword status;
  927. if (Connection_IsConnected(self) < 0)
  928. return -1;
  929. if (!PyInt_Check(value)) {
  930. PyErr_SetString(PyExc_TypeError, "value must be an integer");
  931. return -1;
  932. }
  933. valueToSet = (ub4) PyInt_AsLong(value);
  934. if (PyErr_Occurred())
  935. return -1;
  936. status = OCIAttrSet(self->handle, OCI_HTYPE_SVCCTX, (dvoid*) &valueToSet,
  937. 0, OCI_ATTR_STMTCACHESIZE, self->environment->errorHandle);
  938. if (Environment_CheckForError(self->environment, status,
  939. "Connection_SetStmtCacheSize()") < 0)
  940. return -1;
  941. return 0;
  942. }
  943. //-----------------------------------------------------------------------------
  944. // Connection_GetVersion()
  945. // Retrieve the version of the database and return it. Note that this
  946. // function also places the result in the associated dictionary so it is only
  947. // calculated once.
  948. //-----------------------------------------------------------------------------
  949. static PyObject *Connection_GetVersion(
  950. udt_Connection *self, // connection object
  951. void *arg) // optional argument (ignored)
  952. {
  953. PyObject *procName, *listOfArguments;
  954. udt_Variable *versionVar, *compatVar;
  955. udt_Cursor *cursor;
  956. // if version has already been determined, no need to determine again
  957. if (self->version) {
  958. Py_INCREF(self->version);
  959. return self->version;
  960. }
  961. // allocate a cursor to retrieve the version
  962. cursor = (udt_Cursor*) Connection_NewCursor(self, NULL);
  963. if (!cursor)
  964. return NULL;
  965. // allocate version variable
  966. versionVar = Variable_New(cursor, cursor->arraySize, &vt_String,
  967. vt_String.size);
  968. if (!versionVar) {
  969. Py_DECREF(cursor);
  970. return NULL;
  971. }
  972. // allocate compatibility variable
  973. compatVar = Variable_New(cursor, cursor->arraySize, &vt_String,
  974. vt_String.size);
  975. if (!compatVar) {
  976. Py_DECREF(versionVar);
  977. Py_DECREF(cursor);
  978. return NULL;
  979. }
  980. // create the list of arguments
  981. listOfArguments = PyList_New(2);
  982. if (!listOfArguments) {
  983. Py_DECREF(versionVar);
  984. Py_DECREF(compatVar);
  985. Py_DECREF(cursor);
  986. return NULL;
  987. }
  988. PyList_SET_ITEM(listOfArguments, 0, (PyObject*) versionVar);
  989. PyList_SET_ITEM(listOfArguments, 1, (PyObject*) compatVar);
  990. // create the string variable
  991. procName = cxString_FromAscii("dbms_utility.db_version");
  992. if (!procName) {
  993. Py_DECREF(listOfArguments);
  994. Py_DECREF(cursor);
  995. return NULL;
  996. }
  997. // call stored procedure
  998. if (Cursor_Call(cursor, NULL, procName, listOfArguments, NULL) < 0) {
  999. Py_DECREF(procName);
  1000. Py_DECREF(listOfArguments);
  1001. Py_DECREF(cursor);
  1002. return NULL;
  1003. }
  1004. Py_DECREF(procName);
  1005. // retrieve value
  1006. self->version = Variable_GetValue(versionVar, 0);
  1007. Py_DECREF(listOfArguments);
  1008. Py_DECREF(cursor);
  1009. Py_XINCREF(self->version);
  1010. return self->version;
  1011. }
  1012. //-----------------------------------------------------------------------------
  1013. // Connection_GetEncoding()
  1014. // Return the encoding associated with the environment of the connection.
  1015. //-----------------------------------------------------------------------------
  1016. static PyObject *Connection_GetEncoding(
  1017. udt_Connection *self, // connection object
  1018. void *arg) // optional argument (ignored)
  1019. {
  1020. return cxString_FromAscii(self->environment->encoding);
  1021. }
  1022. //-----------------------------------------------------------------------------
  1023. // Connection_GetNationalEncoding()
  1024. // Return the national encoding associated with the environment of the
  1025. // connection.
  1026. //-----------------------------------------------------------------------------
  1027. static PyObject *Connection_GetNationalEncoding(
  1028. udt_Connection *self, // connection object
  1029. void *arg) // optional argument (ignored)
  1030. {
  1031. return cxString_FromAscii(self->environment->nencoding);
  1032. }
  1033. //-----------------------------------------------------------------------------
  1034. // Connection_GetMaxBytesPerCharacter()
  1035. // Return the maximum number of bytes per character.
  1036. //-----------------------------------------------------------------------------
  1037. static PyObject *Connection_GetMaxBytesPerCharacter(
  1038. udt_Connection *self, // connection object
  1039. void *arg) // optional argument (ignored)
  1040. {
  1041. return PyInt_FromLong(self->environment->maxBytesPerCharacter);
  1042. }
  1043. //-----------------------------------------------------------------------------
  1044. // Connection_Close()
  1045. // Close the connection, disconnecting from the database.
  1046. //-----------------------------------------------------------------------------
  1047. static PyObject *Connection_Close(
  1048. udt_Connection *self, // connection to close
  1049. PyObject *args) // arguments
  1050. {
  1051. sword status;
  1052. // make sure we are actually connected
  1053. if (Connection_IsConnected(self) < 0)
  1054. return NULL;
  1055. // perform a rollback
  1056. Py_BEGIN_ALLOW_THREADS
  1057. status = OCITransRollback(self->handle, self->environment->errorHandle,
  1058. OCI_DEFAULT);
  1059. Py_END_ALLOW_THREADS
  1060. if (Environment_CheckForError(self->environment, status,
  1061. "Connection_Close(): rollback") < 0)
  1062. return NULL;
  1063. // logoff of the server
  1064. if (self->release) {
  1065. Py_BEGIN_ALLOW_THREADS
  1066. status = OCISessionRelease(self->handle,
  1067. self->environment->errorHandle, NULL, 0, OCI_DEFAULT);
  1068. Py_END_ALLOW_THREADS
  1069. if (Environment_CheckForError(self->environment, status,
  1070. "Connection_Close(): release session") < 0)
  1071. return NULL;
  1072. self->release = 0;
  1073. }
  1074. else {
  1075. if (self->sessionHandle) {
  1076. Py_BEGIN_ALLOW_THREADS
  1077. status = OCISessionEnd(self->handle,
  1078. self->environment->errorHandle, self->sessionHandle,
  1079. OCI_DEFAULT);
  1080. Py_END_ALLOW_THREADS
  1081. if (Environment_CheckForError(self->environment, status,
  1082. "Connection_Close(): end session") < 0)
  1083. return NULL;
  1084. OCIHandleFree(self->sessionHandle, OCI_HTYPE_SESSION);
  1085. self->sessionHandle = NULL;
  1086. OCIHandleFree(self->handle, OCI_HTYPE_SVCCTX);
  1087. }
  1088. if (self->serverHandle) {
  1089. status = OCIServerDetach(self->serverHandle,
  1090. self->environment->errorHandle, OCI_DEFAULT);
  1091. if (Environment_CheckForError(self->environment, status,
  1092. "Connection_Close(): server detach") < 0)
  1093. return NULL;
  1094. OCIHandleFree(self->serverHandle, OCI_HTYPE_SERVER);
  1095. self->serverHandle = NULL;
  1096. }
  1097. }
  1098. self->handle = NULL;
  1099. Py_INCREF(Py_None);
  1100. return Py_None;
  1101. }
  1102. //-----------------------------------------------------------------------------
  1103. // Connection_Commit()
  1104. // Commit the transaction on the connection.
  1105. //-----------------------------------------------------------------------------
  1106. static PyObject *Connection_Commit(
  1107. udt_Connection *self, // connection to commit
  1108. PyObject *args) // arguments
  1109. {
  1110. sword status;
  1111. // make sure we are actually connected
  1112. if (Connection_IsConnected(self) < 0)
  1113. return NULL;
  1114. // perform the commit
  1115. Py_BEGIN_ALLOW_THREADS
  1116. status = OCITransCommit(self->handle, self->environment->errorHandle,
  1117. self->commitMode);
  1118. Py_END_ALLOW_THREADS
  1119. if (Environment_CheckForError(self->environment, status,
  1120. "Connection_Commit()") < 0)
  1121. return NULL;
  1122. self->commitMode = OCI_DEFAULT;
  1123. Py_INCREF(Py_None);
  1124. return Py_None;
  1125. }
  1126. //-----------------------------------------------------------------------------
  1127. // Connection_Begin()
  1128. // Begin a new transaction on the connection.
  1129. //-----------------------------------------------------------------------------
  1130. static PyObject *Connection_Begin(
  1131. udt_Connection *self, // connection to commit
  1132. PyObject *args) // arguments
  1133. {
  1134. unsigned transactionIdLength, branchIdLength;
  1135. const char *transactionId, *branchId;
  1136. OCITrans *transactionHandle;
  1137. int formatId;
  1138. sword status;
  1139. XID xid;
  1140. // parse the arguments
  1141. formatId = -1;
  1142. transactionIdLength = branchIdLength = 0;
  1143. if (!PyArg_ParseTuple(args, "|is#s#", &formatId, &transactionId,
  1144. &transactionIdLength, &branchId, &branchIdLength))
  1145. return NULL;
  1146. if (transactionIdLength > MAXGTRIDSIZE) {
  1147. PyErr_SetString(PyExc_ValueError, "transaction id too large");
  1148. return NULL;
  1149. }
  1150. if (branchIdLength > MAXBQUALSIZE) {
  1151. PyErr_SetString(PyExc_ValueError, "branch id too large");
  1152. return NULL;
  1153. }
  1154. // make sure we are actually connected
  1155. if (Connection_IsConnected(self) < 0)
  1156. return NULL;
  1157. // determine if a transaction handle was previously allocated
  1158. status = OCIAttrGet(self->handle, OCI_HTYPE_SVCCTX,
  1159. (dvoid**) &transactionHandle, 0, OCI_ATTR_TRANS,
  1160. self->environment->errorHandle);
  1161. if (Environment_CheckForError(self->environment, status,
  1162. "Connection_Begin(): find existing transaction handle") < 0)
  1163. return NULL;
  1164. // create a new transaction handle, if necessary
  1165. if (!transactionHandle) {
  1166. status = OCIHandleAlloc(self->environment->handle,
  1167. (dvoid**) &transactionHandle, OCI_HTYPE_TRANS, 0, 0);
  1168. if (Environment_CheckForError(self->environment, status,
  1169. "Connection_Begin(): allocate transaction handle") < 0)
  1170. return NULL;
  1171. }
  1172. // set the XID for the transaction, if applicable
  1173. if (formatId != -1) {
  1174. xid.formatID = formatId;
  1175. xid.gtrid_length = transactionIdLength;
  1176. xid.bqual_length = branchIdLength;
  1177. if (transactionIdLength > 0)
  1178. strncpy(xid.data, transactionId, transactionIdLength);
  1179. if (branchIdLength > 0)
  1180. strncpy(&xid.data[transactionIdLength], branchId, branchIdLength);
  1181. OCIAttrSet(transactionHandle, OCI_HTYPE_TRANS, &xid, sizeof(XID),
  1182. OCI_ATTR_XID, self->environment->errorHandle);
  1183. if (Environment_CheckForError(self->environment, status,
  1184. "Connection_Begin(): set XID") < 0)
  1185. return NULL;
  1186. }
  1187. // associate the transaction with the connection
  1188. OCIAttrSet(self->handle, OCI_HTYPE_SVCCTX, transactionHandle, 0,
  1189. OCI_ATTR_TRANS, self->environment->errorHandle);
  1190. if (Environment_CheckForError(self->environment, status,
  1191. "Connection_Begin(): associate transaction") < 0)
  1192. return NULL;
  1193. // start the transaction
  1194. Py_BEGIN_ALLOW_THREADS
  1195. status = OCITransStart(self->handle, self->environment->errorHandle, 0,
  1196. OCI_TRANS_NEW);
  1197. Py_END_ALLOW_THREADS
  1198. if (Environment_CheckForError(self->environment, status,
  1199. "Connection_Begin(): start transaction") < 0)
  1200. return NULL;
  1201. Py_INCREF(Py_None);
  1202. return Py_None;
  1203. }
  1204. //-----------------------------------------------------------------------------
  1205. // Connection_Prepare()
  1206. // Commit the transaction on the connection.
  1207. //-----------------------------------------------------------------------------
  1208. static PyObject *Connection_Prepare(
  1209. udt_Connection *self, // connection to commit
  1210. PyObject *args) // arguments
  1211. {
  1212. sword status;
  1213. // make sure we are actually connected
  1214. if (Connection_IsConnected(self) < 0)
  1215. return NULL;
  1216. // perform the prepare
  1217. Py_BEGIN_ALLOW_THREADS
  1218. status = OCITransPrepare(self->handle, self->environment->errorHandle,
  1219. OCI_DEFAULT);
  1220. Py_END_ALLOW_THREADS
  1221. if (Environment_CheckForError(self->environment, status,
  1222. "Connection_Prepare()") < 0)
  1223. return NULL;
  1224. // if nothing available to prepare, return False in order to allow for
  1225. // avoiding the call to commit() which will fail with ORA-24756
  1226. // (transaction does not exist)
  1227. if (status == OCI_SUCCESS_WITH_INFO) {
  1228. Py_INCREF(Py_False);
  1229. return Py_False;
  1230. }
  1231. self->commitMode = OCI_TRANS_TWOPHASE;
  1232. Py_INCREF(Py_True);
  1233. return Py_True;
  1234. }
  1235. //-----------------------------------------------------------------------------
  1236. // Connection_Rollback()
  1237. // Rollback the transaction on the connection.
  1238. //-----------------------------------------------------------------------------
  1239. static PyObject *Connection_Rollback(
  1240. udt_Connection *self, // connection to rollback
  1241. PyObject *args) // arguments
  1242. {
  1243. sword status;
  1244. // make sure we are actually connected
  1245. if (Connection_IsConnected(self) < 0)
  1246. return NULL;
  1247. // perform the rollback
  1248. Py_BEGIN_ALLOW_THREADS
  1249. status = OCITransRollback(self->handle, self->environment->errorHandle,
  1250. OCI_DEFAULT);
  1251. Py_END_ALLOW_THREADS
  1252. if (Environment_CheckForError(self->environment, status,
  1253. "Connection_Rollback()") < 0)
  1254. return NULL;
  1255. Py_INCREF(Py_None);
  1256. return Py_None;
  1257. }
  1258. //-----------------------------------------------------------------------------
  1259. // Connection_NewCursor()
  1260. // Create a new cursor (statement) referencing the connection.
  1261. //-----------------------------------------------------------------------------
  1262. static PyObject *Connection_NewCursor(
  1263. udt_Connection *self, // connection to create cursor on
  1264. PyObject *args) // arguments
  1265. {
  1266. PyObject *createArgs, *result;
  1267. createArgs = PyTuple_New(1);
  1268. if (!createArgs)
  1269. return NULL;
  1270. Py_INCREF(self);
  1271. PyTuple_SET_ITEM(createArgs, 0, (PyObject*) self);
  1272. result = PyObject_Call( (PyObject*) &g_CursorType, createArgs, NULL);
  1273. Py_DECREF(createArgs);
  1274. return result;
  1275. }
  1276. //-----------------------------------------------------------------------------
  1277. // Connection_Cancel()
  1278. // Execute an OCIBreak() to cause an immediate (asynchronous) abort of any
  1279. // currently executing OCI function.
  1280. //-----------------------------------------------------------------------------
  1281. static PyObject *Connection_Cancel(
  1282. udt_Connection *self, // connection to cancel
  1283. PyObject *args) // arguments
  1284. {
  1285. sword status;
  1286. // make sure we are actually connected
  1287. if (Connection_IsConnected(self) < 0)
  1288. return NULL;
  1289. // perform the break
  1290. status = OCIBreak(self->handle, self->environment->errorHandle);
  1291. if (Environment_CheckForError(self->environment, status,
  1292. "Connection_Cancel()") < 0)
  1293. return NULL;
  1294. Py_INCREF(Py_None);
  1295. return Py_None;
  1296. }
  1297. //-----------------------------------------------------------------------------
  1298. // Connection_RegisterCallback()
  1299. // Register a callback for the OCI function.
  1300. //-----------------------------------------------------------------------------
  1301. static PyObject *Connection_RegisterCallback(
  1302. udt_Connection *self, // connection to register callback on
  1303. PyObject *args) // arguments
  1304. {
  1305. PyObject *callback, *tuple;
  1306. int functionCode, when;
  1307. sword status;
  1308. // parse the arguments
  1309. if (!PyArg_ParseTuple(args, "iiO", &functionCode, &when, &callback))
  1310. return NULL;
  1311. // create a tuple for passing through to the callback handler
  1312. tuple = Py_BuildValue("OO", self, callback);
  1313. if (!tuple)
  1314. return NULL;
  1315. // make sure we are actually connected
  1316. if (Connection_IsConnected(self) < 0)
  1317. return NULL;
  1318. // register the callback with the OCI
  1319. status = OCIUserCallbackRegister(self->environment->handle, OCI_HTYPE_ENV,
  1320. self->environment->errorHandle, (OCIUserCallback) Callback_Handler,
  1321. tuple, functionCode, when, NULL);
  1322. if (Environment_CheckForError(self->environment, status,
  1323. "Connection_RegisterCallback()") < 0)
  1324. return NULL;
  1325. Py_INCREF(Py_None);
  1326. return Py_None;
  1327. }
  1328. //-----------------------------------------------------------------------------
  1329. // Connection_UnregisterCallback()
  1330. // Unregister a callback for the OCI function, if one has been registered.
  1331. // No error is raised if a callback has not been registered.
  1332. //-----------------------------------------------------------------------------
  1333. static PyObject *Connection_UnregisterCallback(
  1334. udt_Connection *self, // connection to unregister callback on
  1335. PyObject *args) // arguments
  1336. {
  1337. OCIUserCallback callback;
  1338. int functionCode, when;
  1339. PyObject *tuple;
  1340. sword status;
  1341. // parse the arguments
  1342. if (!PyArg_ParseTuple(args, "ii", &functionCode, &when))
  1343. return NULL;
  1344. // make sure we are actually connected
  1345. if (Connection_IsConnected(self) < 0)
  1346. return NULL;
  1347. // find out if a callback has been registered
  1348. status = OCIUserCallbackGet(self->environment->handle, OCI_HTYPE_ENV,
  1349. self->environment->errorHandle, functionCode, when, &callback,
  1350. (dvoid**) &tuple, NULL);
  1351. if (Environment_CheckForError(self->environment, status,
  1352. "Connection_UnregisterCallback(): get") < 0)
  1353. return NULL;
  1354. // if a callback was registered, clear it
  1355. if (callback) {
  1356. Py_DECREF(tuple);
  1357. status = OCIUserCallbackRegister(self->environment->handle,
  1358. OCI_HTYPE_ENV, self->environment->errorHandle, NULL,
  1359. NULL, functionCode, when, NULL);
  1360. if (Environment_CheckForError(self->environment, status,
  1361. "Connection_UnregisterCallback(): clear") < 0)
  1362. return NULL;
  1363. }
  1364. Py_INCREF(Py_None);
  1365. return Py_None;
  1366. }
  1367. //-----------------------------------------------------------------------------
  1368. // Connection_ContextManagerEnter()
  1369. // Called when the connection is used as a context manager and simply returns
  1370. // itself as a convenience to the caller.
  1371. //-----------------------------------------------------------------------------
  1372. static PyObject *Connection_ContextManagerEnter(
  1373. udt_Connection *self, // connection
  1374. PyObject* args) // arguments
  1375. {
  1376. Py_INCREF(self);
  1377. return (PyObject*) self;
  1378. }
  1379. //-----------------------------------------------------------------------------
  1380. // Connection_ContextManagerExit()
  1381. // Called when the connection is used as a context manager and if any
  1382. // exception a rollback takes place; otherwise, a commit takes place.
  1383. //-----------------------------------------------------------------------------
  1384. static PyObject *Connection_ContextManagerExit(
  1385. udt_Connection *self, // connection
  1386. PyObject* args) // arguments
  1387. {
  1388. PyObject *excType, *excValue, *excTraceback, *result;
  1389. char *methodName;
  1390. if (!PyArg_ParseTuple(args, "OOO", &excType, &excValue, &excTraceback))
  1391. return NULL;
  1392. if (excType == Py_None && excValue == Py_None && excTraceback == Py_None)
  1393. methodName = "commit";
  1394. else methodName = "rollback";
  1395. result = PyObject_CallMethod((PyObject*) self, methodName, "");
  1396. if (!result)
  1397. return NULL;
  1398. Py_DECREF(result);
  1399. Py_INCREF(Py_False);
  1400. return Py_False;
  1401. }
  1402. #if ORACLE_VERSION_HEX >= ORACLE_VERSION(10, 2)
  1403. #if !defined(AIX5) || ORACLE_VERSION_HEX >= ORACLE_VERSION(11, 1)
  1404. //-----------------------------------------------------------------------------
  1405. // Connection_Ping()
  1406. // Makes a round trip call to the server to confirm that the connection and
  1407. // server are active.
  1408. //-----------------------------------------------------------------------------
  1409. static PyObject *Connection_Ping(
  1410. udt_Connection *self, // connection
  1411. PyObject* args) // arguments
  1412. {
  1413. sword status;
  1414. if (Connection_IsConnected(self) < 0)
  1415. return NULL;
  1416. status = OCIPing(self->handle, self->environment->errorHandle,
  1417. OCI_DEFAULT);
  1418. if (Environment_CheckForError(self->environment, status,
  1419. "Connection_Ping()") < 0)
  1420. return NULL;
  1421. Py_INCREF(Py_None);
  1422. return Py_None;
  1423. }
  1424. #endif
  1425. //-----------------------------------------------------------------------------
  1426. // Connection_Shutdown()
  1427. // Shuts down the database. Note that this must be done in two phases except
  1428. // in the situation where the instance is aborted.
  1429. //-----------------------------------------------------------------------------
  1430. static PyObject *Connection_Shutdown(
  1431. udt_Connection *self, // connection
  1432. PyObject* args, // arguments
  1433. PyObject* keywordArgs) // keyword arguments
  1434. {
  1435. static char *keywordList[] = { "mode", NULL };
  1436. sword status;
  1437. ub4 mode;
  1438. // parse arguments
  1439. mode = OCI_DEFAULT;
  1440. if (!PyArg_ParseTupleAndKeywords(args, keywordArgs, "|i", keywordList,
  1441. &mode))
  1442. return NULL;
  1443. // perform the work
  1444. if (Connection_IsConnected(self) < 0)
  1445. return NULL;
  1446. status = OCIDBShutdown(self->handle, self->environment->errorHandle, NULL,
  1447. mode);
  1448. if (Environment_CheckForError(self->environment, status,
  1449. "Connection_Shutdown()") < 0)
  1450. return NULL;
  1451. Py_INCREF(Py_None);
  1452. return Py_None;
  1453. }
  1454. //-----------------------------------------------------------------------------
  1455. // Connection_Startup()
  1456. // Starts up the database, equivalent to "startup nomount" in SQL*Plus.
  1457. //-----------------------------------------------------------------------------
  1458. static PyObject *Connection_Startup(
  1459. udt_Connection *self, // connection
  1460. PyObject* args, // arguments
  1461. PyObject* keywordArgs) // keyword arguments
  1462. {
  1463. static char *keywordList[] = { "force", "restrict", NULL };
  1464. PyObject *forceObj, *restrictObj;
  1465. int flagTemp;
  1466. sword status;
  1467. ub4 flags;
  1468. // parse arguments
  1469. forceObj = restrictObj = NULL;
  1470. if (!PyArg_ParseTupleAndKeywords(args, keywordArgs, "|OO", keywordList,
  1471. &forceObj, &restrictObj))
  1472. return NULL;
  1473. // set the flags to use during startup
  1474. flags = 0;
  1475. if (forceObj) {
  1476. flagTemp = PyObject_IsTrue(forceObj);
  1477. if (flagTemp < 0)
  1478. return NULL;
  1479. if (flagTemp)
  1480. flags |= OCI_DBSTARTUPFLAG_FORCE;
  1481. }
  1482. if (restrictObj) {
  1483. flagTemp = PyObject_IsTrue(restrictObj);
  1484. if (flagTemp < 0)
  1485. return NULL;
  1486. if (flagTemp)
  1487. flags |= OCI_DBSTARTUPFLAG_RESTRICT;
  1488. }
  1489. // perform the work
  1490. if (Connection_IsConnected(self) < 0)
  1491. return NULL;
  1492. status = OCIDBStartup(self->handle, self->environment->errorHandle, NULL,
  1493. OCI_DEFAULT, flags);
  1494. if (Environment_CheckForError(self->environment, status,
  1495. "Connection_Startup()") < 0)
  1496. return NULL;
  1497. Py_INCREF(Py_None);
  1498. return Py_None;
  1499. }
  1500. //-----------------------------------------------------------------------------
  1501. // Connection_Subscribe()
  1502. // Create a subscription to events that take place in the database.
  1503. //-----------------------------------------------------------------------------
  1504. static PyObject *Connection_Subscribe(
  1505. udt_Connection *self, // connection
  1506. PyObject* args, // arguments
  1507. PyObject* keywordArgs) // keyword arguments
  1508. {
  1509. static char *keywordList[] = { "namespace", "protocol", "callback",
  1510. "timeout", "operations", "rowids", "port", "qos", "cqqos", NULL };
  1511. ub4 namespace, protocol, port, timeout, rowids, operations, qos, cqqos;
  1512. PyObject *rowidsObj, *callback;
  1513. int temp;
  1514. // parse arguments
  1515. timeout = rowids = port = qos = cqqos = 0;
  1516. rowidsObj = callback = NULL;
  1517. namespace = OCI_SUBSCR_NAMESPACE_DBCHANGE;
  1518. protocol = OCI_SUBSCR_PROTO_OCI;
  1519. operations = OCI_OPCODE_ALLOPS;
  1520. if (!PyArg_ParseTupleAndKeywords(args, keywordArgs, "|iiOiiOiii", keywordList,
  1521. &namespace, &protocol, &callback, &timeout, &operations,
  1522. &rowidsObj, &port, &qos, &cqqos))
  1523. return NULL;
  1524. // set the value for rowids
  1525. if (rowidsObj) {
  1526. temp = PyObject_IsTrue(rowidsObj);
  1527. if (temp < 0)
  1528. return NULL;
  1529. if (temp)
  1530. rowids = 1;
  1531. }
  1532. return (PyObject*) Subscription_New(self, namespace, protocol, port,
  1533. callback, timeout, operations, qos, cqqos, rowids);
  1534. }
  1535. #endif