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.
1 2273
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: - class DBServer:
-
def __init__(self, master):
-
self.master = master
-
-
def Login(self, servername, username, password, database=""):
-
try:
-
self.dbconnect = connect(host=servername, user=username, passwd=password, db=database)
-
except (DatabaseError, OperationalError):
-
self.dbconnect = None
-
self.master.write('Couldn\'t connect to the database named %s on host %s'
-
%(repr(database), repr(servername)))
-
return
-
self.dbcursor = self.dbconnect.cursor()
-
self.Execute('SET autocommit=1')
-
return self.dbconnect
-
-
def DBError(self):
-
"""Remove the current message from the cursor
-
and display it."""
-
try:
-
(error, message) = self.dbcursor.messages.pop()
-
except AttributeError:
-
(error, message) = self.dbconnect.messages.pop()
-
self.master.write('%s #%d: %s' %(str(error).split('.')[-1],
-
message[0], message[1]))
-
-
def Execute(self, query):
-
try:
-
cursor = self.dbcursor
-
now = time()
-
cursor.execute(query)
-
nRows = cursor.rowcount
-
self.master.write(query)
-
self.master.write("%d rows affected: %.2f sec." %(nRows, time() - now))
-
except (DatabaseError, OperationalError):
-
self.DBError()
-
return
-
return cursor
-
-
def DBExists(self, database):
-
"""Return True if database exists"""
-
resultset = self.Execute("show databases").fetchall()
-
## print resultset
-
return (database,) in resultset
-
-
def close(self):
-
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?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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...
| |