On 12/18/06, Damjan <[EMAIL PROTECTED]> wrote: > > > For example MySQL's Unicode documentation is here > > > > Also note that you need to consider both the encoding of the database > > and the encoding used by the database driver. > > > > If you're using MySQL together with SQLAlchemy, see the following, as > > there are some bugs in MySQLdb that you'll need to work around: > > > > http://www.mail-archive.com/[email protected]/msg00366.html > > Shannon, I've read the therad on the sqlalchemy list.. but I never saw > the output of 'show create table ...'.
Ah, that's because I wasn't in charge of creating the table in my app. There was another app in charge. Here it is: CREATE TABLE IF NOT EXISTS `users` ( `id` bigint(20) UNSIGNED NOT NULL, `username` varchar(255) collate utf8_bin NOT NULL, `email` varchar(255) collate utf8_bin NOT NULL, `password` varchar(64) collate utf8_bin NOT NULL, `firstName` varchar(128) collate utf8_bin NOT NULL default 'n/a', `lastName` varchar(128) collate utf8_bin NOT NULL default 'n/a', `url` varchar(128) collate utf8_bin NOT NULL default 'n/a', `homedirUrl` varchar(128) collate utf8_bin NOT NULL default 'n/a', `admin` tinyint(1) NOT NULL default '0', `creationtime` timestamp NOT NULL default '0000-00-00 00:00:00', `modtime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `email` (`email`), UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; > This is very important because different versions of MySQL might have > different defaults, and your Linux distro might also set it's own > defaults. Yep. Agreed. > The thing is that a conversion can happen in the MySQL C API and in the > MySQL DB too. That's what I was afraid of. > I've been using this code to connect to MySQL > db = MySQLdb.connect(db='test', charset='utf8', use_unicode=True) I've read the code, and setting charset implicitly sets use_unicode, or something like that. > which, as I understand it, tells the MySQL C API to use UTF-8 over the > wire (charset='utf8'), and to use unicode objects on the Python side of > the things (use_unicode=True). Pretty much. use_unicode says to do encoding and decoding for you. charset='utf8' says which encoding to use on the wire, as you say. > But also my unicode test table is > created like this: > CREATE TABLE `test_unicode_table` ( > `id` int(11) NOT NULL auto_increment, > `test_column` varchar(5) collate utf8_unicode_ci default NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 > COLLATE=utf8_unicode_ci By the way, I *wanted* SQLAlchemy to be in charge of encoding and decoding. Then, MySQLdb could just transfer bytes, and be ignorant. However, that didn't work as MySQLdb would end up double encoding things. Now I'm letting MySQLdb do the encoding and decoding as a workaround. Are we on the same page, or am I still lost? Thanks, -jj -- http://jjinux.blogspot.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" 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/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
