Bugs item #1696359, was opened at 2007-04-08 13:36
Message generated for change (Comment added) made by phd
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1696359&group_id=74338
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: SQLObject release (specify)
>Status: Closed
>Resolution: Invalid
Priority: 5
Private: No
Submitted By: Shimizukawa Takayuki (shimi-ta)
>Assigned to: Oleg Broytmann (phd)
Summary: Can not set ForeignKey and Unicode cols at the same time.
Initial Comment:
on SQLObject-0.8.1 py2.4
Can not set ForeignKey and Unicode cols at the same time.
test code::
class Foo(SQLObject):
name = UnicodeCol()
class User(SQLObject):
name = UnicodeCol()
foo = ForeignKey('Foo')
foo1 = Foo(name="Foo1")
foo2 = Foo(name="Foo2")
# raise UnicodeDecodeError
user = User(name=u'\u8ab0\u304b', fooID=u'2')
# raise UnicodeDecodeError
user.set(name=u'\u8ab0\u304b', fooID=u'2')
----------------------------------------------------------------------
>Comment By: Oleg Broytmann (phd)
Date: 2007-04-10 17:33
Message:
Logged In: YES
user_id=4799
Originator: NO
You are passing unicode to the ForeignKey column: fooID=u'2'. You have to
pass ID-type (default is integer). The following program works for me:
from sqlobject import *
__connection__ = "sqlite:/:memory:?debug=1"
class Foo(SQLObject):
name = UnicodeCol()
class User(SQLObject):
name = UnicodeCol()
foo = ForeignKey('Foo')
Foo.createTable()
User.createTable()
foo1 = Foo(name="Foo1")
foo2 = Foo(name="Foo2")
user = User(name=u'\u8ab0\u304b', fooID=2)
user.set(name=u'\u8ab0\u304b', fooID=2)
Output:
1/Query : CREATE TABLE foo (
id INTEGER PRIMARY KEY,
name TEXT
)
1/QueryR : CREATE TABLE foo (
id INTEGER PRIMARY KEY,
name TEXT
)
2/Query : CREATE TABLE user (
id INTEGER PRIMARY KEY,
name TEXT,
foo_id INT CONSTRAINT foo_id_exists REFERENCES foo(id)
)
2/QueryR : CREATE TABLE user (
id INTEGER PRIMARY KEY,
name TEXT,
foo_id INT CONSTRAINT foo_id_exists REFERENCES foo(id)
)
3/QueryIns: INSERT INTO foo (name) VALUES ('Foo1')
3/QueryR : INSERT INTO foo (name) VALUES ('Foo1')
4/QueryOne: SELECT name FROM foo WHERE id = (1)
4/QueryR : SELECT name FROM foo WHERE id = (1)
5/QueryIns: INSERT INTO foo (name) VALUES ('Foo2')
5/QueryR : INSERT INTO foo (name) VALUES ('Foo2')
6/QueryOne: SELECT name FROM foo WHERE id = (2)
6/QueryR : SELECT name FROM foo WHERE id = (2)
7/QueryIns: INSERT INTO user (foo_id, name) VALUES (2, '誰ã')
7/QueryR : INSERT INTO user (foo_id, name) VALUES (2, '誰ã')
8/QueryOne: SELECT name, foo_id FROM user WHERE id = (1)
8/QueryR : SELECT name, foo_id FROM user WHERE id = (1)
9/Query : UPDATE user SET foo_id = (2), name = ('誰ã') WHERE
id = (1)
9/QueryR : UPDATE user SET foo_id = (2), name = ('誰ã') WHERE
id = (1)
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1696359&group_id=74338
|