473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

cx_oracle capture oracle progress messages

Is it possible, using cx_Oracle to capture the simple messages from oracle, for example, if I am running an insert, in most Oracle tools, it would say '100 rows inserted'. I would like to capture and print these messages in my python program. TIA.
Nov 28 '06 #1
1 2273
bartonc
6,596 Expert 4TB
Is it possible, using cx_Oracle to capture the simple messages from oracle, for example, if I am running an insert, in most Oracle tools, it would say '100 rows inserted'. I would like to capture and print these messages in my python program. TIA.
I had the same problem with MySQL. I solved it by routing the the call to execute through my own cursor like this:


Expand|Select|Wrap|Line Numbers
  1. class DBServer:
  2.     def __init__(self, master):
  3.         self.master = master
  4.  
  5.     def Login(self, servername, username, password, database=""):
  6.         try:
  7.             self.dbconnect = connect(host=servername, user=username, passwd=password, db=database)
  8.         except (DatabaseError, OperationalError):
  9.             self.dbconnect = None
  10.             self.master.write('Couldn\'t connect to the database named %s on host %s'
  11.                               %(repr(database), repr(servername)))
  12.             return
  13.         self.dbcursor = self.dbconnect.cursor()
  14.         self.Execute('SET autocommit=1')
  15.         return self.dbconnect
  16.  
  17.     def DBError(self):
  18.         """Remove the current message from the cursor
  19.            and display it."""
  20.         try:
  21.             (error, message) = self.dbcursor.messages.pop()
  22.         except AttributeError:
  23.             (error, message) = self.dbconnect.messages.pop()
  24.         self.master.write('%s #%d:  %s' %(str(error).split('.')[-1],
  25.                                           message[0], message[1]))
  26.  
  27.     def Execute(self, query):
  28.         try:
  29.             cursor = self.dbcursor
  30.             now = time()
  31.             cursor.execute(query)
  32.             nRows = cursor.rowcount
  33.             self.master.write(query)
  34.             self.master.write("%d rows affected: %.2f sec." %(nRows, time() - now))
  35.         except (DatabaseError, OperationalError):
  36.             self.DBError()
  37.             return
  38.         return cursor
  39.  
  40.     def DBExists(self, database):
  41.         """Return True if database exists"""
  42.         resultset = self.Execute("show databases").fetchall()
  43.         ## print resultset
  44.         return (database,) in resultset
  45.  
  46.     def close(self):
  47.         self.dbconnect.close()
I haven't seen the oracle module interface, but if it comforms the the python API, this should work for you, too. You are using python, right?
Nov 28 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: GrayGeek | last post by:
After cx_Oracle and the related Oracle tools for Python 2.2.3 + Boa-constructor on Win2000, I added "import cx_Oracle" to the top of a test script. It gives me an error about being unable to find...
1
by: Benson, John | last post by:
Hi, I'm a non-Oracle guy just starting to use Python to explore Oracle. I enclose the Python command prompt log for the usage example further down with only the user, password and host names...
8
by: Rodrigo Daunaravicius | last post by:
I can't get this configuration working: cx_Oracle 4.0.1 Oracle 8.0.6 Python 2.3.3 Win NT4.0 SP6fc My first shot at the problem was just running the installation thingie pre-built for...
1
by: Greg Lindstrom | last post by:
>Shouldn't this be '/u01/app/oracle/product/9.2.0' ? Based on the following values, that's what I'd expect. I changed the ORCALE_HOME environment variable to the above suggested value and got a...
1
by: jmdeschamps | last post by:
Hello Having cx_Oracle (an Oracle database connector for Python) used it here where I teach for the last couple of years, and finding it so easy to use (and install) I was taken aback when I got...
0
by: cirudinezidane | last post by:
Hi!! I'd like to install Oracle 10 g express edition over Ubuntu to use with Python 2.4. I have installed Ubuntu, Python 2.4 and Oracle database. I think that I have installed correctly...
7
by: Carl K | last post by:
I am trying to use this: http://python.net/crew/atuining/cx_Oracle/html/cx_Oracle.html it is a real module, right? sudo easy_install cx_Oracle did not easy_install cx_Oracle. ...
1
by: Lukas Ziegler | last post by:
Hi, I want to get an access to an oracle database. For that I found the module cx_oracle (http://www.python.net/crew/atuining/cx_Oracle/) and I have installed the version 'Windows Installer...
3
by: Benjamin Hell | last post by:
Hi! I have a problem with the cx_Oracle module (Oracle database access): On a computer with cx_Oracle version 4.1 (Python 2.4.3, Oracle 10g) I can get query results consisting of strings...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.