Hello All,

I have to store encrypted unicode content in specific database columns
(until now I used sqlalchemy).
Elixir supports column encryption, but I am not able to get back from
the database unicode strings
(to use them directly in a web app)

the following code stores unicode in the db and retrieves unicode
strings from the db, directly.

------------------------
from elixir import *

class Person(Entity):
    name = Field(Unicode)
    password = Field(Unicode)
    ssn = Field(Unicode)
---------------------
# -*- coding: UTF-8 -*-
from elixir import *
from model import *

metadata.bind="postgresql://webuser:1...@localhost:5432/test_db"
metadata.bind.echo=True

setup_all()
create_all()

Person(name=u'Στράτος', password='Στράτος', ssn='Στράτος')

Session.commit()

person = Session.query(Person).first()
print type(person.password)
---------------------
program run output:
Στράτος <type 'unicode'>


The respective code with encryption (it is the example in the source
code):

------------------------

from elixir import *
from elixir.ext.encrypted import acts_as_encrypted

class Person(Entity):
    name = Field(Unicode)
    password = Field(Unicode)
    ssn = Field(Unicode)

    acts_as_encrypted(for_fields=['password', 'ssn'],
                          with_secret='secret')

------------------------
program run output:
Στράτος <type 'str'>


I get also a warning fron SQLA:
 SAWarning: Unicode type received non-unicode bind param value.
  param[key.encode(encoding)] = processors[key](compiled_params[key])

Is this the 'normal' behavior?
Is there a way to get unicode strings from the db directly?
I am using elixir 0.7.1 and sqlalchemy 0.6.4.

The only way to bypass the warning is to use String instead of Unicode
for the encrypted columns and encode to string the unicode inputs.

------------------------
class Person(Entity):
    name = Field(Unicode)
    password = Field(String)
    ssn = Field(String)

    acts_as_encrypted(for_fields=['password', 'ssn'],
                          with_secret='secret')
------------------------
....
Person(name=u'Στράτος', password='Στράτος'.encode('utf-8'),
ssn='Στράτος'.encode('utf-8'))
....
------------------------

Thanks in advance.

Stratos

-- 
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en.

Reply via email to