Michael Radziej wrote:
> d) make the database wrapper accept both unicode and bytestrings in
> the models, but always pass unicode strings to the database backend.
> 
> Details:
> 
> For #952 to work, the name of the character encoding has to be
> translated from python naming conventions to these of the used
> backend, and this would need a huge table (see the ticket). It looks
> easy, but it's a major annoyance.
> 
> Now, instead of doing this, how about modifying the database wrapper
> so that it actually tests whether it gets unicode or bytestrings,
> and in the case of bytestrings, decodes it to unicode using
> settings.CHARACTER_SET as encoding? Then it could use unicode to
> talk to its backend. As far as I see, psycopg2 is unicode capable,
> and python-MySQLdb, too.

Just checking if I get it right... You mean something like:

     class CursorWrapper:
       def __init__(self, cursor):
         self.cursor = cursor

       def execute(command, params):
         if isinstance(command, str):
           command = smart_unicode(command)
         params = [smart_unicode(p) for p in params]
         return self.cursor.execute(command, params)

       # Delegate everything else to self.cursor

     class DatabaseWrapper:
       def cursor():
         # ...
         return CursorWrapper()

I like your proposal and in case of non-unicode backends I think your 
approach would work for them too: as well as unicode-capable backends 
should convert everything into unicode themselves unicode-incapable 
backends should convert from DEFAULT_CHARSET to 'utf-8'. Then we can set 
'utf8' for db connection universally.

> Disadvantage: The backend will probably decode it again to get it
> across the wire, to either UTF-8 or settings.DEFAULT_CHARSET (or
> something else), adding overhead to the database communication.

I believe this is really tiny...

> What do you think?

+1 with my nit about DEFAULT_CHARSET -> utf-8 for non-unicode db backends.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to