On Aug 19, 11:58 am, Tim Sawyer <list.dja...@calidris.co.uk> wrote:
> No, I don't think you're mistaken, especially if you want to use hints.
>
> I tried this code again today with the django database connection (using
> 1.2 final), and it didn't work.  This only works with cx_Oracle connections.
>
> Seehttp://drumcoder.co.uk/blog/2010/apr/23/output-parameters-cx_oracle-a...

There are several reasons why that snippet doesn't work:

1) Django cursors don't support passing in the bind parameters in a
dictionary.  A sequence type is expected.

2) Django cursors use the '%s' syntax for placeholders, not the ':out'
syntax.

3) The oracle backend automatically trims a trailing semi-colon from
all queries, because its presence causes ordinary queries to fail.  To
prevent it from being trimmed, add some whitespace after the semi-
colon, or add a trailing '/' as in sqlplus if you prefer.

Correcting these three issues, the snippet works as expected in 1.2.

On Aug 19, 12:14 pm, buddhasystem <potek...@bnl.gov> wrote:
> I'm 90% sure that you can't get the cx cursor out of Django connection.
> These are similar but different classes. I tried something like that.

It works like this:

from django.db import connection
django_cursor = connection.cursor()
cx_cursor = django_cursor.cursor

This is internal API, so it could change in the future.

On Aug 18, 2:58 pm, buddhasystem <potek...@bnl.gov> wrote:
> However, both "my" and yours solution suffer from the same defect imho --
> that the ORM machinery of Django is unusable. We are back to manual mapping
> of rows onto objects... Or -- am I mistaken?

The raw query mechanism will do the ORM mapping as long as you match
up the column names correctly when writing the query.  The problem
with that is that you can't use cursor.var() directly, because you
don't have direct access to the particular cursor used to run the
query.

There is some more internal API that may help with this.  You can pass
in as a bind parameter an object that has a "bind_parameter" method
with the signature "def bind_parameter(self, cursor)".  When the
statement is executed, the cursor will call that method, which is
expected to return the actual bind variable, and substitute the bind
variable for the object.

For an example, have a look at the "InsertIdVar" class in django/db/
backends/oracle/base.py, which is used within the "RETURNING INTO"
clause of an insert statement to receive the primary key of the
inserted object.

Hope this helps,
Ian

-- 
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