oracledb 3.0.0 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/CHANGELOG.md +135 -8
  2. package/README.md +6 -4
  3. package/build/Release/oracledb-abi48-darwin-x64.node +0 -0
  4. package/build/Release/oracledb-abi48-darwin-x64.node-buildinfo.txt +1 -0
  5. package/build/Release/oracledb-abi48-linux-x64.node +0 -0
  6. package/build/Release/oracledb-abi48-linux-x64.node-buildinfo.txt +1 -0
  7. package/build/Release/oracledb-abi48-win32-x64.node +0 -0
  8. package/build/Release/oracledb-abi48-win32-x64.node-buildinfo.txt +1 -0
  9. package/build/Release/oracledb-abi57-darwin-x64.node +0 -0
  10. package/build/Release/oracledb-abi57-darwin-x64.node-buildinfo.txt +1 -0
  11. package/build/Release/oracledb-abi57-linux-x64.node +0 -0
  12. package/build/Release/oracledb-abi57-linux-x64.node-buildinfo.txt +1 -0
  13. package/build/Release/oracledb-abi57-win32-x64.node +0 -0
  14. package/build/Release/oracledb-abi57-win32-x64.node-buildinfo.txt +1 -0
  15. package/build/Release/oracledb-abi64-darwin-x64.node +0 -0
  16. package/build/Release/oracledb-abi64-darwin-x64.node-buildinfo.txt +1 -0
  17. package/build/Release/oracledb-abi64-linux-x64.node +0 -0
  18. package/build/Release/oracledb-abi64-linux-x64.node-buildinfo.txt +1 -0
  19. package/build/Release/oracledb-abi64-win32-x64.node +0 -0
  20. package/build/Release/oracledb-abi64-win32-x64.node-buildinfo.txt +1 -0
  21. package/build/Release/oracledb-abi67-darwin-x64.node +0 -0
  22. package/build/Release/oracledb-abi67-darwin-x64.node-buildinfo.txt +1 -0
  23. package/build/Release/oracledb-abi67-linux-x64.node +0 -0
  24. package/build/Release/oracledb-abi67-linux-x64.node-buildinfo.txt +1 -0
  25. package/build/Release/oracledb-abi67-win32-x64.node +0 -0
  26. package/build/Release/oracledb-abi67-win32-x64.node-buildinfo.txt +1 -0
  27. package/lib/connection.js +18 -4
  28. package/lib/oracledb.js +44 -92
  29. package/lib/pool.js +36 -2
  30. package/lib/sodaCollection.js +1 -1
  31. package/lib/sodaDatabase.js +1 -1
  32. package/lib/util.js +82 -5
  33. package/package/README.md +32 -101
  34. package/package/install.js +139 -0
  35. package/package/prunebinaries.js +51 -0
  36. package/package.json +4 -11
  37. package/binding.gyp +0 -162
  38. package/lib/rel.txt +0 -1
  39. package/odpi/.npmignore +0 -4
  40. package/odpi/LICENSE.md +0 -218
  41. package/odpi/README.md +0 -61
  42. package/odpi/embed/README.md +0 -4
  43. package/odpi/embed/dpi.c +0 -50
  44. package/odpi/include/dpi.h +0 -1748
  45. package/odpi/src/dpiConn.c +0 -2089
  46. package/odpi/src/dpiContext.c +0 -296
  47. package/odpi/src/dpiData.c +0 -797
  48. package/odpi/src/dpiDebug.c +0 -184
  49. package/odpi/src/dpiDeqOptions.c +0 -370
  50. package/odpi/src/dpiEnqOptions.c +0 -174
  51. package/odpi/src/dpiEnv.c +0 -189
  52. package/odpi/src/dpiError.c +0 -204
  53. package/odpi/src/dpiErrorMessages.h +0 -86
  54. package/odpi/src/dpiGen.c +0 -303
  55. package/odpi/src/dpiGlobal.c +0 -292
  56. package/odpi/src/dpiHandleList.c +0 -117
  57. package/odpi/src/dpiHandlePool.c +0 -118
  58. package/odpi/src/dpiImpl.h +0 -1707
  59. package/odpi/src/dpiLob.c +0 -506
  60. package/odpi/src/dpiMsgProps.c +0 -386
  61. package/odpi/src/dpiObject.c +0 -897
  62. package/odpi/src/dpiObjectAttr.c +0 -115
  63. package/odpi/src/dpiObjectType.c +0 -326
  64. package/odpi/src/dpiOci.c +0 -3527
  65. package/odpi/src/dpiOracleType.c +0 -492
  66. package/odpi/src/dpiPool.c +0 -549
  67. package/odpi/src/dpiRowid.c +0 -136
  68. package/odpi/src/dpiSodaColl.c +0 -685
  69. package/odpi/src/dpiSodaCollCursor.c +0 -143
  70. package/odpi/src/dpiSodaDb.c +0 -432
  71. package/odpi/src/dpiSodaDoc.c +0 -230
  72. package/odpi/src/dpiSodaDocCursor.c +0 -143
  73. package/odpi/src/dpiStmt.c +0 -1797
  74. package/odpi/src/dpiSubscr.c +0 -674
  75. package/odpi/src/dpiUtils.c +0 -410
  76. package/odpi/src/dpiVar.c +0 -1794
  77. package/package/MAKEPKG.BAT +0 -156
  78. package/package/Makefile +0 -85
  79. package/package/createpackage.js +0 -186
  80. package/package/extractpackage.js +0 -76
  81. package/package/getversion.js +0 -37
  82. package/package/oracledbinstall.js +0 -497
  83. package/package/package.json +0 -54
  84. package/package/util.js +0 -286
  85. package/src/njsCommon.cpp +0 -1055
  86. package/src/njsCommon.h +0 -484
  87. package/src/njsConnection.cpp +0 -2926
  88. package/src/njsConnection.h +0 -227
  89. package/src/njsIntLob.cpp +0 -618
  90. package/src/njsIntLob.h +0 -179
  91. package/src/njsMessages.cpp +0 -122
  92. package/src/njsMessages.h +0 -118
  93. package/src/njsOracle.cpp +0 -1274
  94. package/src/njsOracle.h +0 -237
  95. package/src/njsPool.cpp +0 -482
  96. package/src/njsPool.h +0 -132
  97. package/src/njsResultSet.cpp +0 -478
  98. package/src/njsResultSet.h +0 -120
  99. package/src/njsSodaCollection.cpp +0 -507
  100. package/src/njsSodaCollection.h +0 -128
  101. package/src/njsSodaDatabase.cpp +0 -335
  102. package/src/njsSodaDatabase.h +0 -108
  103. package/src/njsSodaDocCursor.cpp +0 -203
  104. package/src/njsSodaDocCursor.h +0 -94
  105. package/src/njsSodaDocument.cpp +0 -412
  106. package/src/njsSodaDocument.h +0 -105
  107. package/src/njsSodaOperation.cpp +0 -557
  108. package/src/njsSodaOperation.h +0 -123
  109. package/src/njsSubscription.cpp +0 -388
  110. package/src/njsSubscription.h +0 -111
  111. package/src/njsUtils.cpp +0 -158
  112. package/src/njsUtils.h +0 -68
@@ -1,2089 +0,0 @@
1
- //-----------------------------------------------------------------------------
2
- // Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
3
- // This program is free software: you can modify it and/or redistribute it
4
- // under the terms of:
5
- //
6
- // (i) the Universal Permissive License v 1.0 or at your option, any
7
- // later version (http://oss.oracle.com/licenses/upl); and/or
8
- //
9
- // (ii) the Apache License v 2.0. (http://www.apache.org/licenses/LICENSE-2.0)
10
- //-----------------------------------------------------------------------------
11
-
12
- //-----------------------------------------------------------------------------
13
- // dpiConn.c
14
- // Implementation of connection.
15
- //-----------------------------------------------------------------------------
16
-
17
- #include "dpiImpl.h"
18
- #include <time.h>
19
-
20
- // forward declarations of internal functions only used in this file
21
- static int dpiConn__createStandalone(dpiConn *conn, const char *userName,
22
- uint32_t userNameLength, const char *password, uint32_t passwordLength,
23
- const char *connectString, uint32_t connectStringLength,
24
- const dpiCommonCreateParams *commonParams,
25
- const dpiConnCreateParams *createParams, dpiError *error);
26
- static int dpiConn__get(dpiConn *conn, const char *userName,
27
- uint32_t userNameLength, const char *password, uint32_t passwordLength,
28
- const char *connectString, uint32_t connectStringLength,
29
- dpiConnCreateParams *createParams, dpiPool *pool, dpiError *error);
30
- static int dpiConn__getHandles(dpiConn *conn, dpiError *error);
31
- static int dpiConn__getServerCharset(dpiConn *conn, dpiError *error);
32
- static int dpiConn__getSession(dpiConn *conn, uint32_t mode,
33
- const char *connectString, uint32_t connectStringLength,
34
- dpiConnCreateParams *params, void *authInfo, dpiError *error);
35
- static int dpiConn__setAttributesFromCreateParams(dpiConn *conn, void *handle,
36
- uint32_t handleType, const char *userName, uint32_t userNameLength,
37
- const char *password, uint32_t passwordLength,
38
- const dpiConnCreateParams *params, void **shardingKey,
39
- void **superShardingKey, dpiError *error);
40
- static int dpiConn__setShardingKey(dpiConn *conn, void **shardingKey,
41
- void *handle, uint32_t handleType, uint32_t attribute,
42
- const char *action, dpiShardingKeyColumn *columns, uint8_t numColumns,
43
- dpiError *error);
44
- static int dpiConn__setShardingKeyValue(dpiConn *conn, void *shardingKey,
45
- dpiShardingKeyColumn *column, dpiError *error);
46
-
47
-
48
- //-----------------------------------------------------------------------------
49
- // dpiConn__check() [INTERNAL]
50
- // Validate the connection handle and that it is still connected to the
51
- // database.
52
- //-----------------------------------------------------------------------------
53
- static int dpiConn__check(dpiConn *conn, const char *fnName, dpiError *error)
54
- {
55
- if (dpiGen__startPublicFn(conn, DPI_HTYPE_CONN, fnName, 1, error) < 0)
56
- return DPI_FAILURE;
57
- return dpiConn__checkConnected(conn, error);
58
- }
59
-
60
-
61
- //-----------------------------------------------------------------------------
62
- // dpiConn__checkConnected() [INTERNAL]
63
- // Check to see if the connection is still open and raise an exception if it
64
- // is not.
65
- //-----------------------------------------------------------------------------
66
- int dpiConn__checkConnected(dpiConn *conn, dpiError *error)
67
- {
68
- if (!conn->handle || conn->closing || (conn->pool && !conn->pool->handle))
69
- return dpiError__set(error, "check connected", DPI_ERR_NOT_CONNECTED);
70
- return DPI_SUCCESS;
71
- }
72
-
73
-
74
- //-----------------------------------------------------------------------------
75
- // dpiConn__close() [INTERNAL]
76
- // Internal method used for closing the connection. Any transaction is rolled
77
- // back and any handles allocated are freed. For connections acquired from a
78
- // pool and that aren't marked as needed to be dropped, the last time used is
79
- // updated. This is called from dpiConn_close() where errors are expected to be
80
- // propagated and from dpiConn__free() where errors are ignored.
81
- //-----------------------------------------------------------------------------
82
- static int dpiConn__close(dpiConn *conn, uint32_t mode, const char *tag,
83
- uint32_t tagLength, int propagateErrors, dpiError *error)
84
- {
85
- int status, txnInProgress;
86
- uint32_t serverStatus, i;
87
- time_t *lastTimeUsed;
88
- dpiObject *obj;
89
- dpiStmt *stmt;
90
- dpiLob *lob;
91
-
92
- // rollback any outstanding transaction, if one is in progress; drop the
93
- // session if any errors take place
94
- txnInProgress = 0;
95
- if (!conn->deadSession && conn->sessionHandle) {
96
- txnInProgress = 1;
97
- if (conn->env->versionInfo->versionNum >= 12)
98
- dpiOci__attrGet(conn->sessionHandle, DPI_OCI_HTYPE_SESSION,
99
- &txnInProgress, NULL, DPI_OCI_ATTR_TRANSACTION_IN_PROGRESS,
100
- NULL, error);
101
- }
102
- if (txnInProgress &&
103
- dpiOci__transRollback(conn, propagateErrors, error) < 0)
104
- conn->deadSession = 1;
105
-
106
- // close all objects; note that no references are retained by the
107
- // handle list (otherwise all objects would be left until an explicit
108
- // close of the connection was made) so a reference needs to be acquired
109
- // first, as otherwise the object may be freed while the close is being
110
- // performed!
111
- if (conn->objects) {
112
- for (i = 0; i < conn->objects->numSlots; i++) {
113
- obj = (dpiObject*) conn->objects->handles[i];
114
- if (!obj)
115
- continue;
116
- if (conn->env->threaded) {
117
- dpiMutex__acquire(conn->env->mutex);
118
- status = dpiGen__checkHandle(obj, DPI_HTYPE_OBJECT, NULL,
119
- NULL);
120
- if (status == DPI_SUCCESS)
121
- obj->refCount += 1;
122
- dpiMutex__release(conn->env->mutex);
123
- if (status < 0)
124
- continue;
125
- }
126
- status = dpiObject__close(obj, propagateErrors, error);
127
- if (conn->env->threaded)
128
- dpiGen__setRefCount(obj, error, -1);
129
- if (status < 0)
130
- return DPI_FAILURE;
131
- }
132
- }
133
-
134
- // close all open statements; note that no references are retained by the
135
- // handle list (otherwise all statements would be left open until an
136
- // explicit close was made of either the statement or the connection) so
137
- // a reference needs to be acquired first, as otherwise the statement may
138
- // be freed while the close is being performed!
139
- if (conn->openStmts) {
140
- for (i = 0; i < conn->openStmts->numSlots; i++) {
141
- stmt = (dpiStmt*) conn->openStmts->handles[i];
142
- if (!stmt)
143
- continue;
144
- if (conn->env->threaded) {
145
- dpiMutex__acquire(conn->env->mutex);
146
- status = dpiGen__checkHandle(stmt, DPI_HTYPE_STMT, NULL, NULL);
147
- if (status == DPI_SUCCESS)
148
- stmt->refCount += 1;
149
- dpiMutex__release(conn->env->mutex);
150
- if (status < 0)
151
- continue;
152
- }
153
- status = dpiStmt__close(stmt, NULL, 0, propagateErrors, error);
154
- if (conn->env->threaded)
155
- dpiGen__setRefCount(stmt, error, -1);
156
- if (status < 0)
157
- return DPI_FAILURE;
158
- }
159
- }
160
-
161
- // close all open LOBs; the same comments apply as for statements
162
- if (conn->openLobs) {
163
- for (i = 0; i < conn->openLobs->numSlots; i++) {
164
- lob = (dpiLob*) conn->openLobs->handles[i];
165
- if (!lob)
166
- continue;
167
- if (conn->env->threaded) {
168
- dpiMutex__acquire(conn->env->mutex);
169
- status = dpiGen__checkHandle(lob, DPI_HTYPE_LOB, NULL, NULL);
170
- if (status == DPI_SUCCESS)
171
- lob->refCount += 1;
172
- dpiMutex__release(conn->env->mutex);
173
- if (status < 0)
174
- continue;
175
- }
176
- status = dpiLob__close(lob, propagateErrors, error);
177
- if (conn->env->threaded)
178
- dpiGen__setRefCount(lob, error, -1);
179
- if (status < 0)
180
- return DPI_FAILURE;
181
- }
182
- }
183
-
184
- // handle connections created with an external handle
185
- if (conn->externalHandle) {
186
- conn->sessionHandle = NULL;
187
-
188
- // handle standalone connections
189
- } else if (conn->standalone) {
190
-
191
- // end session and free session handle
192
- if (dpiOci__sessionEnd(conn, propagateErrors, error) < 0)
193
- return DPI_FAILURE;
194
- dpiOci__handleFree(conn->sessionHandle, DPI_OCI_HTYPE_SESSION);
195
- conn->sessionHandle = NULL;
196
-
197
- // detach from server and free server handle
198
- if (dpiOci__serverDetach(conn, propagateErrors, error) < 0)
199
- return DPI_FAILURE;
200
- dpiOci__handleFree(conn->serverHandle, DPI_OCI_HTYPE_SERVER);
201
-
202
- // free service context handle
203
- dpiOci__handleFree(conn->handle, DPI_OCI_HTYPE_SVCCTX);
204
-
205
- // handle pooled connections
206
- } else {
207
-
208
- // if the session isn't marked as needing to be dropped, update the
209
- // last time used (this is checked when the session is acquired)
210
- // NOTE: this is only needed for clients earlier than 12.2
211
- if (!conn->deadSession && conn->sessionHandle &&
212
- (conn->env->versionInfo->versionNum < 12 ||
213
- (conn->env->versionInfo->versionNum == 12 &&
214
- conn->env->versionInfo->releaseNum < 2))) {
215
-
216
- // get the pointer from the context
217
- lastTimeUsed = NULL;
218
- if (dpiOci__contextGetValue(conn, DPI_CONTEXT_LAST_TIME_USED,
219
- (uint32_t) (sizeof(DPI_CONTEXT_LAST_TIME_USED) - 1),
220
- (void**) &lastTimeUsed, propagateErrors, error) < 0)
221
- return DPI_FAILURE;
222
-
223
- // if no pointer available, allocate and set it
224
- if (!lastTimeUsed) {
225
- if (dpiOci__memoryAlloc(conn, (void**) &lastTimeUsed,
226
- sizeof(time_t), propagateErrors, error) < 0)
227
- return DPI_FAILURE;
228
- if (dpiOci__contextSetValue(conn, DPI_CONTEXT_LAST_TIME_USED,
229
- (uint32_t) (sizeof(DPI_CONTEXT_LAST_TIME_USED) - 1),
230
- lastTimeUsed, propagateErrors, error) < 0)
231
- dpiOci__memoryFree(conn, lastTimeUsed, error);
232
- }
233
-
234
- // set last time used
235
- if (lastTimeUsed)
236
- *lastTimeUsed = time(NULL);
237
-
238
- }
239
-
240
- // check server status; if not connected, ensure session is dropped
241
- if (conn->serverHandle) {
242
- if (dpiOci__attrGet(conn->serverHandle, DPI_OCI_HTYPE_SERVER,
243
- &serverStatus, NULL, DPI_OCI_ATTR_SERVER_STATUS,
244
- "get server status", error) < 0 ||
245
- serverStatus != DPI_OCI_SERVER_NORMAL)
246
- conn->deadSession = 1;
247
- }
248
-
249
- // release session
250
- if (conn->deadSession)
251
- mode |= DPI_OCI_SESSRLS_DROPSESS;
252
- if (dpiOci__sessionRelease(conn, tag, tagLength, mode, propagateErrors,
253
- error) < 0)
254
- return DPI_FAILURE;
255
- conn->sessionHandle = NULL;
256
-
257
- }
258
-
259
- conn->handle = NULL;
260
- conn->serverHandle = NULL;
261
- return DPI_SUCCESS;
262
- }
263
-
264
-
265
- //-----------------------------------------------------------------------------
266
- // dpiConn__create() [PRIVATE]
267
- // Perform internal initialization of the connection.
268
- //-----------------------------------------------------------------------------
269
- int dpiConn__create(dpiConn *conn, const dpiContext *context,
270
- const char *userName, uint32_t userNameLength, const char *password,
271
- uint32_t passwordLength, const char *connectString,
272
- uint32_t connectStringLength, dpiPool *pool,
273
- const dpiCommonCreateParams *commonParams,
274
- dpiConnCreateParams *createParams, dpiError *error)
275
- {
276
- // allocate handle lists for statements, LOBs and objects
277
- if (dpiHandleList__create(&conn->openStmts, error) < 0)
278
- return DPI_FAILURE;
279
- if (dpiHandleList__create(&conn->openLobs, error) < 0)
280
- return DPI_FAILURE;
281
- if (dpiHandleList__create(&conn->objects, error) < 0)
282
- return DPI_FAILURE;
283
-
284
- // initialize environment (for non-pooled connections)
285
- if (!pool && dpiEnv__init(conn->env, context, commonParams, error) < 0)
286
- return DPI_FAILURE;
287
-
288
- // if a handle is specified, use it
289
- if (createParams->externalHandle) {
290
- conn->handle = createParams->externalHandle;
291
- conn->externalHandle = 1;
292
- return dpiConn__getHandles(conn, error);
293
- }
294
-
295
- // connection class, sharding and the use of session pools require the use
296
- // of the OCISessionGet() method; all other cases use the OCISessionBegin()
297
- // method which is more capable
298
- if (pool || (createParams->connectionClass &&
299
- createParams->connectionClassLength > 0) ||
300
- createParams->shardingKeyColumns ||
301
- createParams->superShardingKeyColumns)
302
- return dpiConn__get(conn, userName, userNameLength, password,
303
- passwordLength, connectString, connectStringLength,
304
- createParams, pool, error);
305
- return dpiConn__createStandalone(conn, userName, userNameLength, password,
306
- passwordLength, connectString, connectStringLength, commonParams,
307
- createParams, error);
308
- }
309
-
310
-
311
- //-----------------------------------------------------------------------------
312
- // dpiConn__createStandalone() [PRIVATE]
313
- // Create a standalone connection to the database using the parameters
314
- // specified.
315
- //-----------------------------------------------------------------------------
316
- static int dpiConn__createStandalone(dpiConn *conn, const char *userName,
317
- uint32_t userNameLength, const char *password, uint32_t passwordLength,
318
- const char *connectString, uint32_t connectStringLength,
319
- const dpiCommonCreateParams *commonParams,
320
- const dpiConnCreateParams *createParams, dpiError *error)
321
- {
322
- uint32_t credentialType, authMode;
323
-
324
- // mark the connection as a standalone connection
325
- conn->standalone = 1;
326
-
327
- // allocate the server handle
328
- if (dpiOci__handleAlloc(conn->env->handle, &conn->serverHandle,
329
- DPI_OCI_HTYPE_SERVER, "allocate server handle", error) < 0)
330
- return DPI_FAILURE;
331
-
332
- // attach to the server
333
- if (dpiOci__serverAttach(conn, connectString, connectStringLength,
334
- error) < 0)
335
- return DPI_FAILURE;
336
-
337
- // allocate the service context handle
338
- if (dpiOci__handleAlloc(conn->env->handle, &conn->handle,
339
- DPI_OCI_HTYPE_SVCCTX, "allocate service context handle",
340
- error) < 0)
341
- return DPI_FAILURE;
342
-
343
- // set attribute for server handle
344
- if (dpiOci__attrSet(conn->handle, DPI_OCI_HTYPE_SVCCTX, conn->serverHandle,
345
- 0, DPI_OCI_ATTR_SERVER, "set server handle", error) < 0)
346
- return DPI_FAILURE;
347
-
348
- // allocate the session handle
349
- if (dpiOci__handleAlloc(conn->env->handle, &conn->sessionHandle,
350
- DPI_OCI_HTYPE_SESSION, "allocate session handle", error) < 0)
351
- return DPI_FAILURE;
352
-
353
- // driver name and edition are only relevant for standalone connections
354
- if (dpiUtils__setAttributesFromCommonCreateParams(conn->sessionHandle,
355
- DPI_OCI_HTYPE_SESSION, commonParams, error) < 0)
356
- return DPI_FAILURE;
357
-
358
- // populate attributes on the session handle
359
- if (dpiConn__setAttributesFromCreateParams(conn, conn->sessionHandle,
360
- DPI_OCI_HTYPE_SESSION, userName, userNameLength, password,
361
- passwordLength, createParams, NULL, NULL, error) < 0)
362
- return DPI_FAILURE;
363
-
364
- // set the session handle on the service context handle
365
- if (dpiOci__attrSet(conn->handle, DPI_OCI_HTYPE_SVCCTX,
366
- conn->sessionHandle, 0, DPI_OCI_ATTR_SESSION, "set session handle",
367
- error) < 0)
368
- return DPI_FAILURE;
369
-
370
- // if a new password is specified, change it (this also creates the session
371
- // so a call to OCISessionBegin() is not needed)
372
- if (createParams->newPassword && createParams->newPasswordLength > 0) {
373
- authMode = DPI_OCI_AUTH;
374
- if (createParams->authMode & DPI_MODE_AUTH_SYSDBA)
375
- authMode |= DPI_OCI_CPW_SYSDBA;
376
- if (createParams->authMode & DPI_MODE_AUTH_SYSOPER)
377
- authMode |= DPI_OCI_CPW_SYSOPER;
378
- if (createParams->authMode & DPI_MODE_AUTH_SYSASM)
379
- authMode |= DPI_OCI_CPW_SYSASM;
380
- if (createParams->authMode & DPI_MODE_AUTH_SYSBKP)
381
- authMode |= DPI_OCI_CPW_SYSBKP;
382
- if (createParams->authMode & DPI_MODE_AUTH_SYSDGD)
383
- authMode |= DPI_OCI_CPW_SYSDGD;
384
- if (createParams->authMode & DPI_MODE_AUTH_SYSKMT)
385
- authMode |= DPI_OCI_CPW_SYSKMT;
386
- return dpiOci__passwordChange(conn, userName, userNameLength, password,
387
- passwordLength, createParams->newPassword,
388
- createParams->newPasswordLength, authMode, error);
389
- }
390
-
391
- // begin the session
392
- credentialType = (createParams->externalAuth) ? DPI_OCI_CRED_EXT :
393
- DPI_OCI_CRED_RDBMS;
394
- authMode = createParams->authMode | DPI_OCI_STMT_CACHE;
395
- if (dpiOci__sessionBegin(conn, credentialType, authMode, error) < 0)
396
- return DPI_FAILURE;
397
- return dpiConn__getServerCharset(conn, error);
398
- }
399
-
400
-
401
- //-----------------------------------------------------------------------------
402
- // dpiConn__free() [INTERNAL]
403
- // Free the memory and any resources associated with the connection.
404
- //-----------------------------------------------------------------------------
405
- void dpiConn__free(dpiConn *conn, dpiError *error)
406
- {
407
- if (conn->handle)
408
- dpiConn__close(conn, DPI_MODE_CONN_CLOSE_DEFAULT, NULL, 0, 0,
409
- error);
410
- if (conn->pool) {
411
- dpiGen__setRefCount(conn->pool, error, -1);
412
- conn->pool = NULL;
413
- conn->env = NULL;
414
- }
415
- if (conn->env) {
416
- dpiEnv__free(conn->env, error);
417
- conn->env = NULL;
418
- }
419
- if (conn->releaseString) {
420
- dpiUtils__freeMemory((void*) conn->releaseString);
421
- conn->releaseString = NULL;
422
- }
423
- if (conn->openStmts) {
424
- dpiHandleList__free(conn->openStmts);
425
- conn->openStmts = NULL;
426
- }
427
- if (conn->openLobs) {
428
- dpiHandleList__free(conn->openLobs);
429
- conn->openLobs = NULL;
430
- }
431
- if (conn->objects) {
432
- dpiHandleList__free(conn->objects);
433
- conn->objects = NULL;
434
- }
435
- dpiUtils__freeMemory(conn);
436
- }
437
-
438
-
439
- //-----------------------------------------------------------------------------
440
- // dpiConn__get() [INTERNAL]
441
- // Create a connection to the database using the parameters specified. This
442
- // method uses the simplified OCI session creation protocol which is required
443
- // when using pools and session tagging.
444
- //-----------------------------------------------------------------------------
445
- static int dpiConn__get(dpiConn *conn, const char *userName,
446
- uint32_t userNameLength, const char *password, uint32_t passwordLength,
447
- const char *connectString, uint32_t connectStringLength,
448
- dpiConnCreateParams *createParams, dpiPool *pool, dpiError *error)
449
- {
450
- void *shardingKey = NULL, *superShardingKey = NULL;
451
- int externalAuth, status;
452
- void *authInfo;
453
- uint32_t mode;
454
-
455
- // set things up for the call to acquire a session
456
- if (pool) {
457
- dpiGen__setRefCount(pool, error, 1);
458
- conn->pool = pool;
459
- mode = DPI_OCI_SESSGET_SPOOL;
460
- externalAuth = pool->externalAuth;
461
- if (userName && pool->homogeneous)
462
- return dpiError__set(error, "check proxy", DPI_ERR_INVALID_PROXY);
463
-
464
- // if the userName is provided but no password is provided and external
465
- // authentication is not being used, proxy authentication is taking
466
- // place
467
- if (userName && !password && !externalAuth)
468
- mode |= DPI_OCI_SESSGET_CREDPROXY;
469
- if (createParams->matchAnyTag)
470
- mode |= DPI_OCI_SESSGET_SPOOL_MATCHANY;
471
- } else {
472
- mode = DPI_OCI_SESSGET_STMTCACHE;
473
- externalAuth = createParams->externalAuth;
474
- }
475
- if (createParams->authMode & DPI_MODE_AUTH_SYSDBA)
476
- mode |= DPI_OCI_SESSGET_SYSDBA;
477
- if (externalAuth)
478
- mode |= DPI_OCI_SESSGET_CREDEXT;
479
-
480
- // create authorization handle
481
- if (dpiOci__handleAlloc(conn->env->handle, &authInfo,
482
- DPI_OCI_HTYPE_AUTHINFO, "allocate authinfo handle", error) < 0)
483
- return DPI_FAILURE;
484
-
485
- // set attributes for create parameters
486
- if (dpiConn__setAttributesFromCreateParams(conn, authInfo,
487
- DPI_OCI_HTYPE_AUTHINFO, userName, userNameLength, password,
488
- passwordLength, createParams, &shardingKey, &superShardingKey,
489
- error) < 0) {
490
- dpiOci__handleFree(authInfo, DPI_OCI_HTYPE_AUTHINFO);
491
- return DPI_FAILURE;
492
- }
493
-
494
- // get a session from the pool
495
- status = dpiConn__getSession(conn, mode, connectString,
496
- connectStringLength, createParams, authInfo, error);
497
- if (status == DPI_SUCCESS && pool) {
498
- if (shardingKey)
499
- dpiOci__descriptorFree(shardingKey, DPI_OCI_DTYPE_SHARDING_KEY);
500
- if (superShardingKey)
501
- dpiOci__descriptorFree(superShardingKey,
502
- DPI_OCI_DTYPE_SHARDING_KEY);
503
- }
504
- dpiOci__handleFree(authInfo, DPI_OCI_HTYPE_AUTHINFO);
505
- if (status < 0)
506
- return status;
507
- return dpiConn__getServerCharset(conn, error);
508
- }
509
-
510
-
511
- //-----------------------------------------------------------------------------
512
- // dpiConn__getAttributeText() [INTERNAL]
513
- // Get the value of the OCI attribute from a text string.
514
- //-----------------------------------------------------------------------------
515
- static int dpiConn__getAttributeText(dpiConn *conn, uint32_t attribute,
516
- const char **value, uint32_t *valueLength, const char *fnName)
517
- {
518
- dpiError error;
519
- int status;
520
-
521
- // validate parameters
522
- if (dpiConn__check(conn, fnName, &error) < 0)
523
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
524
- DPI_CHECK_PTR_NOT_NULL(conn, value)
525
- DPI_CHECK_PTR_NOT_NULL(conn, valueLength)
526
-
527
- // determine pointer to pass (OCI uses different sizes)
528
- switch (attribute) {
529
- case DPI_OCI_ATTR_CURRENT_SCHEMA:
530
- case DPI_OCI_ATTR_LTXID:
531
- case DPI_OCI_ATTR_EDITION:
532
- status = dpiOci__attrGet(conn->sessionHandle,
533
- DPI_OCI_HTYPE_SESSION, (void*) value, valueLength,
534
- attribute, "get session value", &error);
535
- break;
536
- case DPI_OCI_ATTR_INTERNAL_NAME:
537
- case DPI_OCI_ATTR_EXTERNAL_NAME:
538
- status = dpiOci__attrGet(conn->serverHandle, DPI_OCI_HTYPE_SERVER,
539
- (void*) value, valueLength, attribute, "get server value",
540
- &error);
541
- break;
542
- default:
543
- status = dpiError__set(&error, "get attribute text",
544
- DPI_ERR_NOT_SUPPORTED);
545
- break;
546
- }
547
-
548
- return dpiGen__endPublicFn(conn, status, &error);
549
- }
550
-
551
-
552
- //-----------------------------------------------------------------------------
553
- // dpiConn__getHandles() [INTERNAL]
554
- // Get the server and session handle from the service context handle.
555
- //-----------------------------------------------------------------------------
556
- static int dpiConn__getHandles(dpiConn *conn, dpiError *error)
557
- {
558
- if (dpiOci__attrGet(conn->handle, DPI_OCI_HTYPE_SVCCTX,
559
- (void*) &conn->sessionHandle, NULL, DPI_OCI_ATTR_SESSION,
560
- "get session handle", error) < 0)
561
- return DPI_FAILURE;
562
- if (dpiOci__attrGet(conn->handle, DPI_OCI_HTYPE_SVCCTX,
563
- (void*) &conn->serverHandle, NULL, DPI_OCI_ATTR_SERVER,
564
- "get server handle", error) < 0)
565
- return DPI_FAILURE;
566
-
567
- return DPI_SUCCESS;
568
- }
569
-
570
-
571
- //-----------------------------------------------------------------------------
572
- // dpiConn__getServerCharset() [INTERNAL]
573
- // Internal method used for retrieving the server character set. This is used
574
- // to determine if any conversion is required when transferring strings between
575
- // the client and the server.
576
- //-----------------------------------------------------------------------------
577
- static int dpiConn__getServerCharset(dpiConn *conn, dpiError *error)
578
- {
579
- return dpiOci__attrGet(conn->serverHandle, DPI_OCI_HTYPE_SERVER,
580
- &conn->charsetId, NULL, DPI_OCI_ATTR_CHARSET_ID,
581
- "get server charset id", error);
582
- }
583
-
584
-
585
- //-----------------------------------------------------------------------------
586
- // dpiConn__getServerVersion() [INTERNAL]
587
- // Internal method used for ensuring that the server version has been cached
588
- // on the connection.
589
- //-----------------------------------------------------------------------------
590
- int dpiConn__getServerVersion(dpiConn *conn, dpiError *error)
591
- {
592
- uint32_t serverRelease;
593
- char buffer[512];
594
-
595
- // nothing to do if the server version has been determined earlier
596
- if (conn->releaseString)
597
- return DPI_SUCCESS;
598
-
599
- // get server version
600
- if (dpiOci__serverRelease(conn, buffer, sizeof(buffer), &serverRelease,
601
- error) < 0)
602
- return DPI_FAILURE;
603
- conn->releaseStringLength = (uint32_t) strlen(buffer);
604
- if (dpiUtils__allocateMemory(1, conn->releaseStringLength, 0,
605
- "allocate release string", (void**) &conn->releaseString,
606
- error) < 0)
607
- return DPI_FAILURE;
608
- strncpy( (char*) conn->releaseString, buffer, conn->releaseStringLength);
609
- conn->versionInfo.versionNum = (int)((serverRelease >> 24) & 0xFF);
610
- if (conn->versionInfo.versionNum >= 18) {
611
- conn->versionInfo.releaseNum = (int)((serverRelease >> 16) & 0xFF);
612
- conn->versionInfo.updateNum = (int)((serverRelease >> 12) & 0x0F);
613
- conn->versionInfo.portReleaseNum = (int)((serverRelease >> 4) & 0xFF);
614
- conn->versionInfo.portUpdateNum = (int)((serverRelease) & 0xF);
615
- } else {
616
- conn->versionInfo.releaseNum = (int)((serverRelease >> 20) & 0x0F);
617
- conn->versionInfo.updateNum = (int)((serverRelease >> 12) & 0xFF);
618
- conn->versionInfo.portReleaseNum = (int)((serverRelease >> 8) & 0x0F);
619
- conn->versionInfo.portUpdateNum = (int)((serverRelease) & 0xFF);
620
- }
621
- conn->versionInfo.fullVersionNum = (uint32_t)
622
- DPI_ORACLE_VERSION_TO_NUMBER(conn->versionInfo.versionNum,
623
- conn->versionInfo.releaseNum,
624
- conn->versionInfo.updateNum,
625
- conn->versionInfo.portReleaseNum,
626
- conn->versionInfo.portUpdateNum);
627
-
628
- return DPI_SUCCESS;
629
- }
630
-
631
-
632
- //-----------------------------------------------------------------------------
633
- // dpiConn__getSession() [INTERNAL]
634
- // Ping and loop until we get a good session. When a database instance goes
635
- // down, it can leave several bad connections that need to be flushed out
636
- // before a good connection can be acquired. If the connection is brand new
637
- // (ping time context value has not been set) there is no need to do a ping.
638
- // This also ensures that the loop cannot run forever!
639
- //-----------------------------------------------------------------------------
640
- static int dpiConn__getSession(dpiConn *conn, uint32_t mode,
641
- const char *connectString, uint32_t connectStringLength,
642
- dpiConnCreateParams *params, void *authInfo, dpiError *error)
643
- {
644
- uint8_t savedBreakOnTimeout, breakOnTimeout;
645
- uint32_t savedTimeout;
646
- time_t *lastTimeUsed;
647
-
648
- while (1) {
649
-
650
- // acquire the new session
651
- if (dpiOci__sessionGet(conn->env->handle, &conn->handle, authInfo,
652
- connectString, connectStringLength, params->tag,
653
- params->tagLength, &params->outTag, &params->outTagLength,
654
- &params->outTagFound, mode, error) < 0)
655
- return DPI_FAILURE;
656
-
657
- // get session and server handles
658
- if (dpiConn__getHandles(conn, error) < 0)
659
- return DPI_FAILURE;
660
-
661
- // get last time used from session context
662
- lastTimeUsed = NULL;
663
- if (dpiOci__contextGetValue(conn, DPI_CONTEXT_LAST_TIME_USED,
664
- (uint32_t) (sizeof(DPI_CONTEXT_LAST_TIME_USED) - 1),
665
- (void**) &lastTimeUsed, 1, error) < 0)
666
- return DPI_FAILURE;
667
-
668
- // if value is not found, a new connection has been created and there
669
- // is no need to perform a ping; nor if we are creating a standalone
670
- // connection
671
- if (!lastTimeUsed || !conn->pool)
672
- break;
673
-
674
- // if ping interval is negative or the ping interval (in seconds)
675
- // has not been exceeded yet, there is also no need to perform a ping
676
- if (conn->pool->pingInterval < 0 ||
677
- *lastTimeUsed + conn->pool->pingInterval > time(NULL))
678
- break;
679
-
680
- // ping needs to be done at this point; set parameters to ensure that
681
- // the ping does not take too long to complete; keep original values
682
- dpiOci__attrGet(conn->serverHandle,
683
- DPI_OCI_HTYPE_SERVER, &savedTimeout, NULL,
684
- DPI_OCI_ATTR_RECEIVE_TIMEOUT, NULL, error);
685
- dpiOci__attrSet(conn->serverHandle, DPI_OCI_HTYPE_SERVER,
686
- &conn->pool->pingTimeout, 0, DPI_OCI_ATTR_RECEIVE_TIMEOUT,
687
- NULL, error);
688
- if (conn->env->versionInfo->versionNum >= 12) {
689
- dpiOci__attrGet(conn->serverHandle,
690
- DPI_OCI_HTYPE_SERVER, &savedBreakOnTimeout, NULL,
691
- DPI_OCI_ATTR_BREAK_ON_NET_TIMEOUT, NULL, error);
692
- breakOnTimeout = 0;
693
- dpiOci__attrSet(conn->serverHandle, DPI_OCI_HTYPE_SERVER,
694
- &breakOnTimeout, 0, DPI_OCI_ATTR_BREAK_ON_NET_TIMEOUT,
695
- NULL, error);
696
- }
697
-
698
- // if ping is successful, the connection is valid and can be returned
699
- // restore original network parameters
700
- if (dpiOci__ping(conn, error) == 0) {
701
- dpiOci__attrSet(conn->serverHandle, DPI_OCI_HTYPE_SERVER,
702
- &savedTimeout, 0, DPI_OCI_ATTR_RECEIVE_TIMEOUT, NULL,
703
- error);
704
- if (conn->env->versionInfo->versionNum >= 12)
705
- dpiOci__attrSet(conn->serverHandle, DPI_OCI_HTYPE_SERVER,
706
- &savedBreakOnTimeout, 0,
707
- DPI_OCI_ATTR_BREAK_ON_NET_TIMEOUT, NULL, error);
708
- break;
709
- }
710
-
711
- // session is bad, need to release and drop it
712
- dpiOci__sessionRelease(conn, NULL, 0, DPI_OCI_SESSRLS_DROPSESS, 0,
713
- error);
714
- conn->handle = NULL;
715
- conn->serverHandle = NULL;
716
- conn->sessionHandle = NULL;
717
-
718
- }
719
-
720
- return DPI_SUCCESS;
721
- }
722
-
723
-
724
- //-----------------------------------------------------------------------------
725
- // dpiConn__setAppContext() [INTERNAL]
726
- // Populate the session handle with the application context.
727
- //-----------------------------------------------------------------------------
728
- static int dpiConn__setAppContext(void *handle, uint32_t handleType,
729
- const dpiConnCreateParams *params, dpiError *error)
730
- {
731
- void *listHandle, *entryHandle;
732
- dpiAppContext *entry;
733
- uint32_t i;
734
-
735
- // set the number of application context entries
736
- if (dpiOci__attrSet(handle, handleType, (void*) &params->numAppContext,
737
- sizeof(params->numAppContext), DPI_OCI_ATTR_APPCTX_SIZE,
738
- "set app context size", error) < 0)
739
- return DPI_FAILURE;
740
-
741
- // get the application context list handle
742
- if (dpiOci__attrGet(handle, handleType, &listHandle, NULL,
743
- DPI_OCI_ATTR_APPCTX_LIST, "get context list handle", error) < 0)
744
- return DPI_FAILURE;
745
-
746
- // set each application context entry
747
- for (i = 0; i < params->numAppContext; i++) {
748
- entry = &params->appContext[i];
749
-
750
- // retrieve the context element descriptor
751
- if (dpiOci__paramGet(listHandle, DPI_OCI_DTYPE_PARAM,
752
- &entryHandle, i + 1, "get context entry handle", error) < 0)
753
- return DPI_FAILURE;
754
-
755
- // set the namespace name
756
- if (dpiOci__attrSet(entryHandle, DPI_OCI_DTYPE_PARAM,
757
- (void*) entry->namespaceName, entry->namespaceNameLength,
758
- DPI_OCI_ATTR_APPCTX_NAME, "set namespace name", error) < 0)
759
- return DPI_FAILURE;
760
-
761
- // set the name
762
- if (dpiOci__attrSet(entryHandle, DPI_OCI_DTYPE_PARAM,
763
- (void*) entry->name, entry->nameLength,
764
- DPI_OCI_ATTR_APPCTX_ATTR, "set name", error) < 0)
765
- return DPI_FAILURE;
766
-
767
- // set the value
768
- if (dpiOci__attrSet(entryHandle, DPI_OCI_DTYPE_PARAM,
769
- (void*) entry->value, entry->valueLength,
770
- DPI_OCI_ATTR_APPCTX_VALUE, "set value", error) < 0)
771
- return DPI_FAILURE;
772
-
773
- }
774
-
775
- return DPI_SUCCESS;
776
- }
777
-
778
-
779
- //-----------------------------------------------------------------------------
780
- // dpiConn__setAttributesFromCreateParams() [INTERNAL]
781
- // Populate the authorization info structure or session handle using the
782
- // create parameters specified.
783
- //-----------------------------------------------------------------------------
784
- static int dpiConn__setAttributesFromCreateParams(dpiConn *conn, void *handle,
785
- uint32_t handleType, const char *userName, uint32_t userNameLength,
786
- const char *password, uint32_t passwordLength,
787
- const dpiConnCreateParams *params, void **shardingKey,
788
- void **superShardingKey, dpiError *error)
789
- {
790
- uint32_t purity;
791
-
792
- // set credentials
793
- if (userName && userNameLength > 0 && dpiOci__attrSet(handle,
794
- handleType, (void*) userName, userNameLength,
795
- DPI_OCI_ATTR_USERNAME, "set user name", error) < 0)
796
- return DPI_FAILURE;
797
- if (password && passwordLength > 0 && dpiOci__attrSet(handle,
798
- handleType, (void*) password, passwordLength,
799
- DPI_OCI_ATTR_PASSWORD, "set password", error) < 0)
800
- return DPI_FAILURE;
801
-
802
- // set connection class and purity parameters
803
- if (params->connectionClass && params->connectionClassLength > 0 &&
804
- dpiOci__attrSet(handle, handleType,
805
- (void*) params->connectionClass,
806
- params->connectionClassLength,
807
- DPI_OCI_ATTR_CONNECTION_CLASS, "set connection class",
808
- error) < 0)
809
- return DPI_FAILURE;
810
- if (params->purity != DPI_OCI_ATTR_PURITY_DEFAULT) {
811
- purity = params->purity;
812
- if (dpiOci__attrSet(handle, handleType, &purity,
813
- sizeof(purity), DPI_OCI_ATTR_PURITY, "set purity", error) < 0)
814
- return DPI_FAILURE;
815
- }
816
-
817
- // set sharding key and super sharding key parameters
818
- if (params->shardingKeyColumns && params->numShardingKeyColumns > 0) {
819
- if (dpiConn__setShardingKey(conn, shardingKey, handle, handleType,
820
- DPI_OCI_ATTR_SHARDING_KEY, "set sharding key",
821
- params->shardingKeyColumns, params->numShardingKeyColumns,
822
- error) < 0)
823
- return DPI_FAILURE;
824
- }
825
- if (params->superShardingKeyColumns &&
826
- params->numSuperShardingKeyColumns > 0) {
827
- if (dpiConn__setShardingKey(conn, superShardingKey, handle, handleType,
828
- DPI_OCI_ATTR_SUPER_SHARDING_KEY, "set super sharding key",
829
- params->superShardingKeyColumns,
830
- params->numSuperShardingKeyColumns, error) < 0)
831
- return DPI_FAILURE;
832
- }
833
-
834
- // set application context, if applicable
835
- if (handleType == DPI_OCI_HTYPE_SESSION && params->numAppContext > 0)
836
- return dpiConn__setAppContext(handle, handleType, params, error);
837
-
838
- return DPI_SUCCESS;
839
- }
840
-
841
-
842
- //-----------------------------------------------------------------------------
843
- // dpiConn__setAttributeText() [INTERNAL]
844
- // Set the value of the OCI attribute from a text string.
845
- //-----------------------------------------------------------------------------
846
- static int dpiConn__setAttributeText(dpiConn *conn, uint32_t attribute,
847
- const char *value, uint32_t valueLength, const char *fnName)
848
- {
849
- dpiError error;
850
- int status;
851
-
852
- // validate parameters
853
- if (dpiConn__check(conn, fnName, &error) < 0)
854
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
855
- DPI_CHECK_PTR_AND_LENGTH(conn, value)
856
-
857
- // determine pointer to pass (OCI uses different sizes)
858
- switch (attribute) {
859
- case DPI_OCI_ATTR_ACTION:
860
- case DPI_OCI_ATTR_CLIENT_IDENTIFIER:
861
- case DPI_OCI_ATTR_CLIENT_INFO:
862
- case DPI_OCI_ATTR_CURRENT_SCHEMA:
863
- case DPI_OCI_ATTR_EDITION:
864
- case DPI_OCI_ATTR_MODULE:
865
- case DPI_OCI_ATTR_DBOP:
866
- status = dpiOci__attrSet(conn->sessionHandle,
867
- DPI_OCI_HTYPE_SESSION, (void*) value, valueLength,
868
- attribute, "set session value", &error);
869
- break;
870
- case DPI_OCI_ATTR_INTERNAL_NAME:
871
- case DPI_OCI_ATTR_EXTERNAL_NAME:
872
- status = dpiOci__attrSet(conn->serverHandle, DPI_OCI_HTYPE_SERVER,
873
- (void*) value, valueLength, attribute, "set server value",
874
- &error);
875
- break;
876
- default:
877
- status = dpiError__set(&error, "set attribute text",
878
- DPI_ERR_NOT_SUPPORTED);
879
- break;
880
- }
881
-
882
- return dpiGen__endPublicFn(conn, status, &error);
883
- }
884
-
885
-
886
- //-----------------------------------------------------------------------------
887
- // dpiConn__setShardingKey() [INTERNAL]
888
- // Using the specified columns, create a sharding key and set it on the given
889
- // handle.
890
- //-----------------------------------------------------------------------------
891
- static int dpiConn__setShardingKey(dpiConn *conn, void **shardingKey,
892
- void *handle, uint32_t handleType, uint32_t attribute,
893
- const char *action, dpiShardingKeyColumn *columns, uint8_t numColumns,
894
- dpiError *error)
895
- {
896
- uint8_t i;
897
-
898
- // this is only supported on 12.2 and higher clients
899
- if (dpiUtils__checkClientVersion(conn->env->versionInfo, 12, 2,
900
- error) < 0)
901
- return DPI_FAILURE;
902
-
903
- // create sharding key descriptor, if necessary
904
- if (dpiOci__descriptorAlloc(conn->env->handle, shardingKey,
905
- DPI_OCI_DTYPE_SHARDING_KEY, "allocate sharding key", error) < 0)
906
- return DPI_FAILURE;
907
-
908
- // add each column to the sharding key
909
- for (i = 0; i < numColumns; i++) {
910
- if (dpiConn__setShardingKeyValue(conn, *shardingKey, &columns[i],
911
- error) < 0)
912
- return DPI_FAILURE;
913
- }
914
-
915
- // add the sharding key to the handle
916
- if (dpiOci__attrSet(handle, handleType, *shardingKey, 0, attribute, action,
917
- error) < 0)
918
- return DPI_FAILURE;
919
-
920
- return DPI_SUCCESS;
921
- }
922
-
923
-
924
- //-----------------------------------------------------------------------------
925
- // dpiConn__setShardingKeyValue() [INTERNAL]
926
- // Using the specified columns, create a sharding key and set it on the given
927
- // handle.
928
- //-----------------------------------------------------------------------------
929
- static int dpiConn__setShardingKeyValue(dpiConn *conn, void *shardingKey,
930
- dpiShardingKeyColumn *column, dpiError *error)
931
- {
932
- const dpiOracleType *oracleType;
933
- dpiOciNumber numberValue;
934
- dpiOciDate dateValue;
935
- uint32_t colLen = 0;
936
- void *col = NULL;
937
- uint16_t colType;
938
- int convertOk;
939
-
940
- oracleType = dpiOracleType__getFromNum(column->oracleTypeNum, error);
941
- if (!oracleType)
942
- return DPI_FAILURE;
943
- convertOk = 0;
944
- colType = oracleType->oracleType;
945
- switch (column->oracleTypeNum) {
946
- case DPI_ORACLE_TYPE_VARCHAR:
947
- case DPI_ORACLE_TYPE_CHAR:
948
- case DPI_ORACLE_TYPE_RAW:
949
- if (column->nativeTypeNum == DPI_NATIVE_TYPE_BYTES) {
950
- col = column->value.asBytes.ptr;
951
- colLen = column->value.asBytes.length;
952
- convertOk = 1;
953
- }
954
- break;
955
- case DPI_ORACLE_TYPE_NUMBER:
956
- col = &numberValue;
957
- colLen = sizeof(numberValue);
958
- if (column->nativeTypeNum == DPI_NATIVE_TYPE_DOUBLE) {
959
- if (dpiDataBuffer__toOracleNumberFromDouble(&column->value,
960
- error, &numberValue) < 0)
961
- return DPI_FAILURE;
962
- convertOk = 1;
963
- } else if (column->nativeTypeNum == DPI_NATIVE_TYPE_INT64) {
964
- if (dpiDataBuffer__toOracleNumberFromInteger(&column->value,
965
- error, &numberValue) < 0)
966
- return DPI_FAILURE;
967
- convertOk = 1;
968
- } else if (column->nativeTypeNum == DPI_NATIVE_TYPE_UINT64) {
969
- if (dpiDataBuffer__toOracleNumberFromUnsignedInteger(
970
- &column->value, error, &numberValue) < 0)
971
- return DPI_FAILURE;
972
- convertOk = 1;
973
- } else if (column->nativeTypeNum == DPI_NATIVE_TYPE_BYTES) {
974
- if (dpiDataBuffer__toOracleNumberFromText(&column->value,
975
- conn->env, error, &numberValue) < 0)
976
- return DPI_FAILURE;
977
- convertOk = 1;
978
- }
979
- break;
980
- case DPI_ORACLE_TYPE_DATE:
981
- col = &dateValue;
982
- colLen = sizeof(dateValue);
983
- colType = DPI_SQLT_DAT;
984
- if (column->nativeTypeNum == DPI_NATIVE_TYPE_TIMESTAMP) {
985
- if (dpiDataBuffer__toOracleDate(&column->value,
986
- &dateValue) < 0)
987
- return DPI_FAILURE;
988
- convertOk = 1;
989
- }
990
- break;
991
- default:
992
- break;
993
- }
994
- if (!convertOk)
995
- return dpiError__set(error, "check type", DPI_ERR_NOT_SUPPORTED);
996
-
997
- return dpiOci__shardingKeyColumnAdd(shardingKey, col, colLen, colType,
998
- error);
999
- }
1000
-
1001
-
1002
- //-----------------------------------------------------------------------------
1003
- // dpiConn_addRef() [PUBLIC]
1004
- // Add a reference to the connection.
1005
- //-----------------------------------------------------------------------------
1006
- int dpiConn_addRef(dpiConn *conn)
1007
- {
1008
- return dpiGen__addRef(conn, DPI_HTYPE_CONN, __func__);
1009
- }
1010
-
1011
-
1012
- //-----------------------------------------------------------------------------
1013
- // dpiConn_beginDistribTrans() [PUBLIC]
1014
- // Begin a distributed transaction.
1015
- //-----------------------------------------------------------------------------
1016
- int dpiConn_beginDistribTrans(dpiConn *conn, long formatId,
1017
- const char *transactionId, uint32_t transactionIdLength,
1018
- const char *branchId, uint32_t branchIdLength)
1019
- {
1020
- void *transactionHandle;
1021
- dpiError error;
1022
- dpiOciXID xid;
1023
- int status;
1024
-
1025
- // validate parameters
1026
- if (dpiConn__check(conn, __func__, &error) < 0)
1027
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1028
- DPI_CHECK_PTR_AND_LENGTH(conn, transactionId)
1029
- DPI_CHECK_PTR_AND_LENGTH(conn, branchId)
1030
- if (transactionIdLength > DPI_XA_MAXGTRIDSIZE) {
1031
- dpiError__set(&error, "check size of transaction id",
1032
- DPI_ERR_TRANS_ID_TOO_LARGE, transactionIdLength,
1033
- DPI_XA_MAXGTRIDSIZE);
1034
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1035
- }
1036
- if (branchIdLength > DPI_XA_MAXBQUALSIZE) {
1037
- dpiError__set(&error, "check size of branch id",
1038
- DPI_ERR_BRANCH_ID_TOO_LARGE, branchIdLength,
1039
- DPI_XA_MAXBQUALSIZE);
1040
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1041
- }
1042
-
1043
- // determine if a transaction handle was previously allocated
1044
- if (dpiOci__attrGet(conn->handle, DPI_OCI_HTYPE_SVCCTX,
1045
- (void*) &transactionHandle, NULL, DPI_OCI_ATTR_TRANS,
1046
- "get transaction handle", &error) < 0)
1047
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1048
-
1049
- // if one was not found, create one and associate it with the connection
1050
- if (!transactionHandle) {
1051
-
1052
- // create new handle
1053
- if (dpiOci__handleAlloc(conn->env->handle, &transactionHandle,
1054
- DPI_OCI_HTYPE_TRANS, "create transaction handle", &error) < 0)
1055
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1056
-
1057
- // associate the transaction with the connection
1058
- if (dpiOci__attrSet(conn->handle, DPI_OCI_HTYPE_SVCCTX,
1059
- transactionHandle, 0, DPI_OCI_ATTR_TRANS,
1060
- "associate transaction", &error) < 0) {
1061
- dpiOci__handleFree(transactionHandle, DPI_OCI_HTYPE_TRANS);
1062
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1063
- }
1064
-
1065
- }
1066
-
1067
- // set the XID for the transaction, if applicable
1068
- if (formatId != -1) {
1069
- xid.formatID = formatId;
1070
- xid.gtrid_length = transactionIdLength;
1071
- xid.bqual_length = branchIdLength;
1072
- if (transactionIdLength > 0)
1073
- strncpy(xid.data, transactionId, transactionIdLength);
1074
- if (branchIdLength > 0)
1075
- strncpy(&xid.data[transactionIdLength], branchId, branchIdLength);
1076
- if (dpiOci__attrSet(transactionHandle, DPI_OCI_HTYPE_TRANS, &xid,
1077
- sizeof(dpiOciXID), DPI_OCI_ATTR_XID, "set XID", &error) < 0)
1078
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1079
- }
1080
-
1081
- // start the transaction
1082
- status = dpiOci__transStart(conn, &error);
1083
- return dpiGen__endPublicFn(conn, status, &error);
1084
- }
1085
-
1086
-
1087
- //-----------------------------------------------------------------------------
1088
- // dpiConn_breakExecution() [PUBLIC]
1089
- // Break (interrupt) the currently executing operation.
1090
- //-----------------------------------------------------------------------------
1091
- int dpiConn_breakExecution(dpiConn *conn)
1092
- {
1093
- dpiError error;
1094
- int status;
1095
-
1096
- if (dpiConn__check(conn, __func__, &error) < 0)
1097
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1098
- status = dpiOci__break(conn, &error);
1099
- return dpiGen__endPublicFn(conn, status, &error);
1100
- }
1101
-
1102
-
1103
- //-----------------------------------------------------------------------------
1104
- // dpiConn_changePassword() [PUBLIC]
1105
- // Change the password for the specified user.
1106
- //-----------------------------------------------------------------------------
1107
- int dpiConn_changePassword(dpiConn *conn, const char *userName,
1108
- uint32_t userNameLength, const char *oldPassword,
1109
- uint32_t oldPasswordLength, const char *newPassword,
1110
- uint32_t newPasswordLength)
1111
- {
1112
- dpiError error;
1113
- int status;
1114
-
1115
- if (dpiConn__check(conn, __func__, &error) < 0)
1116
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1117
- DPI_CHECK_PTR_AND_LENGTH(conn, userName)
1118
- DPI_CHECK_PTR_AND_LENGTH(conn, oldPassword)
1119
- DPI_CHECK_PTR_AND_LENGTH(conn, newPassword)
1120
- status = dpiOci__passwordChange(conn, userName, userNameLength,
1121
- oldPassword, oldPasswordLength, newPassword, newPasswordLength,
1122
- DPI_OCI_DEFAULT, &error);
1123
- return dpiGen__endPublicFn(conn, status, &error);
1124
- }
1125
-
1126
-
1127
- //-----------------------------------------------------------------------------
1128
- // dpiConn_close() [PUBLIC]
1129
- // Close the connection and ensure it can no longer be used.
1130
- //-----------------------------------------------------------------------------
1131
- int dpiConn_close(dpiConn *conn, dpiConnCloseMode mode, const char *tag,
1132
- uint32_t tagLength)
1133
- {
1134
- int propagateErrors = !(mode & DPI_MODE_CONN_CLOSE_DROP);
1135
- dpiError error;
1136
- int closing;
1137
-
1138
- // validate parameters
1139
- if (dpiConn__check(conn, __func__, &error) < 0)
1140
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1141
- DPI_CHECK_PTR_AND_LENGTH(conn, tag)
1142
- if (mode && !conn->pool) {
1143
- dpiError__set(&error, "check in pool", DPI_ERR_CONN_NOT_IN_POOL);
1144
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1145
- }
1146
- if (conn->externalHandle) {
1147
- dpiError__set(&error, "check external", DPI_ERR_CONN_IS_EXTERNAL);
1148
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1149
- }
1150
-
1151
- // determine whether connection is already being closed and if not, mark
1152
- // connection as being closed; this MUST be done while holding the lock
1153
- // (if in threaded mode) to avoid race conditions!
1154
- if (conn->env->threaded)
1155
- dpiMutex__acquire(conn->env->mutex);
1156
- closing = conn->closing;
1157
- conn->closing = 1;
1158
- if (conn->env->threaded)
1159
- dpiMutex__release(conn->env->mutex);
1160
-
1161
- // if connection is already being closed, raise an exception
1162
- if (closing) {
1163
- dpiError__set(&error, "check closing", DPI_ERR_NOT_CONNECTED);
1164
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1165
- }
1166
-
1167
- // if actual close fails, reset closing flag; again, this must be done
1168
- // while holding the lock (if in threaded mode) in order to avoid race
1169
- // conditions!
1170
- if (dpiConn__close(conn, mode, tag, tagLength, propagateErrors,
1171
- &error) < 0) {
1172
- if (conn->env->threaded)
1173
- dpiMutex__acquire(conn->env->mutex);
1174
- conn->closing = 0;
1175
- if (conn->env->threaded)
1176
- dpiMutex__release(conn->env->mutex);
1177
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1178
- }
1179
-
1180
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
1181
- }
1182
-
1183
-
1184
- //-----------------------------------------------------------------------------
1185
- // dpiConn_commit() [PUBLIC]
1186
- // Commit the transaction associated with the connection.
1187
- //-----------------------------------------------------------------------------
1188
- int dpiConn_commit(dpiConn *conn)
1189
- {
1190
- dpiError error;
1191
-
1192
- if (dpiConn__check(conn, __func__, &error) < 0)
1193
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1194
- if (dpiOci__transCommit(conn, conn->commitMode, &error) < 0)
1195
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1196
- conn->commitMode = DPI_OCI_DEFAULT;
1197
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
1198
- }
1199
-
1200
-
1201
- //-----------------------------------------------------------------------------
1202
- // dpiConn_create() [PUBLIC]
1203
- // Create a standalone connection to the database using the parameters
1204
- // specified.
1205
- //-----------------------------------------------------------------------------
1206
- int dpiConn_create(const dpiContext *context, const char *userName,
1207
- uint32_t userNameLength, const char *password, uint32_t passwordLength,
1208
- const char *connectString, uint32_t connectStringLength,
1209
- const dpiCommonCreateParams *commonParams,
1210
- dpiConnCreateParams *createParams, dpiConn **conn)
1211
- {
1212
- dpiCommonCreateParams localCommonParams;
1213
- dpiConnCreateParams localCreateParams;
1214
- dpiConn *tempConn;
1215
- dpiError error;
1216
- int status;
1217
-
1218
- // validate parameters
1219
- if (dpiGen__startPublicFn(context, DPI_HTYPE_CONTEXT, __func__, 0,
1220
- &error) < 0)
1221
- return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
1222
- DPI_CHECK_PTR_NOT_NULL(context, conn)
1223
- DPI_CHECK_PTR_AND_LENGTH(context, userName)
1224
- DPI_CHECK_PTR_AND_LENGTH(context, password)
1225
- DPI_CHECK_PTR_AND_LENGTH(context, connectString)
1226
-
1227
- // use default parameters if none provided
1228
- if (!commonParams) {
1229
- dpiContext__initCommonCreateParams(&localCommonParams);
1230
- commonParams = &localCommonParams;
1231
- }
1232
- if (!createParams) {
1233
- dpiContext__initConnCreateParams(&localCreateParams);
1234
- createParams = &localCreateParams;
1235
- }
1236
-
1237
- // ensure that username and password are not specified if external
1238
- // authentication is desired
1239
- if (createParams->externalAuth &&
1240
- ((userName && userNameLength > 0) ||
1241
- (password && passwordLength > 0))) {
1242
- dpiError__set(&error, "check mixed credentials",
1243
- DPI_ERR_EXT_AUTH_WITH_CREDENTIALS);
1244
- return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
1245
- }
1246
-
1247
- // connectionClass and edition cannot be specified at the same time
1248
- if (createParams->connectionClass &&
1249
- createParams->connectionClassLength > 0 &&
1250
- commonParams->edition && commonParams->editionLength > 0) {
1251
- dpiError__set(&error, "check edition/conn class",
1252
- DPI_ERR_NO_EDITION_WITH_CONN_CLASS);
1253
- return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
1254
- }
1255
-
1256
- // newPassword and edition cannot be specified at the same time
1257
- if (createParams->newPassword && createParams->newPasswordLength > 0 &&
1258
- commonParams->edition && commonParams->editionLength > 0) {
1259
- dpiError__set(&error, "check edition/new password",
1260
- DPI_ERR_NO_EDITION_WITH_NEW_PASSWORD);
1261
- return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
1262
- }
1263
-
1264
- // handle case where pool is specified
1265
- if (createParams->pool) {
1266
- if (dpiGen__checkHandle(createParams->pool, DPI_HTYPE_POOL,
1267
- "verify pool", &error) < 0)
1268
- return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
1269
- if (!createParams->pool->handle) {
1270
- dpiError__set(&error, "check pool", DPI_ERR_NOT_CONNECTED);
1271
- return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
1272
- }
1273
- if (dpiEnv__initError(createParams->pool->env, &error) < 0)
1274
- return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
1275
- status = dpiPool__acquireConnection(createParams->pool, userName,
1276
- userNameLength, password, passwordLength, createParams, conn,
1277
- &error);
1278
- return dpiGen__endPublicFn(context, status, &error);
1279
- }
1280
-
1281
- // create connection
1282
- if (dpiGen__allocate(DPI_HTYPE_CONN, NULL, (void**) &tempConn, &error) < 0)
1283
- return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
1284
- if (dpiConn__create(tempConn, context, userName, userNameLength,
1285
- password, passwordLength, connectString, connectStringLength,
1286
- NULL, commonParams, createParams, &error) < 0) {
1287
- dpiConn__free(tempConn, &error);
1288
- return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
1289
- }
1290
-
1291
- *conn = tempConn;
1292
- dpiHandlePool__release(tempConn->env->errorHandles, error.handle, &error);
1293
- error.handle = NULL;
1294
- return dpiGen__endPublicFn(context, DPI_SUCCESS, &error);
1295
- }
1296
-
1297
-
1298
- //-----------------------------------------------------------------------------
1299
- // dpiConn_getSodaDb() [PUBLIC]
1300
- // Create a new SODA collection with the given name and metadata.
1301
- //-----------------------------------------------------------------------------
1302
- int dpiConn_getSodaDb(dpiConn *conn, dpiSodaDb **db)
1303
- {
1304
- dpiError error;
1305
-
1306
- if (dpiConn__check(conn, __func__, &error) < 0)
1307
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1308
- if (dpiUtils__checkClientVersion(conn->env->versionInfo, 18, 3,
1309
- &error) < 0)
1310
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1311
- if (dpiUtils__checkDatabaseVersion(conn, 18, 0, &error) < 0)
1312
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1313
- if (dpiGen__allocate(DPI_HTYPE_SODA_DB, conn->env, (void**) db,
1314
- &error) < 0)
1315
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1316
- dpiGen__setRefCount(conn, &error, 1);
1317
- (*db)->conn = conn;
1318
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
1319
- }
1320
-
1321
-
1322
- //-----------------------------------------------------------------------------
1323
- // dpiConn_deqObject() [PUBLIC]
1324
- // Dequeue a message from the specified queue.
1325
- //-----------------------------------------------------------------------------
1326
- int dpiConn_deqObject(dpiConn *conn, const char *queueName,
1327
- uint32_t queueNameLength, dpiDeqOptions *options, dpiMsgProps *props,
1328
- dpiObject *payload, const char **msgId, uint32_t *msgIdLength)
1329
- {
1330
- void *ociMsgId = NULL;
1331
- dpiError error;
1332
-
1333
- // validate parameters
1334
- if (dpiConn__check(conn, __func__, &error) < 0)
1335
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1336
- if (dpiGen__checkHandle(options, DPI_HTYPE_DEQ_OPTIONS, "verify options",
1337
- &error) < 0)
1338
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1339
- if (dpiGen__checkHandle(props, DPI_HTYPE_MSG_PROPS,
1340
- "verify message properties", &error) < 0)
1341
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1342
- if (dpiGen__checkHandle(payload, DPI_HTYPE_OBJECT, "verify payload",
1343
- &error) < 0)
1344
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1345
- DPI_CHECK_PTR_AND_LENGTH(conn, queueName)
1346
- DPI_CHECK_PTR_NOT_NULL(conn, msgId)
1347
- DPI_CHECK_PTR_NOT_NULL(conn, msgIdLength)
1348
-
1349
- // dequeue message
1350
- if (dpiOci__aqDeq(conn, queueName, options->handle, props->handle,
1351
- payload->type->tdo, &payload->instance, &payload->indicator,
1352
- &ociMsgId, &error) < 0) {
1353
- if (error.buffer->code == 25228) {
1354
- if (ociMsgId)
1355
- dpiOci__rawResize(conn->env->handle, &ociMsgId, 0, &error);
1356
- *msgId = NULL;
1357
- *msgIdLength = 0;
1358
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
1359
- }
1360
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1361
- }
1362
- if (dpiMsgProps__extractMsgId(props, ociMsgId, msgId, msgIdLength,
1363
- &error) < 0)
1364
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1365
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
1366
- }
1367
-
1368
-
1369
- //-----------------------------------------------------------------------------
1370
- // dpiConn_enqObject() [PUBLIC]
1371
- // Enqueue a message to the specified queue.
1372
- //-----------------------------------------------------------------------------
1373
- int dpiConn_enqObject(dpiConn *conn, const char *queueName,
1374
- uint32_t queueNameLength, dpiEnqOptions *options, dpiMsgProps *props,
1375
- dpiObject *payload, const char **msgId, uint32_t *msgIdLength)
1376
- {
1377
- void *ociMsgId = NULL;
1378
- dpiError error;
1379
-
1380
- // validate parameters
1381
- if (dpiConn__check(conn, __func__, &error) < 0)
1382
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1383
- if (dpiGen__checkHandle(options, DPI_HTYPE_ENQ_OPTIONS, "verify options",
1384
- &error) < 0)
1385
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1386
- if (dpiGen__checkHandle(props, DPI_HTYPE_MSG_PROPS,
1387
- "verify message properties", &error) < 0)
1388
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1389
- if (dpiGen__checkHandle(payload, DPI_HTYPE_OBJECT, "verify payload",
1390
- &error) < 0)
1391
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1392
- DPI_CHECK_PTR_AND_LENGTH(conn, queueName)
1393
- DPI_CHECK_PTR_NOT_NULL(conn, msgId)
1394
- DPI_CHECK_PTR_NOT_NULL(conn, msgIdLength)
1395
-
1396
- // enqueue message
1397
- if (dpiOci__aqEnq(conn, queueName, options->handle, props->handle,
1398
- payload->type->tdo, &payload->instance, &payload->indicator,
1399
- &ociMsgId, &error) < 0)
1400
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1401
- if (dpiMsgProps__extractMsgId(props, ociMsgId, msgId, msgIdLength,
1402
- &error) < 0)
1403
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1404
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
1405
- }
1406
-
1407
-
1408
- //-----------------------------------------------------------------------------
1409
- // dpiConn_getCallTimeout() [PUBLIC]
1410
- // Return the call timeout (in milliseconds) used for round-trips to the
1411
- // database. This is only valid in Oracle Client 18c and higher.
1412
- //-----------------------------------------------------------------------------
1413
- int dpiConn_getCallTimeout(dpiConn *conn, uint32_t *value)
1414
- {
1415
- dpiError error;
1416
- int status;
1417
-
1418
- // validate parameters
1419
- if (dpiConn__check(conn, __func__, &error) < 0)
1420
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1421
- DPI_CHECK_PTR_NOT_NULL(conn, value)
1422
- if (dpiUtils__checkClientVersion(conn->env->versionInfo, 18, 1,
1423
- &error) < 0)
1424
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1425
-
1426
- // get call timeout
1427
- status = dpiOci__attrGet(conn->handle, DPI_OCI_HTYPE_SVCCTX,
1428
- (void*) value, 0, DPI_OCI_ATTR_CALL_TIMEOUT, "get call timeout",
1429
- &error);
1430
- return dpiGen__endPublicFn(conn, status, &error);
1431
- }
1432
-
1433
-
1434
- //-----------------------------------------------------------------------------
1435
- // dpiConn_getCurrentSchema() [PUBLIC]
1436
- // Return the current schema associated with the connection.
1437
- //-----------------------------------------------------------------------------
1438
- int dpiConn_getCurrentSchema(dpiConn *conn, const char **value,
1439
- uint32_t *valueLength)
1440
- {
1441
- return dpiConn__getAttributeText(conn, DPI_OCI_ATTR_CURRENT_SCHEMA, value,
1442
- valueLength, __func__);
1443
- }
1444
-
1445
-
1446
- //-----------------------------------------------------------------------------
1447
- // dpiConn_getEdition() [PUBLIC]
1448
- // Return the edition associated with the connection.
1449
- //-----------------------------------------------------------------------------
1450
- int dpiConn_getEdition(dpiConn *conn, const char **value,
1451
- uint32_t *valueLength)
1452
- {
1453
- return dpiConn__getAttributeText(conn, DPI_OCI_ATTR_EDITION, value,
1454
- valueLength, __func__);
1455
- }
1456
-
1457
-
1458
- //-----------------------------------------------------------------------------
1459
- // dpiConn_getEncodingInfo() [PUBLIC]
1460
- // Get the encodings from the connection.
1461
- //-----------------------------------------------------------------------------
1462
- int dpiConn_getEncodingInfo(dpiConn *conn, dpiEncodingInfo *info)
1463
- {
1464
- dpiError error;
1465
- int status;
1466
-
1467
- if (dpiConn__check(conn, __func__, &error) < 0)
1468
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1469
- status = dpiEnv__getEncodingInfo(conn->env, info);
1470
- return dpiGen__endPublicFn(conn, status, &error);
1471
- }
1472
-
1473
-
1474
- //-----------------------------------------------------------------------------
1475
- // dpiConn_getExternalName() [PUBLIC]
1476
- // Return the external name associated with the connection.
1477
- //-----------------------------------------------------------------------------
1478
- int dpiConn_getExternalName(dpiConn *conn, const char **value,
1479
- uint32_t *valueLength)
1480
- {
1481
- return dpiConn__getAttributeText(conn, DPI_OCI_ATTR_EXTERNAL_NAME, value,
1482
- valueLength, __func__);
1483
- }
1484
-
1485
-
1486
- //-----------------------------------------------------------------------------
1487
- // dpiConn_getHandle() [PUBLIC]
1488
- // Get the OCI service context handle associated with the connection. This is
1489
- // available in order to allow for extensions to the library using OCI
1490
- // directly.
1491
- //-----------------------------------------------------------------------------
1492
- int dpiConn_getHandle(dpiConn *conn, void **handle)
1493
- {
1494
- dpiError error;
1495
-
1496
- if (dpiConn__check(conn, __func__, &error) < 0)
1497
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1498
- DPI_CHECK_PTR_NOT_NULL(conn, handle)
1499
- *handle = conn->handle;
1500
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
1501
- }
1502
-
1503
-
1504
- //-----------------------------------------------------------------------------
1505
- // dpiConn_getInternalName() [PUBLIC]
1506
- // Return the internal name associated with the connection.
1507
- //-----------------------------------------------------------------------------
1508
- int dpiConn_getInternalName(dpiConn *conn, const char **value,
1509
- uint32_t *valueLength)
1510
- {
1511
- return dpiConn__getAttributeText(conn, DPI_OCI_ATTR_INTERNAL_NAME, value,
1512
- valueLength, __func__);
1513
- }
1514
-
1515
-
1516
- //-----------------------------------------------------------------------------
1517
- // dpiConn_getLTXID() [PUBLIC]
1518
- // Return the logical transaction id associated with the connection.
1519
- //-----------------------------------------------------------------------------
1520
- int dpiConn_getLTXID(dpiConn *conn, const char **value, uint32_t *valueLength)
1521
- {
1522
- return dpiConn__getAttributeText(conn, DPI_OCI_ATTR_LTXID, value,
1523
- valueLength, __func__);
1524
- }
1525
-
1526
-
1527
- //-----------------------------------------------------------------------------
1528
- // dpiConn_getObjectType() [PUBLIC]
1529
- // Look up an object type given its name and return it.
1530
- //-----------------------------------------------------------------------------
1531
- int dpiConn_getObjectType(dpiConn *conn, const char *name, uint32_t nameLength,
1532
- dpiObjectType **objType)
1533
- {
1534
- void *describeHandle, *param, *tdo;
1535
- int status, useTypeByFullName;
1536
- dpiError error;
1537
-
1538
- // validate parameters
1539
- if (dpiConn__check(conn, __func__, &error) < 0)
1540
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1541
- DPI_CHECK_PTR_NOT_NULL(conn, name)
1542
- DPI_CHECK_PTR_NOT_NULL(conn, objType)
1543
-
1544
- // allocate describe handle
1545
- if (dpiOci__handleAlloc(conn->env->handle, &describeHandle,
1546
- DPI_OCI_HTYPE_DESCRIBE, "allocate describe handle", &error) < 0)
1547
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1548
-
1549
- // Oracle Client 12.1 is capable of using OCITypeByFullName() but will
1550
- // fail if accessing an Oracle 11.2 database
1551
- useTypeByFullName = 1;
1552
- if (conn->env->versionInfo->versionNum < 12)
1553
- useTypeByFullName = 0;
1554
- else if (dpiConn__getServerVersion(conn, &error) < 0)
1555
- return DPI_FAILURE;
1556
- else if (conn->versionInfo.versionNum < 12)
1557
- useTypeByFullName = 0;
1558
-
1559
- // new API is supported so use it
1560
- if (useTypeByFullName) {
1561
- if (dpiOci__typeByFullName(conn, name, nameLength, &tdo, &error) < 0) {
1562
- dpiOci__handleFree(describeHandle, DPI_OCI_HTYPE_DESCRIBE);
1563
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1564
- }
1565
- if (dpiOci__describeAny(conn, tdo, 0, DPI_OCI_OTYPE_PTR,
1566
- describeHandle, &error) < 0) {
1567
- dpiOci__handleFree(describeHandle, DPI_OCI_HTYPE_DESCRIBE);
1568
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1569
- }
1570
-
1571
- // use older API
1572
- } else {
1573
- if (dpiOci__describeAny(conn, (void*) name, nameLength,
1574
- DPI_OCI_OTYPE_NAME, describeHandle, &error) < 0) {
1575
- dpiOci__handleFree(describeHandle, DPI_OCI_HTYPE_DESCRIBE);
1576
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1577
- }
1578
- }
1579
-
1580
- // get the parameter handle
1581
- if (dpiOci__attrGet(describeHandle,
1582
- DPI_OCI_HTYPE_DESCRIBE, &param, 0, DPI_OCI_ATTR_PARAM,
1583
- "get param", &error) < 0) {
1584
- dpiOci__handleFree(describeHandle, DPI_OCI_HTYPE_DESCRIBE);
1585
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1586
- }
1587
-
1588
- // create object type
1589
- status = dpiObjectType__allocate(conn, param, DPI_OCI_ATTR_NAME, objType,
1590
- &error);
1591
- dpiOci__handleFree(describeHandle, DPI_OCI_HTYPE_DESCRIBE);
1592
- return dpiGen__endPublicFn(conn, status, &error);
1593
- }
1594
-
1595
-
1596
- //-----------------------------------------------------------------------------
1597
- // dpiConn_getServerVersion() [PUBLIC]
1598
- // Get the server version string from the database.
1599
- //-----------------------------------------------------------------------------
1600
- int dpiConn_getServerVersion(dpiConn *conn, const char **releaseString,
1601
- uint32_t *releaseStringLength, dpiVersionInfo *versionInfo)
1602
- {
1603
- dpiError error;
1604
-
1605
- // validate parameters
1606
- if (dpiConn__check(conn, __func__, &error) < 0)
1607
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1608
- DPI_CHECK_PTR_NOT_NULL(conn, releaseString)
1609
- DPI_CHECK_PTR_NOT_NULL(conn, releaseStringLength)
1610
- DPI_CHECK_PTR_NOT_NULL(conn, versionInfo)
1611
-
1612
- // get server version
1613
- if (dpiConn__getServerVersion(conn, &error) < 0)
1614
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1615
- *releaseString = conn->releaseString;
1616
- *releaseStringLength = conn->releaseStringLength;
1617
- memcpy(versionInfo, &conn->versionInfo, sizeof(dpiVersionInfo));
1618
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
1619
- }
1620
-
1621
-
1622
- //-----------------------------------------------------------------------------
1623
- // dpiConn_getStmtCacheSize() [PUBLIC]
1624
- // Return the current size of the statement cache.
1625
- //-----------------------------------------------------------------------------
1626
- int dpiConn_getStmtCacheSize(dpiConn *conn, uint32_t *cacheSize)
1627
- {
1628
- dpiError error;
1629
- int status;
1630
-
1631
- if (dpiConn__check(conn, __func__, &error) < 0)
1632
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1633
- DPI_CHECK_PTR_NOT_NULL(conn, cacheSize)
1634
- status = dpiOci__attrGet(conn->handle, DPI_OCI_HTYPE_SVCCTX, cacheSize,
1635
- NULL, DPI_OCI_ATTR_STMTCACHESIZE, "get stmt cache size", &error);
1636
- return dpiGen__endPublicFn(conn, status, &error);
1637
- }
1638
-
1639
-
1640
- //-----------------------------------------------------------------------------
1641
- // dpiConn_newDeqOptions() [PUBLIC]
1642
- // Create a new dequeue options object and return it.
1643
- //-----------------------------------------------------------------------------
1644
- int dpiConn_newDeqOptions(dpiConn *conn, dpiDeqOptions **options)
1645
- {
1646
- dpiDeqOptions *tempOptions;
1647
- dpiError error;
1648
-
1649
- if (dpiConn__check(conn, __func__, &error) < 0)
1650
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1651
- DPI_CHECK_PTR_NOT_NULL(conn, options)
1652
- if (dpiGen__allocate(DPI_HTYPE_DEQ_OPTIONS, conn->env,
1653
- (void**) &tempOptions, &error) < 0)
1654
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1655
- if (dpiDeqOptions__create(tempOptions, conn, &error) < 0) {
1656
- dpiDeqOptions__free(tempOptions, &error);
1657
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1658
- }
1659
-
1660
- *options = tempOptions;
1661
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
1662
- }
1663
-
1664
-
1665
- //-----------------------------------------------------------------------------
1666
- // dpiConn_newEnqOptions() [PUBLIC]
1667
- // Create a new enqueue options object and return it.
1668
- //-----------------------------------------------------------------------------
1669
- int dpiConn_newEnqOptions(dpiConn *conn, dpiEnqOptions **options)
1670
- {
1671
- dpiEnqOptions *tempOptions;
1672
- dpiError error;
1673
-
1674
- if (dpiConn__check(conn, __func__, &error) < 0)
1675
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1676
- DPI_CHECK_PTR_NOT_NULL(conn, options)
1677
- if (dpiGen__allocate(DPI_HTYPE_ENQ_OPTIONS, conn->env,
1678
- (void**) &tempOptions, &error) < 0)
1679
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1680
- if (dpiEnqOptions__create(tempOptions, conn, &error) < 0) {
1681
- dpiEnqOptions__free(tempOptions, &error);
1682
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1683
- }
1684
-
1685
- *options = tempOptions;
1686
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
1687
- }
1688
-
1689
-
1690
- //-----------------------------------------------------------------------------
1691
- // dpiConn_newTempLob() [PUBLIC]
1692
- // Create a new temporary LOB and return it.
1693
- //-----------------------------------------------------------------------------
1694
- int dpiConn_newTempLob(dpiConn *conn, dpiOracleTypeNum lobType, dpiLob **lob)
1695
- {
1696
- const dpiOracleType *type;
1697
- dpiLob *tempLob;
1698
- dpiError error;
1699
-
1700
- if (dpiConn__check(conn, __func__, &error) < 0)
1701
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1702
- DPI_CHECK_PTR_NOT_NULL(conn, lob)
1703
- switch (lobType) {
1704
- case DPI_ORACLE_TYPE_CLOB:
1705
- case DPI_ORACLE_TYPE_BLOB:
1706
- case DPI_ORACLE_TYPE_NCLOB:
1707
- type = dpiOracleType__getFromNum(lobType, &error);
1708
- break;
1709
- default:
1710
- dpiError__set(&error, "check lob type",
1711
- DPI_ERR_INVALID_ORACLE_TYPE, lobType);
1712
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1713
- }
1714
- if (dpiLob__allocate(conn, type, &tempLob, &error) < 0)
1715
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1716
- if (dpiOci__lobCreateTemporary(tempLob, &error) < 0) {
1717
- dpiLob__free(tempLob, &error);
1718
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1719
- }
1720
-
1721
- *lob = tempLob;
1722
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
1723
- }
1724
-
1725
-
1726
- //-----------------------------------------------------------------------------
1727
- // dpiConn_newMsgProps() [PUBLIC]
1728
- // Create a new message properties object and return it.
1729
- //-----------------------------------------------------------------------------
1730
- int dpiConn_newMsgProps(dpiConn *conn, dpiMsgProps **props)
1731
- {
1732
- dpiMsgProps *tempProps;
1733
- dpiError error;
1734
-
1735
- if (dpiConn__check(conn, __func__, &error) < 0)
1736
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1737
- DPI_CHECK_PTR_NOT_NULL(conn, props)
1738
- if (dpiGen__allocate(DPI_HTYPE_MSG_PROPS, conn->env, (void**) &tempProps,
1739
- &error) < 0)
1740
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1741
- if (dpiMsgProps__create(tempProps, conn, &error) < 0) {
1742
- dpiMsgProps__free(tempProps, &error);
1743
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1744
- }
1745
-
1746
- *props = tempProps;
1747
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
1748
- }
1749
-
1750
-
1751
- //-----------------------------------------------------------------------------
1752
- // dpiConn_newVar() [PUBLIC]
1753
- // Create a new variable and return it.
1754
- //-----------------------------------------------------------------------------
1755
- int dpiConn_newVar(dpiConn *conn, dpiOracleTypeNum oracleTypeNum,
1756
- dpiNativeTypeNum nativeTypeNum, uint32_t maxArraySize, uint32_t size,
1757
- int sizeIsBytes, int isArray, dpiObjectType *objType, dpiVar **var,
1758
- dpiData **data)
1759
- {
1760
- dpiError error;
1761
- int status;
1762
-
1763
- if (dpiConn__check(conn, __func__, &error) < 0)
1764
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1765
- DPI_CHECK_PTR_NOT_NULL(conn, var)
1766
- DPI_CHECK_PTR_NOT_NULL(conn, data)
1767
- status = dpiVar__allocate(conn, oracleTypeNum, nativeTypeNum, maxArraySize,
1768
- size, sizeIsBytes, isArray, objType, var, data, &error);
1769
- return dpiGen__endPublicFn(conn, status, &error);
1770
- }
1771
-
1772
-
1773
- //-----------------------------------------------------------------------------
1774
- // dpiConn_ping() [PUBLIC]
1775
- // Makes a round trip call to the server to confirm that the connection and
1776
- // server are still active.
1777
- //-----------------------------------------------------------------------------
1778
- int dpiConn_ping(dpiConn *conn)
1779
- {
1780
- dpiError error;
1781
- int status;
1782
-
1783
- if (dpiConn__check(conn, __func__, &error) < 0)
1784
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1785
- status = dpiOci__ping(conn, &error);
1786
- return dpiGen__endPublicFn(conn, status, &error);
1787
- }
1788
-
1789
-
1790
- //-----------------------------------------------------------------------------
1791
- // dpiConn_prepareDistribTrans() [PUBLIC]
1792
- // Prepare a distributed transaction for commit. A boolean is returned
1793
- // indicating if a commit is actually needed as an attempt to perform a commit
1794
- // when nothing is actually prepared results in ORA-24756 (transaction does not
1795
- // exist). This is determined by the return value from OCITransPrepare() which
1796
- // is OCI_SUCCESS_WITH_INFO if there is no transaction requiring commit.
1797
- //-----------------------------------------------------------------------------
1798
- int dpiConn_prepareDistribTrans(dpiConn *conn, int *commitNeeded)
1799
- {
1800
- dpiError error;
1801
-
1802
- if (dpiConn__check(conn, __func__, &error) < 0)
1803
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1804
- DPI_CHECK_PTR_NOT_NULL(conn, commitNeeded)
1805
- if (dpiOci__transPrepare(conn, commitNeeded, &error) < 0)
1806
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1807
- if (*commitNeeded)
1808
- conn->commitMode = DPI_OCI_TRANS_TWOPHASE;
1809
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
1810
- }
1811
-
1812
-
1813
- //-----------------------------------------------------------------------------
1814
- // dpiConn_prepareStmt() [PUBLIC]
1815
- // Create a new statement and return it after preparing the specified SQL.
1816
- //-----------------------------------------------------------------------------
1817
- int dpiConn_prepareStmt(dpiConn *conn, int scrollable, const char *sql,
1818
- uint32_t sqlLength, const char *tag, uint32_t tagLength,
1819
- dpiStmt **stmt)
1820
- {
1821
- dpiStmt *tempStmt;
1822
- dpiError error;
1823
-
1824
- *stmt = NULL;
1825
- if (dpiConn__check(conn, __func__, &error) < 0)
1826
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1827
- DPI_CHECK_PTR_AND_LENGTH(conn, sql)
1828
- DPI_CHECK_PTR_AND_LENGTH(conn, tag)
1829
- DPI_CHECK_PTR_NOT_NULL(conn, stmt)
1830
- if (dpiStmt__allocate(conn, scrollable, &tempStmt, &error) < 0)
1831
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1832
- if (dpiStmt__prepare(tempStmt, sql, sqlLength, tag, tagLength,
1833
- &error) < 0) {
1834
- dpiStmt__free(tempStmt, &error);
1835
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1836
- }
1837
- *stmt = tempStmt;
1838
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
1839
- }
1840
-
1841
-
1842
- //-----------------------------------------------------------------------------
1843
- // dpiConn_release() [PUBLIC]
1844
- // Release a reference to the connection.
1845
- //-----------------------------------------------------------------------------
1846
- int dpiConn_release(dpiConn *conn)
1847
- {
1848
- return dpiGen__release(conn, DPI_HTYPE_CONN, __func__);
1849
- }
1850
-
1851
-
1852
- //-----------------------------------------------------------------------------
1853
- // dpiConn_rollback() [PUBLIC]
1854
- // Rollback the transaction associated with the connection.
1855
- //-----------------------------------------------------------------------------
1856
- int dpiConn_rollback(dpiConn *conn)
1857
- {
1858
- dpiError error;
1859
- int status;
1860
-
1861
- if (dpiConn__check(conn, __func__, &error) < 0)
1862
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1863
- status = dpiOci__transRollback(conn, 1, &error);
1864
- return dpiGen__endPublicFn(conn, status, &error);
1865
- }
1866
-
1867
-
1868
- //-----------------------------------------------------------------------------
1869
- // dpiConn_setAction() [PUBLIC]
1870
- // Set the action associated with the connection.
1871
- //-----------------------------------------------------------------------------
1872
- int dpiConn_setAction(dpiConn *conn, const char *value, uint32_t valueLength)
1873
- {
1874
- return dpiConn__setAttributeText(conn, DPI_OCI_ATTR_ACTION, value,
1875
- valueLength, __func__);
1876
- }
1877
-
1878
-
1879
- //-----------------------------------------------------------------------------
1880
- // dpiConn_setCallTimeout() [PUBLIC]
1881
- // Set the call timeout (in milliseconds) used for round-trips to the
1882
- // database. This is only valid in Oracle Client 18c and higher.
1883
- //-----------------------------------------------------------------------------
1884
- int dpiConn_setCallTimeout(dpiConn *conn, uint32_t value)
1885
- {
1886
- dpiError error;
1887
- int status;
1888
-
1889
- // validate parameters
1890
- if (dpiConn__check(conn, __func__, &error) < 0)
1891
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1892
- if (dpiUtils__checkClientVersion(conn->env->versionInfo, 18, 1,
1893
- &error) < 0)
1894
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1895
-
1896
- // set call timeout
1897
- status = dpiOci__attrSet(conn->handle, DPI_OCI_HTYPE_SVCCTX, &value,
1898
- 0, DPI_OCI_ATTR_CALL_TIMEOUT, "set call timeout", &error);
1899
- return dpiGen__endPublicFn(conn, status, &error);
1900
- }
1901
-
1902
-
1903
- //-----------------------------------------------------------------------------
1904
- // dpiConn_setClientIdentifier() [PUBLIC]
1905
- // Set the client identifier associated with the connection.
1906
- //-----------------------------------------------------------------------------
1907
- int dpiConn_setClientIdentifier(dpiConn *conn, const char *value,
1908
- uint32_t valueLength)
1909
- {
1910
- return dpiConn__setAttributeText(conn, DPI_OCI_ATTR_CLIENT_IDENTIFIER,
1911
- value, valueLength, __func__);
1912
- }
1913
-
1914
-
1915
- //-----------------------------------------------------------------------------
1916
- // dpiConn_setClientInfo() [PUBLIC]
1917
- // Set the client info associated with the connection.
1918
- //-----------------------------------------------------------------------------
1919
- int dpiConn_setClientInfo(dpiConn *conn, const char *value,
1920
- uint32_t valueLength)
1921
- {
1922
- return dpiConn__setAttributeText(conn, DPI_OCI_ATTR_CLIENT_INFO, value,
1923
- valueLength, __func__);
1924
- }
1925
-
1926
-
1927
- //-----------------------------------------------------------------------------
1928
- // dpiConn_setCurrentSchema() [PUBLIC]
1929
- // Set the current schema associated with the connection.
1930
- //-----------------------------------------------------------------------------
1931
- int dpiConn_setCurrentSchema(dpiConn *conn, const char *value,
1932
- uint32_t valueLength)
1933
- {
1934
- return dpiConn__setAttributeText(conn, DPI_OCI_ATTR_CURRENT_SCHEMA, value,
1935
- valueLength, __func__);
1936
- }
1937
-
1938
-
1939
- //-----------------------------------------------------------------------------
1940
- // dpiConn_setDbOp() [PUBLIC]
1941
- // Set the database operation associated with the connection.
1942
- //-----------------------------------------------------------------------------
1943
- int dpiConn_setDbOp(dpiConn *conn, const char *value, uint32_t valueLength)
1944
- {
1945
- return dpiConn__setAttributeText(conn, DPI_OCI_ATTR_DBOP, value,
1946
- valueLength, __func__);
1947
- }
1948
-
1949
-
1950
- //-----------------------------------------------------------------------------
1951
- // dpiConn_setExternalName() [PUBLIC]
1952
- // Set the external name associated with the connection.
1953
- //-----------------------------------------------------------------------------
1954
- int dpiConn_setExternalName(dpiConn *conn, const char *value,
1955
- uint32_t valueLength)
1956
- {
1957
- return dpiConn__setAttributeText(conn, DPI_OCI_ATTR_EXTERNAL_NAME, value,
1958
- valueLength, __func__);
1959
- }
1960
-
1961
-
1962
- //-----------------------------------------------------------------------------
1963
- // dpiConn_setInternalName() [PUBLIC]
1964
- // Set the internal name associated with the connection.
1965
- //-----------------------------------------------------------------------------
1966
- int dpiConn_setInternalName(dpiConn *conn, const char *value,
1967
- uint32_t valueLength)
1968
- {
1969
- return dpiConn__setAttributeText(conn, DPI_OCI_ATTR_INTERNAL_NAME, value,
1970
- valueLength, __func__);
1971
- }
1972
-
1973
-
1974
- //-----------------------------------------------------------------------------
1975
- // dpiConn_setModule() [PUBLIC]
1976
- // Set the module associated with the connection.
1977
- //-----------------------------------------------------------------------------
1978
- int dpiConn_setModule(dpiConn *conn, const char *value, uint32_t valueLength)
1979
- {
1980
- return dpiConn__setAttributeText(conn, DPI_OCI_ATTR_MODULE, value,
1981
- valueLength, __func__);
1982
- }
1983
-
1984
-
1985
- //-----------------------------------------------------------------------------
1986
- // dpiConn_setStmtCacheSize() [PUBLIC]
1987
- // Set the size of the statement cache.
1988
- //-----------------------------------------------------------------------------
1989
- int dpiConn_setStmtCacheSize(dpiConn *conn, uint32_t cacheSize)
1990
- {
1991
- dpiError error;
1992
- int status;
1993
-
1994
- if (dpiConn__check(conn, __func__, &error) < 0)
1995
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
1996
- status = dpiOci__attrSet(conn->handle, DPI_OCI_HTYPE_SVCCTX, &cacheSize, 0,
1997
- DPI_OCI_ATTR_STMTCACHESIZE, "set stmt cache size", &error);
1998
- return dpiGen__endPublicFn(conn, status, &error);
1999
- }
2000
-
2001
-
2002
- //-----------------------------------------------------------------------------
2003
- // dpiConn_shutdownDatabase() [PUBLIC]
2004
- // Shutdown the database. Note that this must be done in two phases except in
2005
- // the situation where the instance is being aborted.
2006
- //-----------------------------------------------------------------------------
2007
- int dpiConn_shutdownDatabase(dpiConn *conn, dpiShutdownMode mode)
2008
- {
2009
- dpiError error;
2010
- int status;
2011
-
2012
- if (dpiConn__check(conn, __func__, &error) < 0)
2013
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
2014
- status = dpiOci__dbShutdown(conn, mode, &error);
2015
- return dpiGen__endPublicFn(conn, status, &error);
2016
- }
2017
-
2018
-
2019
- //-----------------------------------------------------------------------------
2020
- // dpiConn_startupDatabase() [PUBLIC]
2021
- // Startup the database. This is equivalent to "startup nomount" in SQL*Plus.
2022
- //-----------------------------------------------------------------------------
2023
- int dpiConn_startupDatabase(dpiConn *conn, dpiStartupMode mode)
2024
- {
2025
- dpiError error;
2026
- int status;
2027
-
2028
- if (dpiConn__check(conn, __func__, &error) < 0)
2029
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
2030
- status = dpiOci__dbStartup(conn, mode, &error);
2031
- return dpiGen__endPublicFn(conn, status, &error);
2032
- }
2033
-
2034
- //-----------------------------------------------------------------------------
2035
- // dpiConn_subscribe() [PUBLIC]
2036
- // Subscribe to events in the database. A subscription is created and
2037
- // returned. This replaces dpiConn_newSubscription().
2038
- //-----------------------------------------------------------------------------
2039
- int dpiConn_subscribe(dpiConn *conn, dpiSubscrCreateParams *params,
2040
- dpiSubscr **subscr)
2041
- {
2042
- dpiSubscr *tempSubscr;
2043
- dpiError error;
2044
-
2045
- if (dpiConn__check(conn, __func__, &error) < 0)
2046
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
2047
- DPI_CHECK_PTR_NOT_NULL(conn, params)
2048
- DPI_CHECK_PTR_NOT_NULL(conn, subscr)
2049
- if (!conn->env->events) {
2050
- dpiError__set(&error, "subscribe", DPI_ERR_EVENTS_MODE_REQUIRED);
2051
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
2052
- }
2053
- if (dpiGen__allocate(DPI_HTYPE_SUBSCR, conn->env, (void**) &tempSubscr,
2054
- &error) < 0)
2055
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
2056
- if (dpiSubscr__create(tempSubscr, conn, params, &error) < 0) {
2057
- dpiSubscr__free(tempSubscr, &error);
2058
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
2059
- }
2060
-
2061
- *subscr = tempSubscr;
2062
- return dpiGen__endPublicFn(conn, DPI_SUCCESS, &error);
2063
- }
2064
-
2065
-
2066
- //-----------------------------------------------------------------------------
2067
- // dpiConn_unsubscribe() [PUBLIC]
2068
- // Unsubscribe from events in the database. Once this call completes
2069
- // successfully no further notifications will be sent.
2070
- //-----------------------------------------------------------------------------
2071
- int dpiConn_unsubscribe(dpiConn *conn, dpiSubscr *subscr)
2072
- {
2073
- dpiError error;
2074
-
2075
- if (dpiConn__check(conn, __func__, &error) < 0)
2076
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
2077
- if (dpiGen__checkHandle(subscr, DPI_HTYPE_SUBSCR, "check subscription",
2078
- &error) < 0)
2079
- return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
2080
- if (subscr->registered) {
2081
- if (dpiOci__subscriptionUnRegister(conn, subscr, &error) < 0)
2082
- return dpiGen__endPublicFn(subscr, DPI_FAILURE, &error);
2083
- subscr->registered = 0;
2084
- }
2085
-
2086
- dpiGen__setRefCount(subscr, &error, -1);
2087
- return dpiGen__endPublicFn(subscr, DPI_SUCCESS, &error);
2088
- }
2089
-