Hans you have clearly thought this through. I already have two patches
pending from you. May I ask you to consolidate your patches with this
one and send it to me? Thank you.

Massimo

On Nov 21, 3:27 pm, Hans Murx <murxun...@googlemail.com> wrote:
> Maybe we can give DAL() an optional extra argument 'db_codec' with
> default 'utf-8'.
>
> >> db = DAL('informix://oli:x...@suse101/stammdat', db_codec='latin-1')    # 
> >> 'latin-1' instead of 'utf-8' here
>
> whenever we retrieve string values as type str from a table we convert
> them to unicode with codec db_codec:
>
> if isinstance(val, str):
>     val = val.decode(db_codec)
> elif isinstance(val, unicode):
>     pass # nothing to do
>
> (as a side-effect this would assure that iso-8859-1 strings from a DB
> are displayed correctly in web-pages with charset=UTF-8)
>
> and then in function gluon/sql.py:sql_represent() we can easily say
> (provided that sql_represent gets an optional extra argument
> 'db_codec' too):
>
> if isinstance(obj, unicode):
>     obj = obj.encode(db_codec)
> elif isinstance(obj, str):
>     obj = obj.decode('utf-8').encode(db_codec)
>
>   Hans
>
> ~~~~~
> On 21 Nov., 16:37, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > Currently you cannot. Support for legacy databases is not on the same
> > foot as support for databases created by web2py. In particular as you
> > point out the encoding is an issue.
>
> > One way around is use a custom field type.
>
> > On Nov 21, 8:58 am, Hans Murx <murxun...@googlemail.com> wrote:
>
> > > example:
>
> > > In [1]: db = DAL('informix://oli:x...@suse101/stammdat')
> > > In [2]: db.define_table("personen",
> > >    ...:     Field("name", length=80),
> > >    ...:     Field("anz", "integer"),
> > >    ...:     primarykey=["name"],
> > >    ...:     migrate=False
> > >    ...: )
> > > In [3]: a = db().select(db.personen.name)[0].name
> > > In [4]: print a
> > > Öläf
> > > In [5]: db(db.personen.name == a)._update(anz=2)
> > > Out[5]: "UPDATE personen SET anz=2 WHERE personen.name='\xc3\x96l
> > > \xc3\xa4f';"
> > > In [6]: print db(db.personen.name == a).update(anz=2)
> > > 0
>
> > > shows that 0 rows were updated although 1 row should have been
> > > updated.
>
> > > I think the cause of this problem is that the values in our database
> > > are not utf-8 but iso-8859-1encoded and web2py explicitly encodes
> > > values to uft-8 in funtion 'sql_represent' (gluon/sql.py) when
> > > creating sql-statemens for updates and inserts.
>
> > > How to talk to iso-8859-1 encoded legacy DBs?
>
> > > Regards,
>
> > >   Hans
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to