New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change object transaction id #32

Closed
markfinn opened this Issue Aug 21, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@markfinn
Copy link

markfinn commented Aug 21, 2017

The Database Change Notification docs seem to indicate that transaction ID should be available on a change message. I would like to request this be plumbed through to the odpi layer (next I'll ask for it in cx_Oracle.

I see DPI_OCI_ATTR_CHDES_XID exists in the headers, so I've been stumbling around in the code seeing if it is populated.

/tmp/cx_Oracle/odpi ((v2.0.0))$ git diff
diff --git a/include/dpi.h b/include/dpi.h
index d8f8a60..6739766 100644
--- a/include/dpi.h
+++ b/include/dpi.h
@@ -587,6 +587,8 @@ struct dpiSubscrMessage {
     dpiEventType eventType;
     const char *dbName;
     uint32_t dbNameLength;
+    const char *TxID;
+    uint32_t TxIDLength;
     dpiSubscrMessageTable *tables;
     uint32_t numTables;
     dpiSubscrMessageQuery *queries;
diff --git a/src/dpiSubscr.c b/src/dpiSubscr.c
index e35c29d..8eb9cdc 100644
--- a/src/dpiSubscr.c
+++ b/src/dpiSubscr.c
@@ -289,6 +289,13 @@ static int dpiSubscr__populateMessage(dpiSubscr *subscr,
             DPI_OCI_ATTR_CHDES_DBNAME, "get DB name", error) < 0)
         return DPI_FAILURE;
 
+    // determine transaction id
+    if (dpiOci__attrGet(descriptor, DPI_OCI_DTYPE_CHDES,
+            (void*) &message->TxID, &message->TxIDLength,
+            DPI_OCI_ATTR_CHDES_XID, "get transaction id", error) < 0)
+        return DPI_FAILURE;
+
+
     // populate event specific attributes
     switch (message->eventType) {
         case DPI_EVENT_OBJCHANGE:

This seems to give the transaction ID, but not quite correclty. For a transaxction ID of 4.22.470 I get back 0x80 0x00 0x00 0x00 THEN the transaction 0x04 0x00 0x16 0x00 0x68 0x04 0x00 0x00.

In other words if I look in message->TxID+4 I see what seem like a transaction ID.

So, any chance of getting this added, and any idea why my test returned a weird shifted result?

@cjbj cjbj added the enhancement label Aug 22, 2017

@anthony-tuininga

This comment has been minimized.

Copy link
Member

anthony-tuininga commented Sep 14, 2017

I can answer the question about why you got a "weird" result. What is being returned is an OCIRaw pointer, not the actual transaction id! I will add support for this and push it through to cx_Oracle as well -- but I can't guarantee exactly when, of course!

@markfinn

This comment has been minimized.

Copy link
Author

markfinn commented Sep 21, 2017

Thanks! I look forward to it!

And thanks for the tip on OCIRaw pointer. This gives me something to play with while I wait for the real thing. I just went with splitting up the resulting bytes into a tuple of (uint16, uint16, uint32)

anthony-tuininga added a commit that referenced this issue Nov 8, 2017

anthony-tuininga added a commit to oracle/python-cx_Oracle that referenced this issue Nov 8, 2017

@anthony-tuininga

This comment has been minimized.

Copy link
Member

anthony-tuininga commented Nov 8, 2017

I just added code to both ODPI-C and cx_Oracle to support the transaction id, as requested. Give it a whirl and let me know if that does what you intended. Thanks!

@markfinn

This comment has been minimized.

Copy link
Author

markfinn commented Nov 21, 2017

looks good, thanks!

@anthony-tuininga

This comment has been minimized.

Copy link
Member

anthony-tuininga commented Nov 21, 2017

Excellent. I'll mark this as closed then. This enhancement will become part of ODPI-C 2.1 and cx_Oracle 6.1 when they are released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment