Skip to content

Commit c122690

Browse files
Add support for identifying the id of the transaction which spawned the
message, as requested (oracle/odpi#32).
1 parent 26c3a4c commit c122690

4 files changed

Lines changed: 16 additions & 1 deletion

File tree

doc/src/subscription.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ Message Objects
9696
the notification.
9797

9898

99+
.. attribute:: Message.txid
100+
101+
This read-only attribute returns the id of the transaction that generated
102+
the notification.
103+
104+
99105
.. attribute:: Message.queries
100106

101107
This read-only attribute returns a list of message query objects that give

samples/QueryChangeNotification.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def callback(message):
3434
registered = False
3535
return
3636
print("Message database name:", message.dbname)
37+
print("Message tranasction id:", message.txid)
3738
print("Message queries:")
3839
for query in message.queries:
3940
print("--> Query ID:", query.id)

src/Subscription.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef struct {
3434
udt_Subscription *subscription;
3535
dpiEventType type;
3636
PyObject *dbname;
37+
PyObject *txId;
3738
PyObject *tables;
3839
PyObject *queries;
3940
} udt_Message;
@@ -92,6 +93,7 @@ static PyMemberDef g_MessageTypeMembers[] = {
9293
READONLY },
9394
{ "type", T_INT, offsetof(udt_Message, type), READONLY },
9495
{ "dbname", T_OBJECT, offsetof(udt_Message, dbname), READONLY },
96+
{ "txid", T_OBJECT, offsetof(udt_Message, txId), READONLY },
9597
{ "tables", T_OBJECT, offsetof(udt_Message, tables), READONLY },
9698
{ "queries", T_OBJECT, offsetof(udt_Message, queries), READONLY },
9799
{ NULL }
@@ -450,6 +452,12 @@ static int Message_Initialize(udt_Message *self,
450452
message->dbNameLength, encoding);
451453
if (!self->dbname)
452454
return -1;
455+
if (message->txId) {
456+
self->txId = PyBytes_FromStringAndSize(message->txId,
457+
message->txIdLength);
458+
if (!self->txId)
459+
return -1;
460+
}
453461
switch (message->eventType) {
454462
case DPI_EVENT_OBJCHANGE:
455463
self->tables = PyList_New(message->numTables);

0 commit comments

Comments
 (0)