I tried to run the following (test.py) with the latest stable web2py (i.e.: python web2py.py -S welcome -R test.py) db = DAL('sqlite:///tmp/storage.sqlite') db.define_table('unicode_test', Field('test', 'string')) test_val = unicode('på Facebook', 'utf-8') db.unicode_test.insert(test=test_val) db.commit()
for r in db(db.unicode_test).select(): print r.test, type(r.test) print db.unicode_test[1].test I got på Facebook <type 'str'> på Facebook Paolo On Thursday, November 12, 2015 at 8:03:25 PM UTC+1, Dandelion Mine wrote: > > I tried it on 2.12.3-stable: > >>> db = DAL('sqlite://storage.sqlite') > >>> db._db_codec > 'UTF-8' > >>> db.define_table('unicode_test', Field('test', 'string')) > <Table unicode_test (id,test)> > >>> test_val = unicode('på Facebook', 'utf-8') > >>> db.unicode_test.insert(test=test_val) > 1L > >>> for r in db(db.unicode_test).select(): print r.test, type(r.test) > ... > på Facebook <type 'str'> > >>> db.unicode_test[1].test > 'p\xc3\xa5 Facebook' > >>> db.unicode_test[1].test.decode('utf-8') > u'p\xe5 Facebook' > > On Wednesday, November 11, 2015 at 5:52:47 PM UTC+3, Massimo Di Pierro > wrote: >> >> The strings you get are probably UTF8. Can you confirm? >> >> On Wednesday, 4 November 2015 08:19:41 UTC-6, Dandelion Mine wrote: >>> >>> Hello! >>> According to Web2py book, 'by default web2py uses utf8 character >>> encoding for databases'. I get the contrary results: there are fields with >>> type 'string', mysql shows that they have collation utf8_general_ci, but >>> when I select them with DAL, the type of returned fields are 'str', not >>> 'unicode'. >>> >>> db.define_table('customers', >>> Field('name', 'string')) >>> >>> +-----------+--------------+-----------------+------ >>> | Field | Type | Collation | Null | Key | >>> +-----------+--------------+-----------------+------+ >>> | name | varchar(512) | utf8_general_ci | >>> >>> print type(db(db.tradera_customers).select().first().name) >>> <type 'str'> >>> >>> I tried to remove *.table in databases and to use db_codec parameter for >>> DAL, but nothing changed. >>> >>> Web2py version 2.9.11-stable, Python 2.7.9, MySQL ver 14.14 Distrib >>> 5.5.40 >>> >>> Is it a known bug or I'm doing something wrong? >>> Thanks in advance. >>> >> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.