Quantcast
Channel: SCN: Message List - SAP Adaptive Server Enterprise (SAP ASE) for Custom Applications
Viewing all articles
Browse latest Browse all 3587

Re: Using python to catch server messages

$
0
0

Hi Alexander,

 

In python I have a way to get messages and errors.  This sample shows some ways to do so and we have a messages method in the docs:

 

Connection Object Methods

 

messages()

This is a Python list object to which the module
                appends tuples (exception class and exception object) for all messages that the
                module receives for this connection. An error on any cursor obtained from the same
                connection object, is appended to the messages attribute of the connection object of
                the cursor.

 

    
              

connection.messages()

 

       

Usage example:

 

try:

cur.execute("select ...")

except sybpydb.Error:

for err in cur.connection.messages:

print("Exception %s, Value %s", % err[0], err[1])

 

 

 

Also, on connection:

 

conn = sybpydb.connect(user='sa', password='secret', dsn='servername=pvw71572;charset=cp1252')

for mess in conn.messages:

print("Warning: %s " % mess[1][0])

 

 

And for errors:

try:

cur.execute("raiserror 99999 'This is a raiserror'")

while True:

  row = cur.fetchone()

  if (not row):

   break

except sybpydb.Error as e:

print ('Error: %s' %(e))

 


Cheers,

-Paul


Viewing all articles
Browse latest Browse all 3587

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>