oracle / python-oracledb

Python driver for Oracle Database conforming to the Python DB API 2.0 specification. This is the renamed, new major release of cx_Oracle
https://oracle.github.io/python-oracledb
Other
339 stars 67 forks source link

TQ MSGID not returned as it was working before #64

Closed rlenka1 closed 2 years ago

rlenka1 commented 2 years ago
  1. What versions are you using?
  1. Is it an error or a hang or a crash?

  2. What error(s) or behavior you are seeing?

  1. Does your application call init_oracle_client()?
  1. Include a runnable Python script that shows the problem.

a=queue.enqone(con.msgproperties(payload=book)) print(a)

rlenka1 commented 2 years ago

Version 1.0 was returning MSGID but new version 1.1 not returning

Tried with PLSQL it is also returning

anthony-tuininga commented 2 years ago

Can you provide a complete script that demonstrates the problem? And include the PL/SQL script as well? I'm not sure which attribute you are referring to. Thanks!

rlenka1 commented 2 years ago

/ This is part of 15. Using Oracle Advanced Queuing (AQ), when we enqueue. If we run below in PLSQL we get the MSGID, same was also happening in the python when we had below in python a=queue.enqone(con.msgproperties(payload=book)) print(a)/

set serveroutput on;
DECLARE
   enqueue_options     DBMS_AQ.enqueue_options_t;
   message_properties  DBMS_AQ.message_properties_t;
   message_handle      RAW(16);
   message             message_typ;
BEGIN
  FOR groupno in 1..3 LOOP
    FOR msgno in 1..3 LOOP
      message := message_typ(
               004,
               'GROUP ' || groupno, 
               'Message ' || msgno || ' in group ' || groupno);
      DBMS_AQ.ENQUEUE(
         queue_name             => 'group_queue',
         enqueue_options        => enqueue_options,
         message_properties     => message_properties,
         payload                => message,
         msgid                  => message_handle);
         DBMS_OUTPUT.PUT_LINE(message_handle);

    END LOOP;
    COMMIT; 
  END LOOP;
END;
/

***Python code**

con = oracledb.connect(user=p_username, password=p_password, dsn="teqodb_medium", 
                       config_dir="C:\\Users\\User\\Documents\\OracleAutonomousDB\\teqodb\\teqodb_extract",
                       wallet_location="C:\\Users\\User\\Documents\\OracleAutonomousDB\\teqodb\\teqodb_extract",
                       wallet_password=p_walletpass)

# In[34]:

print(con)

# In[35]:

book_type = con.gettype("MESSAGE_TYPE")

# In[36]:

queue = con.queue("OBJTYPE_TEQ5", book_type)

# In[37]:

queue.enqoptions.visibility = oracledb.ENQ_IMMEDIATE

# In[38]:

book = book_type.newobject()

# In[39]:

book.SUBJECT = "Hi There1"

# In[40]:

book.TEXT = "I am Python"

# In[44]:

a = queue.enqone(con.msgproperties(payload=book))

# In[42]:

print(a)

*** now the print just gives "None" , earlier it was returning MSGIDg

anthony-tuininga commented 2 years ago

Hmm, I don't see any changes between 1.0 and 1.1 that would suggest print(a) would have produced anything except None. I tried with version 1.0 and confirmed that was indeed the case. You can manipulate the object_aq.py sample like I did to verify that fact. Looks to me like you want to do this, though:

msg = con.msgproperties(payload=book)
queue.enqone(msg)
print("msgid:", msg.msgid)
rlenka1 commented 2 years ago

Thanks.

The output now i get from python is

msgid: b'\xe9\x1eo@mQn\xfc\xe0S#\x14\x00\nSi' msgid: b'\xe9\x1eo@mSn\xfc\xe0S#\x14\x00\nSi' msgid: b'\xe9\x1eo@mUn\xfc\xe0S#\x14\x00\nSi' msgid: b'\xe9\x1eo@mWn\xfc\xe0S#\x14\x00\nSi' msgid: b'\xe9\x1eo@mYn\xfc\xe0S#\x14\x00\nSi' msgid: b'\xe9\x1eo@m[n\xfc\xe0S#\x14\x00\nSi'

But in DB via PLSQL i get E91E6F406D526EFCE0532314000A5369 E91E6F406D536EFCE0532314000A5369 E91E6F406D546EFCE0532314000A5369 E91E6F406D556EFCE0532314000A5369 E91E6F406D566EFCE0532314000A5369 E91E6F406D576EFCE0532314000A5369

Something needs to do with conversion maybe if you can help

anthony-tuininga commented 2 years ago

Those look to be the same. You can confirm that by using this code:

msg = con.msgproperties(payload=book)
queue.enqone(msg)
print("msgid:", msg.msgid.hex().upper())
rlenka1 commented 2 years ago

Yes, perfect, thanks for your help, i can reconcile easily now