Wednesday, September 1, 2010

Django RawQuerySet with Oracle CLOB

Hi there,

I've recently been using the raw() manager method to perform a few
more complex SQL queries on my Oracle DB and this has been working
very nicely. One particular SQL, however, appears to be giving blank
or phantom objects:

raw_query_list = list(tmp_class.object.raw(SELECT TO_CHAR(clob_column)
AS tmp_char, pk AS tmp_pk FROM table_name WHERE conditions))

where the tmp_class consists of:

class tmp_class(models.Model):

tmp_pk = models.IntegerField(primary_key=True)
tmp_char = models.TextField()

class Meta:
managed=False

Running the SQL query through cx_Oracle gives expected results however
when trying to present the list through a template the objects all
appear as blank. I realise that strictly speaking converting CLOB to
VARCHAR2 gives rise to potential issues over string length however in
this case all values in the CLOB column are less than 4000 characters.
My problem is that I am unsure as to where to start debugging. If I
had to guess at what the source of the problem was given the symptoms
I would say that it was something to do with the fact that CLOBs
operate using memory pointers rather than actual values so the phantom
objects are displayed as a result of the pointer being at the end of
the column. I could have made a mistake with the model however so I am
unsure. Any suggestions?

Many thanks as ever.

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

No comments:

Post a Comment