473,545 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

any cx_Oracle sample code?

Does anyone have any sample code for the cx_Oracle library?
www.computronix.com

I have the doco and can connect and do simple ops against my database but
I'm struggling with
the correct syntax for implementing bind variables with a cursor.
TIA

Mike

Jul 18 '05 #1
2 6959

"Mike Stenzler" <ms*******@ssar is.com> wrote in message
news:9r******** ***********@fe3 1.usenetserver. com...
Does anyone have any sample code for the cx_Oracle library?
www.computronix.com

I have the doco and can connect and do simple ops against my database but
I'm struggling with
the correct syntax for implementing bind variables with a cursor.

Nevermind...

Some diligent reading of the python DB-API 2.0 yielded the required
knowledge..

import cx_Oracle

## execute wants it's parameters in a dictionary
params = {'val_1':"AA"}

## sql statement uses a bind var style of "named" as default - ":" denotes
bind var
sqlstr = "select name from my.table where id = :val_1"

## open a connection
conn = cx_Oracle.Conne ction("user/pword@server")

## open a cursor
curs = conn.cursor()

## tell Oracle how many rows to fetch
## at a time - default is 1
curs.arraysize = 256

## send the sql statement to Oracle parser for execution
curs.execute(sq lstr, params)

## fetch resultset from cursor
for name in curs.fetchall() :
print "name: ", name

mike

Jul 18 '05 #2
Hi Mike,

you can also just use keyword args like

curs.execute("" "\
SELECT *
FROM table
WHERE table.field1 = :keyword1
AND table.field2 = :keyword2
""", keyword1="value 1", keyword2=17)

instead of passing a dict.

I'm curious: why do you set the arraysize and then do a .fetchall? As I
understand it, fetchall does not look at arraysize, only fetchmany
does, in case you don't supply a size in the fetchmany call (i.e.
curs.fetchmany( 15)); did I miss something?

Cheers,
Stefan
On 22.07.2004, at 23:04, Mike Stenzler wrote:

"Mike Stenzler" <ms*******@ssar is.com> wrote in message
news:9r******** ***********@fe3 1.usenetserver. com...
Does anyone have any sample code for the cx_Oracle library?
www.computronix.com

I have the doco and can connect and do simple ops against my database
but
I'm struggling with
the correct syntax for implementing bind variables with a cursor.

Nevermind...

Some diligent reading of the python DB-API 2.0 yielded the required
knowledge..

import cx_Oracle

## execute wants it's parameters in a dictionary
params = {'val_1':"AA"}

## sql statement uses a bind var style of "named" as default - ":"
denotes
bind var
sqlstr = "select name from my.table where id = :val_1"

## open a connection
conn = cx_Oracle.Conne ction("user/pword@server")

## open a cursor
curs = conn.cursor()

## tell Oracle how many rows to fetch
## at a time - default is 1
curs.arraysize = 256

## send the sql statement to Oracle parser for execution
curs.execute(sq lstr, params)

## fetch resultset from cursor
for name in curs.fetchall() :
print "name: ", name

mike

--
http://mail.python.org/mailman/listinfo/python-list


Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
8958
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 the OCISetDefault entry point in 'oci.dll'. Google says nothing about this error, and neither does the cx_Oracle author. Anyone have a solution...
8
6254
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 win32/python2.3/Oracle8i. It installed with no complaints but I can't import the module (can't find OCIEnvCreate entry point in the OCI.dll library).
1
8490
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 new error!! That's progress, right? I'm now told: cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve service name /usr/bin/sh:...
1
4549
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 an error message telling me it could not load the DLL (complete message below) Third, I've read (on activeState site) about someone else having...
1
4405
by: Maxim Kuleshov | last post by:
Hello! Trying to fetch long varchar2 column and get the following error: cx_Oracle.DatabaseError: column at array pos 0 fetched with error: 1406 i.e. string buffer is not much enough to fetch the string. # fragment of code... myCon = cx_Oracle.connect(user, psw, dsn)
4
5265
by: MooMaster | last post by:
After some google searching on the forum I couldn't find any topics that seemed to relate exactly to my problem, so hopefully someone can help me out... I'm running python 2.4.1 on a local Win2K system and doing some work-related development on an AIX box, and I'm running into a problem using cx_Oracle to add some information to an Oracle...
7
14691
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. http://www.python.org/pypi/cx_Oracle/4.3.1 doesn't give me any clue. I got the source from...
1
2586
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 (Oracle 10g, Python 2.5)'. Now I tried to run the script in the readme file: -------------------------------------------------------------------...
3
4832
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 including non-ASCII characters, e.g. the code example below outputs "é 0xe9" (which is the correct ISO-8859-1 hex code for "é"). On a newer installation...
0
7428
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7941
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7784
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6014
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5354
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5071
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1039
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.