Em Quinta 27 Abril 2006 19:23, Baruch escreveu:
> Still, whoever uses UnicodeCol should be wary of the case when the
> string is truncated. It leads to exceptions you don't normally expect.

I'm using UnicodeCol here with PostgreSQL and I've just written a test case.  
Lets see what happens here:

===============================================================================
#!/bin/python
# -*- coding: utf-8 -*-

import sqlobject
#!/bin/python
# -*- coding: utf-8 -*-

import sqlobject

conn_str = 'postgres://godoy:[EMAIL PROTECTED]/test_unicode'
connection = sqlobject.connectionForURI(conn_str)
sqlobject.sqlhub.processConnection = connection

class MyTestClass(sqlobject.SQLObject):
    class sqlmeta:
        table = 'test_unicode_table'

    test_column = sqlobject.UnicodeCol(length = 5)


test123 = MyTestClass(test_column = u'áéíóú')
print test123
print test123.test_column
===============================================================================

And here's the output

===============================================================================
[EMAIL PROTECTED] ~/tmp/tempo % python tempo.py
<MyTestClass 1L test_column="u'\\xe1\\xe9\\xed\\xf...'">
áéíóú
[EMAIL PROTECTED] ~/tmp/tempo % 
===============================================================================

Just to be sure, here's what I get in PostgreSQL after a few runs:

===============================================================================
test_unicode=# select * from test_unicode_table;
 id | test_column 
----+-------------
  1 | áéíóú
  2 | áéíóú
  3 | áéíóú
  4 | áéíóú
  5 | áéíóú
  6 | áéíóú
(6 registros)

test_unicode=# 
===============================================================================

And here's the table structure to corroborate that the size was declared 
correctly:

===============================================================================
test_unicode=# \d test_unicode_table
                                  Tabela "public.test_unicode_table"
   Coluna    |         Tipo         |                          Modificadores    
                      
-------------+----------------------+-----------------------------------------------------------------
 id          | integer              | not null default 
nextval('test_unicode_table_id_seq'::regclass)
 test_column | character varying(5) | 
Índices:
    "test_unicode_table_pkey" PRIMARY KEY, btree (id)

test_unicode=# 
===============================================================================


So, your problem is not with SQL Object but with your database messing with 
things.

Of course, I have setup mine to work with Unicode:

===============================================================================
test_unicode=# \set
VERSION = 'PostgreSQL 8.1.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 
4.0.2 20050901 (prerelease) (SUSE Linux)'
AUTOCOMMIT = 'on'
VERBOSITY = 'default'
PROMPT1 = '%/%R%# '
PROMPT2 = '%/%R%# '
PROMPT3 = '>> '
DBNAME = 'test_unicode'
USER = 'godoy'
HOST = 'internet'
PORT = '5432'
ENCODING = 'UTF8'
HISTSIZE = '500'
LASTOID = '0'
test_unicode=# 
===============================================================================



-- 
Jorge Godoy      <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to