Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
.. _dpiPoolFunctions:

ODPI-C Pool Functions
---------------------

Pool handles are used to represent session pools. They are created using the
function :func:`dpiPool_create()` and can be closed by calling the function
:func:`dpiPool_close()` or releasing the last reference to the pool by
calling the function :func:`dpiPool_release()`. Pools can be used to create
connections by calling the function :func:`dpiPool_acquireConnection()`.


.. function:: int dpiPool_acquireConnection(dpiPool* pool, \
        const char* userName, uint32_t userNameLength, \
        const char* password, uint32_t passwordLength, \
        dpiConnCreateParams* params, dpiConn** conn)

    Acquires a connection from the pool and returns a reference to it. This
    reference should be released by calling :func:`dpiConn_release()` as soon
    as it is no longer needed, which will also return the connection back to
    the pool for subsequent calls to this function. The connection can be
    returned back to the pool earlier by calling :func:`dpiConn_close()`.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - The pool from which a connection is to be acquired. If the
            reference is NULL or invalid, an error is returned.
        * - ``userName``
          - IN
          - The name of the user used for authenticating the user, as a byte
            string in the encoding used for CHAR data. NULL is also acceptable
            if external authentication is being requested or credentials were
            supplied when the pool was created.
        * - ``userNameLength``
          - IN
          - The length of the userName parameter, in bytes, or 0 if the
            userName parameter is NULL.
        * - ``password``
          - IN
          - The password to use for authenticating the user, as a byte string
            in the encoding used for CHAR data. NULL is also acceptable if
            external authentication is being requested or if credentials were
            supplied when the pool was created.
        * - ``passwordLength``
          - IN
          - The length of the password parameter, in bytes, or 0 if the
            password parameter is NULL.
        * - ``params``
          - IN
          - A pointer to a :ref:`dpiConnCreateParams<dpiConnCreateParams>`
            structure which is used to specify parameters for connection
            creation. NULL is also acceptable in which case all default
            parameters will be used when creating the connection.
        * - ``conn``
          - OUT
          - A reference to the connection that is acquired from the pool.
            This value is populated upon successful completion of this
            function.

.. function:: int dpiPool_addRef(dpiPool* pool)

    Adds a reference to the pool. This is intended for situations where a
    reference to the pool needs to be maintained independently of the reference
    returned when the pool was created.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - The pool to which a reference is to be added. If the reference
            is NULL or invalid, an error is returned.

.. function:: int dpiPool_close(dpiPool* pool, dpiPoolCloseMode closeMode)

    Closes the pool and makes it unusable for further activity.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool which is to be closed. If the reference is
            NULL or invalid, an error is returned.
        * - ``closeMode``
          - IN
          - One or more of the values from the enumeration
            :ref:`dpiPoolCloseMode<dpiPoolCloseMode>`, OR'ed together.

.. function:: int dpiPool_create(const dpiContext* context, \
        const char* userName, uint32_t userNameLength, \
        const char* password, uint32_t passwordLength, \
        const char* connectString, uint32_t connectStringLength, \
        dpiCommonCreateParams* commonParams, \
        dpiPoolCreateParams* createParams, dpiPool** pool)

    Creates a session pool which creates and maintains a group of stateless
    sessions to the database. The main benefit of session pooling is
    performance since making a connection to the database is a time-consuming
    activity, especially when the database is remote.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.
    If a failure occurs, the errorInfo structure is filled in with error
    information.

    .. parameters-table::

        * - ``context``
          - IN
          - The context handle created earlier using the function
            :func:`dpiContext_createWithParams()`. If the handle is NULL or
            invalid, an error is returned.
        * - ``userName``
          - IN
          - The name of the user used for authenticating sessions, as a byte
            string in the encoding used for CHAR data. NULL is also acceptable
            if external authentication is being requested or if a heterogeneous
            pool is being created.
        * - ``userNameLength``
          - IN
          - The length of the userName parameter, in bytes, or 0 if the
            userName parameter is NULL.
        * - ``password``
          - IN
          - The password to use for authenticating sessions, as a byte string
            in the encoding used for CHAR data. NULL is also acceptable if
            external authentication is being requested or if a heterogeneous
            pool is being created.
        * - ``passwordLength``
          - IN
          - The length of the password parameter, in bytes, or 0 if the
            password parameter is NULL.
        * - ``connectString``
          - IN
          - The connect string identifying the database to which connections
            are to be established by the session pool, as a byte string in
            the encoding used for CHAR data. NULL is also acceptable for
            local connections (identified by the environment variable
            ORACLE_SID).
        * - ``connectStringLength``
          - IN
          - The length of the connectString parameter, in bytes, or 0 if the
            connectString parameter is NULL.
        * - ``connectStringLength``
          - IN
          - The length of the connectString parameter, in bytes, or 0 if the
            connectString parameter is NULL.
        * - ``commonParams``
          - IN
          - A pointer to a :ref:`dpiCommonCreateParams<dpiCommonCreateParams>`
            structure which is used to specify context parameters for pool
            creation. NULL is also acceptable in which case all default
            parameters will be used when creating the pool.
        * - ``createParams``
          - IN
          - A pointer to a :ref:`dpiPoolCreateParams<dpiPoolCreateParams>`
            structure which is used to specify parameters for pool creation.
            NULL is also acceptable in which case all default parameters will
            be used for pool creation.
        * - ``pool``
          - OUT
          - A pointer to a reference to the pool that is created. Call
            :func:`dpiPool_release()` when the reference is no longer needed.

.. function:: int dpiPool_getBusyCount(dpiPool* pool, uint32_t* value)

    Returns the number of sessions in the pool that are busy.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool from which the number of busy sessions is
            to be retrieved. If the reference is NULL or invalid, an error is
            returned.
        * - ``value``
          - OUT
          - A pointer to the value which will be populated upon successful
            completion of this function.

.. function:: int dpiPool_getEncodingInfo(dpiPool* pool, \
        dpiEncodingInfo* info)

    Returns the encoding information used by the pool. This will be equivalent
    to the values passed when the pool was created, or the values retrieved
    from the environment variables NLS_LANG and NLS_NCHAR.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool whose encoding information is to be
            retrieved. If the reference is NULL or invalid, an error is
            returned.
        * - ``info``
          - OUT
          - A pointer to a :ref:`dpiEncodingInfo<dpiEncodingInfo>` structure
            which will be populated with the encoding information used by the
            pool.

.. function:: int dpiPool_getGetMode(dpiPool* pool, dpiPoolGetMode* value)

    Returns the mode used for acquiring or getting connections from the pool.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool from which the mode used for acquiring
            connections is to be retrieved. If the reference is NULL or
            invalid an error is returned.
        * - ``value``
          - OUT
          - A pointer to the value which will be populated upon successful
            completion of this function.

.. function:: int dpiPool_getMaxLifetimeSession(dpiPool* pool, \
        uint32_t* value)

    Returns the maximum lifetime a pooled session may exist, in seconds.
    Sessions in use will not be closed. They become candidates for termination
    only when they are released back to the pool and have existed for longer
    then the returned value. Note that termination only occurs when the pool is
    accessed. The value 0 means that there is no maximum length of time that a
    pooled session may exist.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool from which the maximum lifetime of
            sessions is to be retrieved. If the reference is NULL or invalid,
            an error is returned.
        * - ``value``
          - OUT
          - A pointer to the value which will be populated upon successful
            completion of this function.

.. function:: int dpiPool_getMaxSessionsPerShard(dpiPool* pool, \
        uint32_t* value)

    Returns the maximum sessions per shard. This parameter is used for
    balancing shards.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool from which the maximum sessoins per shard
            is to be retrieved. If the refernece is NULL or invalid, an error
            is returned.
        * - ``value``
          - OUT
          - A pointer to the value which will be populated upon successful
            completion of this function.

.. function:: int dpiPool_getOpenCount(dpiPool* pool, uint32_t* value)

    Returns the number of sessions in the pool that are open.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool from which the number of open sessions is
            to be retrieved. If the reference is NULL or invalid, an error is
            returned.
        * - ``value``
          - OUT
          - A pointer to the value which will be populated upon successful
            completion of this function.

.. function:: int dpiPool_getPingInterval(dpiPool* pool, int* value)

    Returns the ping interval duration (in seconds), which is used to check the
    healthiness of idle connections before getting checked out. A negative
    value indicates this check is disabled.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool from which the ping interval is to be
            retrieved. If the reference is NULL or invalid, an error is
            returned.
        * - ``value``
          - OUT
          - A pointer to the value which will be populated upon successful
            completion of this function.

.. function:: int dpiPool_getSodaMetadataCache(dpiPool* pool, int* enabled)

    Returns whether or not the SODA metadata cache is enabled or not.

    The SODA metadata cache requires Oracle Client 21.3, or later. It is also
    available in Oracle Client 19 from 19.11.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool from which the status of the SODA metadata
            cache is to be retrieved. If the reference is NULL or invalid, an
            error is returned.
        * - ``enabled``
          - OUT
          - A pointer to an integer defining whether the SODA metadata cache
            is enabled (1) or not (0), which will be populated upon successful
            completion of this function.

.. function:: int dpiPool_getStmtCacheSize(dpiPool* pool, \
        uint32_t* cacheSize)

    Returns the default size of the statement cache for sessions in the pool,
    in number of statements.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool from which the default size of the
            statement cache is to be retrieved. If the reference is NULL
            or invalid, an error is returned.
        * - ``cacheSize``
          - OUT
          - A pointer to the default size of the statement cache, which will
            be populated upon successful completion of this function.

.. function:: int dpiPool_getTimeout(dpiPool* pool, uint32_t* value)

    Returns the length of time (in seconds) after which idle sessions in the
    pool are terminated. Note that termination only occurs when the pool is
    accessed. A value of 0 means that no ide sessions are terminated.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool from which the timeout for idle sessions
            is to be retrieved. If the reference is NULL or invalid, an error
            is returned.
        * - ``value``
          - OUT
          - A pointer to the value which will be populated upon successful
            completion of this function.

.. function:: int dpiPool_getWaitTimeout(dpiPool* pool, uint32_t* value)

    Returns the amount of time (in milliseconds) that the caller will wait for
    a session to become available in the pool before returning an error.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool from which the wait timeout is to be
            retrieved. If the reference is NULL or invalid, an error is
            returned.
        * - ``value``
          - OUT
          - A pointer to the value which will be populated upon successful
            completion of this function.

.. function:: int dpiPool_reconfigure(dpiPool* pool, uint32_t minSessions, \
        uint32_t maxSesssions, uint32 sessionIncrement)

    Changes pool configuration corresponding to members
    :member:`dpiPoolCreateParams.minSessions`,
    :member:`dpiPoolCreateParams.maxSessions` and
    :member:`dpiPoolCreateParams.sessionIncrement` to the specified values.
    Connections will be created as needed if the value of `minSessions` is
    increased. Connections will be dropped from the pool as they are released
    back to the pool if `minSessions` is decreased.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool which needs to be reconfigured. If the
            reference is NULL or invalid, an error is returned.
        * - ``minSessions``
          - IN
          - New value for the minimum number of sessions that should be
            maintained.
        * - ``maxSessions``
          - IN
          - New value for the maximum number of sessions that may be retained
            in the pool.
        * - ``sessionIncrement``
          - IN
          - New value for the number of sessions that will be created each
            time the pool needs to be expanded.

.. function:: int dpiPool_release(dpiPool* pool)

    Releases a reference to the pool. A count of the references to the pool is
    maintained and when this count reaches zero, the memory associated with the
    pool is freed and the session pool is closed if that has not already
    taken place using the function :func:`dpiPool_close()`.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - The pool from which a reference is to be released. If the
            reference is NULL or invalid, an error is returned.

.. function:: int dpiPool_setAccessToken(dpiPool* pool, \
        dpiAccessToken* accessToken)

    The function is used to manually set the token and private key for a
    session pool. After pool creation it can be used to periodically reset
    the token and private key to avoid the need for the pool token callback
    function
    :member:`accessTokenCallback<dpiPoolCreateParams.accessTokenCallback>` to
    be called during pool growth.

    This function may also be useful for testing. By setting an expired token
    and key the subsequent pool callback function behavior can be seen without
    waiting for normal token expiry.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool where authentication parameters will be
            set. If the pool parameter is NULL or invalid, an error is
            returned.
        * - ``accessToken``
          - IN
          - A pointer to a :ref:`dpiAccessToken<dpiAccessToken>` structure
            which is used to specify parameters for token based authentication.
            If the pointer is NULL, an error is returned.

.. function:: int dpiPool_setGetMode(dpiPool* pool, dpiPoolGetMode value)

    Sets the mode used for acquiring or getting connections from the pool.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool in which the mode used for acquiring
            connections is to be set. If the reference is NULL or invalid, an
            error is returned.
        * - ``value``
          - IN
          - The value to set.

.. function:: int dpiPool_setMaxLifetimeSession(dpiPool* pool, uint32_t value)

    Sets the maximum lifetime a pooled session may exist, in seconds. Sessions
    in use will not be closed. They become candidates for termination only when
    they are released back to the pool and have existed for longer then the
    specified value. Note that termination only occurs when the pool is
    accessed. The value 0 means that there is no maximum length of time that a
    pooled session may exist.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool in which the maximum lifetime of sessions
            is to be set. If the reference is NULL or invalid, an error is
            returned.
        * - ``value``
          - IN
          - The value to set.

.. function:: int dpiPool_setMaxSessionsPerShard(dpiPool* pool, uint32_t value)

    Sets the maximum number of sessions per shard.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool in which the maximum sessions per shard is
            to be set. If the reference is NULL or invalid, an error is
            returned.
        * - ``value``
          - IN
          - The value to set.

.. function:: int dpiPool_setPingInterval(dpiPool* pool, int value)

    Sets the ping interval duration (in seconds) which is used to to check for
    healthiness of sessions. If this time has passed since the last time the
    session was checked out a ping will be performed. A negative value will
    disable this check.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool in which the ping interval is to be set.
            If the reference is NULL or invalid, an error is returned.
        * - ``value``
          - IN
          - The value to set.

.. function:: int dpiPool_setSodaMetadataCache(dpiPool* pool, int enabled)

    Sets whether the SODA metadata cache is enabled or not. Enabling the SODA
    metadata cache can significantly improve the performance of repeated calls
    to methods :func:`dpiSodaDb_createCollection()` (when not specifying a
    value for the metadata parameter) and :func:`dpiSodaDb_openCollection()`.
    Note that the cache can become out of date if changes to the metadata of
    cached collections are made externally.

    The SODA metadata cache requires Oracle Client 21.3, or later. It is also
    available in Oracle Client 19 from 19.11.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool in which the SODA metadata cache is to be
            enabled or disabled. If the reference is NULL or invalid, an error
            is returned.
        * - ``enabled``
          - IN
          - Identifies if the cache should be enabled (1) or not (0).

.. function:: int dpiPool_setStmtCacheSize(dpiPool* pool, uint32_t cacheSize)

    Sets the default size of the statement cache for sessions in the pool.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool in which the default size of the statement
            cache is to be set. If the reference is NULL or invalid, an error
            is returned.
        * - ``cacheSize``
          - IN
          - The new size of the statement cache, in number of statements.

.. function:: int dpiPool_setTimeout(dpiPool* pool, uint32_t value)

    Sets the amount of time (in seconds) after which idle sessions in the
    pool are terminated. Note that termination only occurs when the pool is
    accessed. A value of zero will result in no idle sessions being terminated.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool in which the timeout for idle sessions is
            to be set. If the reference is NULL or invalid, an error is
            returned.
        * - ``value``
          - IN
          - The value to set.

.. function:: int dpiPool_setWaitTimeout(dpiPool* pool, uint32_t value)

    Sets the amount of time (in milliseconds) that the caller should wait for a
    session to be available in the pool before returning with an error.

    The function returns DPI_SUCCESS for success and DPI_FAILURE for failure.

    .. parameters-table::

        * - ``pool``
          - IN
          - A reference to the pool in which the wait timeout is to be set. If
            the reference is NULL or invalid, an error is returned.
        * - ``value``
          - IN
          - The value to set.