FAQ
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

Search Discussions

  • Uwe Hoffmann at Sep 8, 2006 at 6:34 pm

    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
  • Richard Schulman at Sep 8, 2006 at 8:02 pm

    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
  • Diez B. Roggisch at Sep 8, 2006 at 6:36 pm

    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
  • Diez B. Roggisch at Sep 8, 2006 at 6:42 pm

    cursor.execute("""select mean_eng_txt from mean
    where mean_id=:arg_1""",{"arg_1"=arg_1})
    Needs quotes of course.

    Diez

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 8, '06 at 6:26p
activeSep 8, '06 at 8:02p
posts5
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase