Connection.c 63 KB

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