473,320 Members | 2,052 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,320 software developers and data experts.

cx_Oracle question

I'm having trouble getting started using Python's cx_Oracle binding to
Oracle XE. In forthcoming programs, I need to set variables within sql
statements based on values read in from flat files. But I don't seem
to be able to get even the following stripped-down test program to
work:

import cx_Oracle
connection = cx_Oracle.connect("username", "password")
cursor = connection.cursor()

arg_1 = 2 #later, arg_1, arg_2, etc. will be read in files

cursor.execute("""select mean_eng_txt from mean
where mean_id=:arg_1""",arg_1)
for row in cursor.fetchone():
print row
cursor.close()
connection.close()

The program above produces the following error message:

C:\pythonapps>python oracle_test.py
Traceback (most recent call last):
File "oracle_test.py", line 7, in ?
cursor.execute('select mean_eng_txt from mean where
mean_id=:arg_1',arg_1)
TypeError: expecting a dictionary, sequence or keyword args

What do I need to do to get this sort of program working?

TIA,
Richard Schulman
For email reply, remove the xx characters
Sep 8 '06 #1
4 9607
Richard Schulman schrieb:
>
cursor.execute("""select mean_eng_txt from mean
where mean_id=:arg_1""",arg_1)
cursor.execute("""select mean_eng_txt from mean
where mean_id=:arg_1""",{"arg_1":arg_1})
Traceback (most recent call last):
File "oracle_test.py", line 7, in ?
cursor.execute('select mean_eng_txt from mean where
mean_id=:arg_1',arg_1)
TypeError: expecting a dictionary, sequence or keyword args
Sep 8 '06 #2
Richard Schulman schrieb:
I'm having trouble getting started using Python's cx_Oracle binding to
Oracle XE. In forthcoming programs, I need to set variables within sql
statements based on values read in from flat files. But I don't seem
to be able to get even the following stripped-down test program to
work:

import cx_Oracle
connection = cx_Oracle.connect("username", "password")
cursor = connection.cursor()

arg_1 = 2 #later, arg_1, arg_2, etc. will be read in files

cursor.execute("""select mean_eng_txt from mean
where mean_id=:arg_1""",arg_1)
for row in cursor.fetchone():
print row
cursor.close()
connection.close()

The program above produces the following error message:

C:\pythonapps>python oracle_test.py
Traceback (most recent call last):
File "oracle_test.py", line 7, in ?
cursor.execute('select mean_eng_txt from mean where
mean_id=:arg_1',arg_1)
TypeError: expecting a dictionary, sequence or keyword args

What do I need to do to get this sort of program working?
Do what it tells you to do: use a dictionary as parameters or
keyword-args. Not sure what they mean by a sequence though.
So it should work like this:
cursor.execute("""select mean_eng_txt from mean
where mean_id=:arg_1""",{arg_1=arg_1})

Diez
Sep 8 '06 #3
cursor.execute("""select mean_eng_txt from mean
where mean_id=:arg_1""",{"arg_1"=arg_1})
Needs quotes of course.

Diez
Sep 8 '06 #4
Richard Schulman:
>cursor.execute("""select mean_eng_txt from mean
where mean_id=:arg_1""",arg_1)
Uwe Hoffman:
>cursor.execute("""select mean_eng_txt from mean
where mean_id=:arg_1""",{"arg_1":arg_1})
R.S.'s error message:
>Traceback (most recent call last):
File "oracle_test.py", line 7, in ?
cursor.execute('select mean_eng_txt from mean where
mean_id=:arg_1',arg_1)
TypeError: expecting a dictionary, sequence or keyword args
Excellent! Vielen Dank, Uwe (and Diez).

This also turned out to work:

cursor.execute("""select mean_eng_txt from mean
where mean_id=:arg_1""",arg_1=arg_1)

Richard Schulman
For email reply, remove the xx part
Sep 8 '06 #5

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

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...
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...
7
by: coolmenu | last post by:
Hi i hava a db ORACLE 10G,a table valid_card (card_no,varchar2(10),now_balance number (12,2)) its'some record in table ('7188','42055.66') i use cx_Oracle to select now_balance from table ...
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...
4
by: infidel | last post by:
I have a stored procedure that has a single output parameter. Why do I have to pass it a string big enough to hold the value it is to receive? Why can't I pass an empty string or None? >>>...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.