[Monetdb-developers] encoding of strings returned by Python client

Mark Bucciarelli mkbucc at gmail.com
Wed Dec 23 18:24:27 CET 2009


On Tue, Dec 22, 2009 at 9:58 AM, Gijs Molenaar <gijs.molenaar at cwi.nl> wrote:
>
> Just committed the REAL/DOUBLE fix, this encoding
> thingy has to wait until January, sorry.
>

One thing I noticed is that the mapi backend has
some magic to handle both Unicode and UTF-8
strings when passed in.

Enlcosed below is the python script I used to
exercise the encoding machinery.

Thanks!

m

import monetdb.sql
from monetdb.monetdb_exceptions import OperationalError

con = monetdb.sql.connect(username="test", password="test", database="test")
c = con.cursor()
try:
	c.execute('drop table test')
	c.execute('COMMIT')
except OperationalError, e:
	c.execute('ROLLBACK')
	print "drop table test failed:", e
	pass

c.execute('create table test (id int, s varchar(30))')
c.execute('COMMIT')

#
# cafe is in unicode here.
#

cafe  = u"caf" + unichr(0x00E9)

print 'cafe.__repr__()              =', cafe.__repr__()
print 'cafe.encode("utf8").__repr() =', cafe.encode("utf8").__repr__()

c.execute('insert into test values (%s,%s)', (1,cafe))
#c.execute('insert into test values (%s,%s)', (1,cafe.encode("utf8")))
c.execute('COMMIT')

c.execute("select s from test where id = %d" % (1,))
row = c.fetchone()

print row




More information about the developers-list mailing list