From: Gerhard H?r. <gha...@us...> - 2003-07-10 16:05:34
|
Update of /cvsroot/pypgsql/pypgsql In directory sc8-pr-cvs1:/tmp/cvs-serv791 Modified Files: README Log Message: 10JUL2003 gh Added paragraph about the Unicode related parameters of the connect function. Index: README =================================================================== RCS file: /cvsroot/pypgsql/pypgsql/README,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** README 5 Dec 2002 05:34:30 -0000 1.30 --- README 10 Jul 2003 15:36:19 -0000 1.31 *************** *** 1599,1602 **** --- 1599,1639 ---- way to get the object ID of a newly inserted record. + 2.2.5 Unicode support + --------------------- + + pyPgSQL has a few extensions that make it possible to insert Unicode strings + into PostgreSQL and fetch unicode strings instead of byte strings from the + database. + + The module-level connect() function has two Unicode-related parameters: + + - client_encoding + - unicode_results + + *client_encoding* accepts the same parameters as the encode method + of Unicode strings. If you also want to set a policy for encoding + errors, set client_encoding to a tuple, like ("koi8-r", "replace") + + Note that you still must make sure that the PostgreSQL client is + using the same encoding as set with the client_encoding parameter. + This is typically done by issuing a "SET CLIENT_ENCODING TO ..." + SQL statement immediately after creating the connection. + + If you also want to fetch Unicode strings from the database, set + *unicode_results* to 1. + + For example, assuming a database created with *createdb mydb -E UNICODE* and a + table *TEST(V VARCHAR(50))*: + + >>> from pyPgSQL import PgSQL + >>> cx = PgSQL.connect(database="mydb", client_encoding="utf-8", unicode_results=1) + >>> cu = cx.cursor() + >>> cu.execute("set client_encoding to unicode") + >>> cu.execute("insert into test(v) values (%s)", (u'\x99sterreich',)) + >>> cu.execute("select v from test") + >>> cu.fetchone() + [u'\x99sterreich'] + >>> + ================================== 3.0 General Notes and Observations |