Bugs item #1243224, was opened at 2005-07-22 21:23
Message generated for change (Comment added) made by phd
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1243224&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: General
Group: SQLObject release (specify)
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Oleg Broytmann (phd)
Summary: crash using a UnicodeCol defined as alternateID.
Initial Comment:
Using SQLObject 0.6.1 with sqlite-3.2.2 and pysqlite-2.0.3.
I have a table with a UnicodeCol defined as alternateID.
sqlobject crashes when using a unicode string.
Example:
===========================================
# -*- coding: iso8859-1 -*-
from sqlobject import SQLiteConnection, SQLObject,
UnicodeCol
from sqlobject.sqlite import builder
SQLiteConnection = builder()
conn = SQLiteConnection('test.db')
class MyTable(SQLObject):
_connection = conn
name = UnicodeCol(alternateID=True)
MyTable.createTable(ifNotExists=True)
row1 = MyTable(name = 'Tom')
row2 = MyTable(name = u'I')
del(row1)
del(row2)
print MyTable.byName('Tom')
print MyTable.byName(u'I')
===========================================
[inigo@inigo ~]$ python test.py
Traceback (most recent call last):
File "test.py", line 14, in ?
row1 = MyTable(name = 'Tom')
File
"/usr/lib/python2.4/site-packages/sqlobject/main.py",
line 890, in __init__
self._create(id, **kw)
File
"/usr/lib/python2.4/site-packages/sqlobject/main.py",
line 923, in _create
self._SO_finishCreate(id)
File
"/usr/lib/python2.4/site-packages/sqlobject/main.py",
line 947, in _SO_finishCreate
id, names, values)
File
"/usr/lib/python2.4/site-packages/sqlobject/dbconnection.py",
line 241, in queryInsertID
return self._runWithConnection(self._queryInsertID,
soInstance, id, names, values)
File
"/usr/lib/python2.4/site-packages/sqlobject/dbconnection.py",
line 125, in _runWithConnection
val = meth(conn, *args)
File
"/usr/lib/python2.4/site-packages/sqlobject/sqlite/sqliteconnection.py",
line 47, in _queryInsertID
c.execute(q)
File
"/usr/src/build/539311-i386/install//usr/lib/python2.4/site-packages/sqlite/main.py",
line 244, in execute
_sqlite.IntegrityError: column name is not unique
[inigo@inigo ~]$
----------------------------------------------------------------------
>Comment By: Oleg Broytmann (phd)
Date: 2006-09-07 19:33
Message:
Logged In: YES
user_id=4799
That's been mostly fixed.
----------------------------------------------------------------------
Comment By: Oleg Broytmann (phd)
Date: 2005-09-13 17:21
Message:
Logged In: YES
user_id=4799
And the second problem is that .byName() requires strings,
so you have to convert unicode to dbEncoding manually. This
works:
print MyTable.byName(u'IЯigo'.encode("UTF-8"))
----------------------------------------------------------------------
Comment By: Oleg Broytmann (phd)
Date: 2005-07-25 09:02
Message:
Logged In: YES
user_id=4799
SQLObject is not yet fully compatible with PySQLite2. Use
PySQLite1 instead. This works for me with PySQLite 1.1.6 and
the latest SQLObject:
# -*- coding: koi8-r -*-
from sqlobject import SQLiteConnection, SQLObject, UnicodeCol
conn = "sqlite:/:memory:?debug=1"
class MyTable(SQLObject):
_connection = conn
name = UnicodeCol(dbEncoding="koi8-r", alternateID=True)
MyTable.createTable(ifNotExists=True)
row1 = MyTable(name = 'Tom')
row2 = MyTable(name = u'Олег')
del(row1)
del(row2)
print MyTable.byName('Tom')
print MyTable.byName(u'Олег')
It prints:
1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE
type='table' AND tbl_name = 'my_table'
1/COMMIT : auto
1/Query : CREATE TABLE my_table (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL UNIQUE
)
1/COMMIT : auto
1/QueryIns: INSERT INTO my_table (name) VALUES ('Tom')
1/COMMIT : auto
1/QueryOne: SELECT name FROM my_table WHERE id = 1
1/COMMIT : auto
1/QueryIns: INSERT INTO my_table (name) VALUES ('Олег')
1/COMMIT : auto
1/QueryOne: SELECT name FROM my_table WHERE id = 2
1/COMMIT : auto
1/QueryOne: SELECT id, name FROM my_table WHERE name = 'Tom'
1/COMMIT : auto
<MyTable 1 name=u'Tom'>
1/QueryOne: SELECT id, name FROM my_table WHERE name = 'Олег'
1/COMMIT : auto
<MyTable 2 name=u'\u041e\u043b\u0435\u0433'>
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1243224&group_id=74338
|