On Apr 23, 1:59 pm, Tim Sawyer <list.dja...@calidris.co.uk> wrote:
> Hello.
>
> This code works fine:
>
>  >>> import cx_Oracle
>  >>> lDsn = cx_Oracle.makedsn(lDatabaseHost, int(lDatabasePort),
> lDatabaseName)
>  >>> lConnectString = "%s/%...@%s" % (lDatabaseUsername,
> lDatabasePassword, lDsn)
>  >>> lConnection = cx_Oracle.connect(lConnectString)
>  >>> cursor = lConnection.cursor()
>  >>> lOutput = cursor.var(cx_Oracle.STRING)
>  >>> cursor.execute("BEGIN :out := 'N'; END;", {'out' : lOutput})
>  >>> print lOutput
> <cx_Oracle.STRING with value 'N'>
>  >>> print lOutput.getvalue()
> N
>
> However, if I change this to get the connection from Django, it all
> falls in a big heap:
>
>  >>> from django.db import connection
>  >>> cursor = connection.cursor()
>  >>> import cx_Oracle
>  >>> lOutput = cursor.var(cx_Oracle.STRING)
>  >>> cursor.execute("BEGIN :out := 'N'; END;", {'out' : lOutput})
> Traceback (most recent call last):
>    File "<console>", line 1, in <module>
>    File "/dev/HEAD/INTERNAL/websites/Wam3\django\db\backends\util.py",
> line 19, in execute
>      return self.cursor.execute(sql, params)
>    File "/web/djangocourse\django\db\backends\oracle\base.py", line 435,
> in execute
>      query = convert_unicode(query % tuple(args), self.charset)
> TypeError: not all arguments converted during string formatting
>
> Can anyone point me in the direction of how I can fix this?
>
> Cheers,
>
> Tim.


Hi Tim,

Django cursors universally use the 'format' dbapi paramstyle rather
than the 'named' style natively used by cx_Oracle [1].  To convert
your query, replace the parameter markers with %s and pass the
parameters as a list rather than a dictionary.

If you instead want to work with the underlying cx_Oracle cursor
directly, you can access that as cursor.cursor.  However, this is not
documented API, so don't expect it to be stable.  I'm also not sure
whether it works at all with the sqlite3 backend.

HTH,
Ian

[1] http://docs.djangoproject.com/en/1.1/topics/db/sql/#connections-and-cursors

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to