#24012: models.UUIDfield fails on Oracle backend
-------------------------------------+-------------------------------------
Reporter: JorisBenschop | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: oracle, | Triage Stage: Accepted
models.UUIDfield,1.8-alpha |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by JorisBenschop):
I cannot make test databases, so my test are very limited. However, I
created a custom Field that does all I need. It's far from complete
though. Hope this helps. Let me knwo if I can assist anywhere. The
new_sys_guid function breaks if the default DB is not oracle.
{{{
import binascii
def new_sys_guid(as_binary=False):
'''
this retreives a new SYS_GUID value from the database
'''
cursor = connection.cursor()
cursor.execute("SELECT SYS_GUID() FROM DUAL")
sysguidval= cursor.fetchone()[0]
if as_binary:
return(sysguidval)
else:
return rawtohex(sysguidval)
def hextoraw(hexval):
''' mimic the internal oracle hextoraw function'''
return a2b_hex(hexval)
def rawtohex(rawval):
''' mimic the internal oracle rawtohex function'''
return str(b2a_hex(rawval)).upper()
class SYSGUID16Field(models.Field):
default_error_messages = {
'invalid': "'%(value)s' is not a valid SYS_GUID."
}
description = "A connector to the SYS_GUID() fields for Oracle
Backends"
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 16
super(SYSGUID16Field, self).__init__(*args,**kwargs)
def from_db_value(self, value, connection):
#print 'call from_db_value %s' % value
if value is None:
return value
return str(b2a_hex(value)).upper()
def get_internal_type(self):
#print 'call get_internal_value'
return "RAWField"
def db_type(self, connection):
#print 'call db_type'
return 'RAW(16)'
def to_python(self, value):
print 'call to_python: %s' % value
return value
#def get_prep_value(self, value):
#print 'call get_prep_value %s' % value
# return value
def get_db_prep_value(self,value,connection,prepared):
#print 'call get_db_prep_value'
super(SYSGUID16Field,self).get_db_prep_value(value,connection,prepared)
'''
sometimes (specifically with foreign keys) the field content is
not translated to hex.
As there is no easy way to check we make the (dangerous)
assumption that
all the binary fields will have at least one non-hex character.
'''
try:
return connection.Database.Binary(a2b_hex(value))
except TypeError:
return connection.Database.Binary(value)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24012#comment:12>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/071.db4aa4bb65b4549da4e871bf24b4d0c3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.