Unicode question

Jim Hefferon <[email protected]> Fri, 20 Jun 2003 16:16:27 -0400
Newsgroups gmane.comp.python.db.pypgsql.user
Message-ID <[email protected]>
Hello,

I'm having trouble with Unicode.  I have set up the database to use UTF-8.
I am trying to get some non-ASCII strings in there and I am failing.

Here is a short version of the script:
--------------------------------------
#!/usr/bin/python -u
# test unicode support in pyPgSQL
import string;
from pyPgSQL import libpq
from pyPgSQL import PgSQL

dBconnection=PgSQL.connect("::ctanWeb:ftpmaint:")
dBcursor=dBconnection.cursor()

dBcursor.execute("SELECT * FROM authors") 
print dBcursor.fetchone()  # works fine; I'm connected

# these two also work fine
dBcursor.execute("INSERT INTO authors (name,email) VALUES ('Mike Jones','[email protected]')")
dBcursor.execute("INSERT INTO authors (name,email) VALUES (%(name)s,%(email)s)",{'name':'Mike Jones','email':'[email protected]'})

# this does not work
dBcursor.execute("INSERT INTO authors (name,email) VALUES ('Mike Schr\xf6der','[email protected]')")

# I cannot get to run, even
dBcursor.execute("INSERT INTO authors (name,email) VALUES (%(name)s,%(email)s)",{'name':u'Mike Schr\xf6der','email':u'[email protected]'})
-------------------------------------

The line that does not work gives me the error message:

  Traceback (most recent call last):
    File "./test_uni.py", line 25, in ?
      dBcursor.execute("INSERT INTO authors (name,email) VALUES ('Mike Schr\xf6der','[email protected]')")
    File "/usr/lib/python2.2/site-packages/pyPgSQL/PgSQL.py", line 2956, in execute
      raise OperationalError, msg
  libpq.OperationalError: ERROR:  Unicode >= 0x10000 is not supoorted

I cannot make it out: is that a PostgreSQL objection or does it
come from PyPgSQL?  (By the way, the 'supoorted' is not me.)

So my questions are:
  (1) Is Pg unable to take this character?
  (2) What is the right format for a dictionary substitution?  I can't
   get the final line past an ASCII encoding error: ordinal not in range.

Thanks for any help at all; I tried looking in the archives of this list
but I had no luck,
 
Jim Hefferon


-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php