On 03/07/12 17:45, Jan Urbański wrote:
On 29/06/12 00:36, Jan Urbański wrote:
On 27/06/12 13:57, Jan Urbański wrote:
On 27/06/12 11:51, Asif Naeem wrote:
Hi,
On Windows 7 64bit, plpython is causing server crash with the following
test case i.e.
So: I'd add code to translate WINxxx into CPxxx when choosing the Python
to use, change PLy_elog to elog in PLyUnicode_Bytes and leave the
SQL_ASCII case alone, as there were no complaints and people using
SQL_ASCII are asking for it anyway.
Since no one commented, I'll produce a patch to that effect. I believe
this should go into 9.2 given that otherwise PL/Python will basically
crash any database using the CP12xx encoding.
Patch attached. Asif, could you try a few things on a CP1252 database?
First verify if your original test case now works and then try this:
create function enctest() returns text as $$
return b'tr\xc3\xb3spido'.decode('utf-8')
$$ language plpython3u;
select enctest(), encode(convert_to(enctest(), 'utf-8'), 'hex');
Thanks,
Jan
diff --git a/src/pl/plpython/plpy_util.c b/src/pl/plpython/plpy_util.c
new file mode 100644
index 9a4901e..5fafbd1
*** a/src/pl/plpython/plpy_util.c
--- b/src/pl/plpython/plpy_util.c
*************** PLyUnicode_Bytes(PyObject *unicode)
*** 66,80 ****
/*
* Python understands almost all PostgreSQL encoding names, but it doesn't
! * know SQL_ASCII.
*/
! if (GetDatabaseEncoding() == PG_SQL_ASCII)
! serverenc = "ascii";
! else
! serverenc = GetDatabaseEncodingName();
rv = PyUnicode_AsEncodedString(unicode, serverenc, "strict");
! if (rv == NULL)
! PLy_elog(ERROR, "could not convert Python Unicode object to PostgreSQL server encoding");
return rv;
}
--- 66,125 ----
/*
* Python understands almost all PostgreSQL encoding names, but it doesn't
! * know SQL_ASCII and calls the Windows encodings differently.
*/
! switch (GetDatabaseEncoding())
! {
! case PG_SQL_ASCII:
! serverenc = "ascii";
! break;
! case PG_WIN1250:
! serverenc = "cp1250";
! break;
! case PG_WIN1251:
! serverenc = "cp1251";
! break;
! case PG_WIN1252:
! serverenc = "cp1252";
! break;
! case PG_WIN1253:
! serverenc = "cp1253";
! break;
! case PG_WIN1254:
! serverenc = "cp1254";
! break;
! case PG_WIN1255:
! serverenc = "cp1255";
! break;
! case PG_WIN1256:
! serverenc = "cp1256";
! break;
! case PG_WIN1257:
! serverenc = "cp1257";
! break;
! case PG_WIN1258:
! serverenc = "cp1258";
! break;
! case PG_WIN866:
! serverenc = "cp866";
! break;
! case PG_WIN874:
! serverenc = "cp874";
! break;
! default:
! serverenc = GetDatabaseEncodingName();
! break;
! }
!
rv = PyUnicode_AsEncodedString(unicode, serverenc, "strict");
! if (rv == NULL) {
! /*
! * Use a plan elog instead of PLy_elog here to avoid getting in
! * recursion trouble when the traceback formatting functions try doing
! * unicode to bytes conversion.
! */
! elog(ERROR, "could not convert Python Unicode object to PostgreSQL server encoding");
! }
return rv;
}
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers