forked from oracle/python-cx_Oracle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAQ.c
More file actions
771 lines (710 loc) · 30.2 KB
/
AQ.c
File metadata and controls
771 lines (710 loc) · 30.2 KB
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
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
//-----------------------------------------------------------------------------
// Copyright 2016, 2017, Oracle and/or its affiliates. All rights reserved.
//
// Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
//
// Portions Copyright 2001-2007, Computronix (Canada) Ltd., Edmonton, Alberta,
// Canada. All rights reserved.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// AQ.c
// Implements the enqueue and dequeue options and message properties objects
// used in Advanced Queuing.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// structures used for handling AQ options and message properties
//-----------------------------------------------------------------------------
typedef struct {
PyObject_HEAD
udt_Environment *environment;
OCIAQEnqOptions *handle;
} udt_EnqOptions;
typedef struct {
PyObject_HEAD
udt_Environment *environment;
OCIAQDeqOptions *handle;
} udt_DeqOptions;
typedef struct {
PyObject_HEAD
udt_Environment *environment;
OCIAQMsgProperties *handle;
} udt_MessageProperties;
//-----------------------------------------------------------------------------
// Declaration of methods used for enqueue options
//-----------------------------------------------------------------------------
static udt_EnqOptions *EnqOptions_New(udt_Environment*);
static void EnqOptions_Free(udt_EnqOptions*);
static PyObject *EnqOptions_GetOCIAttr(udt_EnqOptions*, ub4*);
static int EnqOptions_SetOCIAttr(udt_EnqOptions*, PyObject*, ub4*);
//-----------------------------------------------------------------------------
// Declaration of methods used for dequeue options
//-----------------------------------------------------------------------------
static udt_DeqOptions *DeqOptions_New(udt_Environment*);
static void DeqOptions_Free(udt_DeqOptions*);
static PyObject *DeqOptions_GetOCIAttr(udt_DeqOptions*, ub4*);
static int DeqOptions_SetOCIAttr(udt_DeqOptions*, PyObject*, ub4*);
//-----------------------------------------------------------------------------
// Declaration of methods used for message properties
//-----------------------------------------------------------------------------
static udt_MessageProperties *MessageProperties_New(udt_Environment*);
static void MessageProperties_Free(udt_MessageProperties*);
static PyObject *MessageProperties_GetOCIAttr(udt_MessageProperties*, ub4*);
static int MessageProperties_SetOCIAttr(udt_MessageProperties*, PyObject*,
ub4*);
//-----------------------------------------------------------------------------
// constants for OCI attributes
//-----------------------------------------------------------------------------
static ub4 gc_AQAttempts = OCI_ATTR_ATTEMPTS;
static ub4 gc_AQConsumerName = OCI_ATTR_CONSUMER_NAME;
static ub4 gc_AQCorrelation = OCI_ATTR_CORRELATION;
static ub4 gc_AQDelay = OCI_ATTR_DELAY;
static ub4 gc_AQDeliveryMode = OCI_ATTR_MSG_DELIVERY_MODE;
static ub4 gc_AQDeqCondition = OCI_ATTR_DEQCOND;
static ub4 gc_AQDeqMode = OCI_ATTR_DEQ_MODE;
static ub4 gc_AQDeqMsgId = OCI_ATTR_DEQ_MSGID;
static ub4 gc_AQEnqTime = OCI_ATTR_ENQ_TIME;
static ub4 gc_AQExceptionQ = OCI_ATTR_EXCEPTION_QUEUE;
static ub4 gc_AQExpiration = OCI_ATTR_EXPIRATION;
static ub4 gc_AQNavigation = OCI_ATTR_NAVIGATION;
static ub4 gc_AQOriginalMsgId = OCI_ATTR_ORIGINAL_MSGID;
static ub4 gc_AQPriority = OCI_ATTR_PRIORITY;
static ub4 gc_AQState = OCI_ATTR_MSG_STATE;
static ub4 gc_AQTransformation = OCI_ATTR_TRANSFORMATION;
static ub4 gc_AQVisibility = OCI_ATTR_VISIBILITY;
static ub4 gc_AQWait = OCI_ATTR_WAIT;
//-----------------------------------------------------------------------------
// declaration of calculated members for Python type "EnqOptions"
//-----------------------------------------------------------------------------
static PyGetSetDef g_EnqOptionsCalcMembers[] = {
{ "deliverymode", 0, (setter) EnqOptions_SetOCIAttr, 0,
&gc_AQDeliveryMode },
{ "transformation", (getter) EnqOptions_GetOCIAttr,
(setter) EnqOptions_SetOCIAttr, 0, &gc_AQTransformation },
{ "visibility", (getter) EnqOptions_GetOCIAttr,
(setter) EnqOptions_SetOCIAttr, 0, &gc_AQVisibility },
{ NULL }
};
//-----------------------------------------------------------------------------
// declaration of calculated members for Python type "DeqOptions"
//-----------------------------------------------------------------------------
static PyGetSetDef g_DeqOptionsCalcMembers[] = {
{ "condition", (getter) DeqOptions_GetOCIAttr,
(setter) DeqOptions_SetOCIAttr, 0, &gc_AQDeqCondition },
{ "consumername", (getter) DeqOptions_GetOCIAttr,
(setter) DeqOptions_SetOCIAttr, 0, &gc_AQConsumerName },
{ "correlation", (getter) DeqOptions_GetOCIAttr,
(setter) DeqOptions_SetOCIAttr, 0, &gc_AQCorrelation },
{ "deliverymode", 0, (setter) EnqOptions_SetOCIAttr, 0,
&gc_AQDeliveryMode },
{ "mode", (getter) DeqOptions_GetOCIAttr,
(setter) DeqOptions_SetOCIAttr, 0, &gc_AQDeqMode },
{ "msgid", (getter) DeqOptions_GetOCIAttr,
(setter) DeqOptions_SetOCIAttr, 0, &gc_AQDeqMsgId },
{ "navigation", (getter) DeqOptions_GetOCIAttr,
(setter) DeqOptions_SetOCIAttr, 0, &gc_AQNavigation },
{ "transformation", (getter) EnqOptions_GetOCIAttr,
(setter) EnqOptions_SetOCIAttr, 0, &gc_AQTransformation },
{ "visibility", (getter) DeqOptions_GetOCIAttr,
(setter) DeqOptions_SetOCIAttr, 0, &gc_AQVisibility },
{ "wait", (getter) DeqOptions_GetOCIAttr,
(setter) DeqOptions_SetOCIAttr, 0, &gc_AQWait },
{ NULL }
};
//-----------------------------------------------------------------------------
// declaration of calculated members for Python type "MessageProperties"
//-----------------------------------------------------------------------------
static PyGetSetDef g_MessagePropertiesCalcMembers[] = {
{ "attempts", (getter) MessageProperties_GetOCIAttr, 0, 0,
&gc_AQAttempts },
{ "correlation", (getter) MessageProperties_GetOCIAttr,
(setter) MessageProperties_SetOCIAttr, 0, &gc_AQCorrelation },
{ "delay", (getter) MessageProperties_GetOCIAttr,
(setter) MessageProperties_SetOCIAttr, 0, &gc_AQDelay },
{ "deliverymode", (getter) MessageProperties_GetOCIAttr, 0, 0,
&gc_AQDeliveryMode },
{ "enqtime", (getter) MessageProperties_GetOCIAttr, 0, 0, &gc_AQEnqTime },
{ "exceptionq", (getter) MessageProperties_GetOCIAttr,
(setter) MessageProperties_SetOCIAttr, 0, &gc_AQExceptionQ },
{ "expiration", (getter) MessageProperties_GetOCIAttr,
(setter) MessageProperties_SetOCIAttr, 0, &gc_AQExpiration },
{ "msgid", (getter) MessageProperties_GetOCIAttr,
(setter) MessageProperties_SetOCIAttr, 0, &gc_AQOriginalMsgId },
{ "priority", (getter) MessageProperties_GetOCIAttr,
(setter) MessageProperties_SetOCIAttr, 0, &gc_AQPriority },
{ "state", (getter) MessageProperties_GetOCIAttr, 0, 0, &gc_AQState },
{ NULL }
};
//-----------------------------------------------------------------------------
// Python type declarations
//-----------------------------------------------------------------------------
static PyTypeObject g_EnqOptionsType = {
PyVarObject_HEAD_INIT(NULL, 0)
"cx_Oracle.EnqOptions", // tp_name
sizeof(udt_EnqOptions), // tp_basicsize
0, // tp_itemsize
(destructor) EnqOptions_Free, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
0, // tp_compare
0, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
0, // tp_hash
0, // tp_call
0, // tp_str
0, // tp_getattro
0, // tp_setattro
0, // tp_as_buffer
Py_TPFLAGS_DEFAULT, // tp_flags
0, // tp_doc
0, // tp_traverse
0, // tp_clear
0, // tp_richcompare
0, // tp_weaklistoffset
0, // tp_iter
0, // tp_iternext
0, // tp_methods
0, // tp_members
g_EnqOptionsCalcMembers, // tp_getset
0, // tp_base
0, // tp_dict
0, // tp_descr_get
0, // tp_descr_set
0, // tp_dictoffset
0, // tp_init
0, // tp_alloc
0, // tp_new
0, // tp_free
0, // tp_is_gc
0 // tp_bases
};
static PyTypeObject g_DeqOptionsType = {
PyVarObject_HEAD_INIT(NULL, 0)
"cx_Oracle.DeqOptions", // tp_name
sizeof(udt_DeqOptions), // tp_basicsize
0, // tp_itemsize
(destructor) DeqOptions_Free, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
0, // tp_compare
0, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
0, // tp_hash
0, // tp_call
0, // tp_str
0, // tp_getattro
0, // tp_setattro
0, // tp_as_buffer
Py_TPFLAGS_DEFAULT, // tp_flags
0, // tp_doc
0, // tp_traverse
0, // tp_clear
0, // tp_richcompare
0, // tp_weaklistoffset
0, // tp_iter
0, // tp_iternext
0, // tp_methods
0, // tp_members
g_DeqOptionsCalcMembers, // tp_getset
0, // tp_base
0, // tp_dict
0, // tp_descr_get
0, // tp_descr_set
0, // tp_dictoffset
0, // tp_init
0, // tp_alloc
0, // tp_new
0, // tp_free
0, // tp_is_gc
0 // tp_bases
};
static PyTypeObject g_MessagePropertiesType = {
PyVarObject_HEAD_INIT(NULL, 0)
"cx_Oracle.MessageProperties", // tp_name
sizeof(udt_MessageProperties), // tp_basicsize
0, // tp_itemsize
(destructor) MessageProperties_Free,// tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
0, // tp_compare
0, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
0, // tp_hash
0, // tp_call
0, // tp_str
0, // tp_getattro
0, // tp_setattro
0, // tp_as_buffer
Py_TPFLAGS_DEFAULT, // tp_flags
0, // tp_doc
0, // tp_traverse
0, // tp_clear
0, // tp_richcompare
0, // tp_weaklistoffset
0, // tp_iter
0, // tp_iternext
0, // tp_methods
0, // tp_members
g_MessagePropertiesCalcMembers, // tp_getset
0, // tp_base
0, // tp_dict
0, // tp_descr_get
0, // tp_descr_set
0, // tp_dictoffset
0, // tp_init
0, // tp_alloc
0, // tp_new
0, // tp_free
0, // tp_is_gc
0 // tp_bases
};
//-----------------------------------------------------------------------------
// EnqOptions_New()
// Create a new enqueue options object.
//-----------------------------------------------------------------------------
static udt_EnqOptions *EnqOptions_New(
udt_Environment *env) // environment in which to create
{
udt_EnqOptions *self;
sword status;
self = (udt_EnqOptions*) g_EnqOptionsType.tp_alloc(&g_EnqOptionsType, 0);
if (!self)
return NULL;
Py_INCREF(env);
self->environment = env;
status = OCIDescriptorAlloc(env->handle, (dvoid**) &self->handle,
OCI_DTYPE_AQENQ_OPTIONS, 0, 0);
if (Environment_CheckForError(env, status, "EnqOptions_New()") < 0) {
Py_DECREF(self);
return NULL;
}
return self;
}
//-----------------------------------------------------------------------------
// EnqOptions_Free()
// Free the memory associated with the enqueue options object.
//-----------------------------------------------------------------------------
static void EnqOptions_Free(
udt_EnqOptions *self) // object to free
{
if (self->handle)
OCIDescriptorFree(self->handle, OCI_DTYPE_AQENQ_OPTIONS);
Py_CLEAR(self->environment);
Py_TYPE(self)->tp_free((PyObject*) self);
}
//-----------------------------------------------------------------------------
// EnqOptions_GetOCIAttr()
// Get the value of the OCI attribute.
//-----------------------------------------------------------------------------
static PyObject *EnqOptions_GetOCIAttr(
udt_EnqOptions *self, // options object
ub4 *attribute) // OCI attribute type
{
ub4 valueLength, ub4Value;
dvoid *ociValue = NULL;
char *textValue;
sword status;
// get the value from the OCI
switch (*attribute) {
case OCI_ATTR_VISIBILITY:
ociValue = &ub4Value;
break;
case OCI_ATTR_TRANSFORMATION:
ociValue = &textValue;
break;
};
status = OCIAttrGet(self->handle, OCI_DTYPE_AQENQ_OPTIONS, ociValue,
&valueLength, *attribute, self->environment->errorHandle);
if (Environment_CheckForError(self->environment, status,
"EnqOptions_GetOCIAttr()") < 0)
return NULL;
if (*attribute == gc_AQTransformation) {
if (!textValue)
Py_RETURN_NONE;
return cxString_FromEncodedString(textValue, valueLength,
self->environment->encoding);
}
return PyInt_FromLong(ub4Value);
}
//-----------------------------------------------------------------------------
// EnqOptions_SetOCIAttr()
// Set the value of the OCI attribute.
//-----------------------------------------------------------------------------
static int EnqOptions_SetOCIAttr(
udt_EnqOptions *self, // options object
PyObject *value, // value to set
ub4 *attribute) // OCI attribute type
{
dvoid *ociValue = NULL;
ub4 valueLength = 0;
udt_Buffer buffer;
ub4 ub4Value;
ub2 ub2Value;
sword status;
switch (*attribute) {
case OCI_ATTR_MSG_DELIVERY_MODE:
ub2Value = (ub2) PyInt_AsLong(value);
if (PyErr_Occurred())
return -1;
ociValue = &ub2Value;
break;
case OCI_ATTR_VISIBILITY:
ub4Value = (ub4) PyInt_AsLong(value);
if (PyErr_Occurred())
return -1;
ociValue = &ub4Value;
break;
case OCI_ATTR_TRANSFORMATION:
if (cxBuffer_FromObject(&buffer, value,
self->environment->encoding) < 0)
return -1;
ociValue = (dvoid*) buffer.ptr;
valueLength = (ub4) buffer.size;
break;
};
status = OCIAttrSet(self->handle, OCI_DTYPE_AQENQ_OPTIONS,
ociValue, valueLength, *attribute, self->environment->errorHandle);
if (*attribute == gc_AQTransformation)
cxBuffer_Clear(&buffer);
if (Environment_CheckForError(self->environment, status,
"EnqOptions_SetOCIAttr()") < 0)
return -1;
return 0;
}
//-----------------------------------------------------------------------------
// DeqOptions_New()
// Create a new dequeue options object.
//-----------------------------------------------------------------------------
static udt_DeqOptions *DeqOptions_New(
udt_Environment *env) // environment in which to create
{
udt_DeqOptions *self;
sword status;
self = (udt_DeqOptions*) g_DeqOptionsType.tp_alloc(&g_DeqOptionsType, 0);
if (!self)
return NULL;
Py_INCREF(env);
self->environment = env;
status = OCIDescriptorAlloc(env->handle, (dvoid**) &self->handle,
OCI_DTYPE_AQDEQ_OPTIONS, 0, 0);
if (Environment_CheckForError(env, status, "DeqOptions_New()") < 0) {
Py_DECREF(self);
return NULL;
}
return self;
}
//-----------------------------------------------------------------------------
// DeqOptions_Free()
// Free the memory associated with the dequeue options object.
//-----------------------------------------------------------------------------
static void DeqOptions_Free(
udt_DeqOptions *self) // object to free
{
if (self->handle)
OCIDescriptorFree(self->handle, OCI_DTYPE_AQDEQ_OPTIONS);
Py_CLEAR(self->environment);
Py_TYPE(self)->tp_free((PyObject*) self);
}
//-----------------------------------------------------------------------------
// DeqOptions_GetOCIAttr()
// Get the value of the OCI attribute.
//-----------------------------------------------------------------------------
static PyObject *DeqOptions_GetOCIAttr(
udt_DeqOptions *self, // options object
ub4 *attribute) // OCI attribute type
{
ub4 valueLength, ub4Value;
dvoid *ociValue = NULL;
char *rawValuePtr;
OCIRaw *rawValue;
char *textValue;
sword status;
// get the value from the OCI
switch (*attribute) {
case OCI_ATTR_DEQ_MODE:
case OCI_ATTR_NAVIGATION:
case OCI_ATTR_VISIBILITY:
case OCI_ATTR_WAIT:
ociValue = &ub4Value;
break;
case OCI_ATTR_CONSUMER_NAME:
case OCI_ATTR_CORRELATION:
case OCI_ATTR_DEQCOND:
case OCI_ATTR_TRANSFORMATION:
ociValue = &textValue;
break;
case OCI_ATTR_DEQ_MSGID:
rawValue = NULL;
ociValue = &rawValue;
break;
};
status = OCIAttrGet(self->handle, OCI_DTYPE_AQDEQ_OPTIONS, ociValue,
&valueLength, *attribute, self->environment->errorHandle);
if (Environment_CheckForError(self->environment, status,
"DeqOptions_GetOCIAttr()") < 0)
return NULL;
if (ociValue == &textValue) {
if (!textValue)
Py_RETURN_NONE;
return cxString_FromEncodedString(textValue, valueLength,
self->environment->encoding);
} else if (ociValue == &rawValue) {
if (!rawValue)
Py_RETURN_NONE;
rawValuePtr = (char*) OCIRawPtr(self->environment->handle, rawValue);
valueLength = OCIRawSize(self->environment->handle, rawValue);
return PyBytes_FromStringAndSize(rawValuePtr, valueLength);
}
return PyInt_FromLong(ub4Value);
}
//-----------------------------------------------------------------------------
// DeqOptions_SetOCIAttr()
// Set the value of the OCI attribute.
//-----------------------------------------------------------------------------
static int DeqOptions_SetOCIAttr(
udt_DeqOptions *self, // options object
PyObject *value, // value to set
ub4 *attribute) // OCI attribute type
{
Py_ssize_t rawValueLength;
OCIRaw *rawValue = NULL;
dvoid *ociValue = NULL;
ub4 valueLength = 0;
udt_Buffer buffer;
char *rawValuePtr;
ub4 ub4Value;
ub2 ub2Value;
sword status;
cxBuffer_Init(&buffer);
switch (*attribute) {
case OCI_ATTR_MSG_DELIVERY_MODE:
ub2Value = (ub2) PyInt_AsLong(value);
if (PyErr_Occurred())
return -1;
ociValue = &ub2Value;
break;
case OCI_ATTR_DEQ_MODE:
case OCI_ATTR_NAVIGATION:
case OCI_ATTR_VISIBILITY:
case OCI_ATTR_WAIT:
ub4Value = (ub4) PyInt_AsLong(value);
if (PyErr_Occurred())
return -1;
ociValue = &ub4Value;
break;
case OCI_ATTR_CONSUMER_NAME:
case OCI_ATTR_CORRELATION:
case OCI_ATTR_DEQCOND:
case OCI_ATTR_TRANSFORMATION:
if (cxBuffer_FromObject(&buffer, value,
self->environment->encoding) < 0)
return -1;
ociValue = (dvoid*) buffer.ptr;
valueLength = (ub4) buffer.size;
break;
case OCI_ATTR_DEQ_MSGID:
if (PyBytes_AsStringAndSize(value, &rawValuePtr,
&rawValueLength) < 0)
return -1;
status = OCIRawAssignBytes(self->environment->handle,
self->environment->errorHandle, (const ub1*) rawValuePtr,
(ub4) rawValueLength, &rawValue);
if (Environment_CheckForError(self->environment, status,
"DeqOptions_SetOCIAttr(): assign raw value") < 0)
return -1;
ociValue = (dvoid*) &rawValue;
valueLength = OCIRawSize(self->environment->handle, rawValue);
break;
};
status = OCIAttrSet(self->handle, OCI_DTYPE_AQDEQ_OPTIONS,
ociValue, valueLength, *attribute, self->environment->errorHandle);
cxBuffer_Clear(&buffer);
if (rawValue)
OCIRawResize(self->environment->handle, self->environment->errorHandle,
0, &rawValue);
if (Environment_CheckForError(self->environment, status,
"DeqOptions_SetOCIAttr(): set value") < 0)
return -1;
return 0;
}
//-----------------------------------------------------------------------------
// MessageProperties_New()
// Create a new dequeue options object.
//-----------------------------------------------------------------------------
static udt_MessageProperties *MessageProperties_New(
udt_Environment *env) // environment in which to create
{
udt_MessageProperties *self;
sword status;
self = (udt_MessageProperties*)
g_MessagePropertiesType.tp_alloc(&g_MessagePropertiesType, 0);
if (!self)
return NULL;
Py_INCREF(env);
self->environment = env;
status = OCIDescriptorAlloc(env->handle, (dvoid**) &self->handle,
OCI_DTYPE_AQMSG_PROPERTIES, 0, 0);
if (Environment_CheckForError(env, status,
"MessageProperties_New()") < 0) {
Py_DECREF(self);
return NULL;
}
return self;
}
//-----------------------------------------------------------------------------
// MessageProperties_Free()
// Free the memory associated with the message properties object.
//-----------------------------------------------------------------------------
static void MessageProperties_Free(
udt_MessageProperties *self) // object to free
{
if (self->handle)
OCIDescriptorFree(self->handle, OCI_DTYPE_AQMSG_PROPERTIES);
Py_CLEAR(self->environment);
Py_TYPE(self)->tp_free((PyObject*) self);
}
//-----------------------------------------------------------------------------
// MessageProperties_GetOCIAttr()
// Get the value of the OCI attribute.
//-----------------------------------------------------------------------------
static PyObject *MessageProperties_GetOCIAttr(
udt_MessageProperties *self, // options object
ub4 *attribute) // OCI attribute type
{
ub4 valueLength, ub4Value;
dvoid *ociValue = NULL;
char *rawValuePtr;
OCIDate dateValue;
OCIRaw *rawValue;
char *textValue;
sb4 sb4Value;
ub2 ub2Value;
sword status;
// get the value from the OCI
switch (*attribute) {
case OCI_ATTR_MSG_DELIVERY_MODE:
ociValue = &ub2Value;
break;
case OCI_ATTR_ATTEMPTS:
case OCI_ATTR_DELAY:
case OCI_ATTR_EXPIRATION:
case OCI_ATTR_PRIORITY:
ociValue = &sb4Value;
break;
case OCI_ATTR_MSG_STATE:
ociValue = &ub4Value;
break;
case OCI_ATTR_CORRELATION:
case OCI_ATTR_EXCEPTION_QUEUE:
ociValue = &textValue;
break;
case OCI_ATTR_ENQ_TIME:
ociValue = &dateValue;
break;
case OCI_ATTR_ORIGINAL_MSGID:
rawValue = NULL;
ociValue = &rawValue;
break;
};
status = OCIAttrGet(self->handle, OCI_DTYPE_AQMSG_PROPERTIES, ociValue,
&valueLength, *attribute, self->environment->errorHandle);
if (Environment_CheckForError(self->environment, status,
"MessageProperties_GetOCIAttr()") < 0)
return NULL;
if (ociValue == &textValue) {
if (!textValue)
Py_RETURN_NONE;
return cxString_FromEncodedString(textValue, valueLength,
self->environment->encoding);
} else if (ociValue == &rawValue) {
if (!rawValue)
Py_RETURN_NONE;
rawValuePtr = (char*) OCIRawPtr(self->environment->handle, rawValue);
valueLength = OCIRawSize(self->environment->handle, rawValue);
return PyBytes_FromStringAndSize(rawValuePtr, valueLength);
} else if (ociValue == &dateValue)
return OracleDateToPythonDate(&vt_DateTime, &dateValue);
else if (ociValue == &ub2Value)
return PyInt_FromLong(ub2Value);
else if (ociValue == &sb4Value)
return PyInt_FromLong(sb4Value);
return PyInt_FromLong(ub4Value);
}
//-----------------------------------------------------------------------------
// MessageProperties_SetOCIAttr()
// Set the value of the OCI attribute.
//-----------------------------------------------------------------------------
static int MessageProperties_SetOCIAttr(
udt_MessageProperties *self, // options object
PyObject *value, // value to set
ub4 *attribute) // OCI attribute type
{
Py_ssize_t rawValueLength;
OCIRaw *rawValue = NULL;
dvoid *ociValue = NULL;
ub4 valueLength = 0;
udt_Buffer buffer;
char *rawValuePtr;
ub4 ub4Value;
ub2 ub2Value;
sword status;
cxBuffer_Init(&buffer);
switch (*attribute) {
case OCI_ATTR_MSG_DELIVERY_MODE:
ub2Value = (ub2) PyInt_AsLong(value);
if (PyErr_Occurred())
return -1;
ociValue = &ub2Value;
break;
case OCI_ATTR_DEQ_MODE:
case OCI_ATTR_NAVIGATION:
case OCI_ATTR_VISIBILITY:
case OCI_ATTR_WAIT:
ub4Value = (ub4) PyInt_AsLong(value);
if (PyErr_Occurred())
return -1;
ociValue = &ub4Value;
break;
case OCI_ATTR_CONSUMER_NAME:
case OCI_ATTR_CORRELATION:
case OCI_ATTR_DEQCOND:
case OCI_ATTR_TRANSFORMATION:
if (cxBuffer_FromObject(&buffer, value,
self->environment->encoding) < 0)
return -1;
ociValue = (dvoid*) buffer.ptr;
valueLength = (ub4) buffer.size;
break;
case OCI_ATTR_DEQ_MSGID:
if (PyBytes_AsStringAndSize(value, &rawValuePtr,
&rawValueLength) < 0)
return -1;
status = OCIRawAssignBytes(self->environment->handle,
self->environment->errorHandle, (const ub1*) rawValuePtr,
(ub4) rawValueLength, &rawValue);
if (Environment_CheckForError(self->environment, status,
"MessageProperties_SetOCIAttr(): assign raw value") < 0)
return -1;
ociValue = (dvoid*) &rawValue;
valueLength = OCIRawSize(self->environment->handle, rawValue);
break;
};
status = OCIAttrSet(self->handle, OCI_DTYPE_AQMSG_PROPERTIES,
ociValue, valueLength, *attribute, self->environment->errorHandle);
cxBuffer_Clear(&buffer);
if (rawValue)
OCIRawResize(self->environment->handle, self->environment->errorHandle,
0, &rawValue);
if (Environment_CheckForError(self->environment, status,
"MessageProperties_SetOCIAttr(): set value") < 0)
return -1;
return 0;
}