
On Fri, Nov 23, 2007 at 10:40:28PM +0100, Markus Gritsch wrote:
Hi,
is the Python module MonetSQLdb expected to handle unicode? Currently when INSERTing I must make sure that Python unicode types get converted to strings using UTF-8 encoding. Likewise when SELECTing I get UTF-8 encoded strings back. BTW, is it possible to use another encoding than UTF-8 with MonetDB?
The server is UTF-8 only. It could very well be that the nessesary convertions from unicode X -> UTF-8 and UTF-8 to unicode X are missing in the python MonetSQLdb module.
The Python DB API for SQLite allows inserting Python unicode types and yields unicode when selecting.
MySQLdb allows specifying a 'charset' parameter in the connection constructor and uses this charset to automatically encode unicode objects when inserting. It also returns unicode objects.
The following script raises an exception when used with MonetDB:
import MonetSQLdb
x = MonetSQLdb.connect() c = x.cursor()
c.execute('DROP TABLE test') c.execute('CREATE TABLE test(id int, name varchar(20))') c.execute('INSERT INTO test (id, name) VALUES (%s, %s)', (0, u'm')) c.execute("SELECT * FROM test")
This indeed points out that the python module isn't doing all the converts. Niels
value = c.fetchone()[-1] print type(value)
c.close() x.close()
---
Traceback (most recent call last): File "test.py", line 8, in <module> c.execute('INSERT INTO test (id, name) VALUES (%s, %s)', (0, u'm')) File "C:\Python25\lib\site-packages\mdb\MonetSQLdb\cursors.py", line 95, in execute self.errorhandler(self, exc, value) File "C:\Python25\lib\site-packages\mdb\MonetSQLdb\__init__.py", line 77, in defaulterrorhandler raise errorclass, errorvalue RuntimeError: !SELECT: identifier 'm' unknown
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ MonetDB-users mailing list MonetDB-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-users
-- Niels Nes, Centre for Mathematics and Computer Science (CWI) Kruislaan 413, 1098 SJ Amsterdam, The Netherlands room C0.02, phone ++31 20 592-4098, fax ++31 20 592-4312 url: http://www.cwi.nl/~niels e-mail: Niels.Nes@cwi.nl