any cx_Oracle -skip it

Stefan Eischet stefan at eischet.com
Sat Jul 24 19:14:30 CEST 2004


Hi Mike,

you can also just use keyword args like

curs.execute("""\
SELECT *
FROM   table
WHERE  table.field1 = :keyword1
AND    table.field2 = :keyword2
""", keyword1="value1", 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" <mstenzler at ssaris.com> wrote in message
> news:9rULc.45998$DR3.15494 at fe31.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.Connection("user/pword at 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(sqlstr, params)
>
> ## fetch resultset from cursor
> for name in curs.fetchall():
>   print "name: ", name
>
> mike
>
>
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
>
>




More information about the Python-list mailing list