Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb66de4c

Browse files
committed
Fix mapping of PostgreSQL encodings to Python encodings.
Windows encodings, "win1252" and so forth, are named differently in Python,like "cp1252". Also, if the PyUnicode_AsEncodedString() function call failsfor some reason, use a plain ereport(), not a PLy_elog(), to report thaterror. That avoids recursion and crash, if PLy_elog() tries to callPLyUnicode_Bytes() again.This fixes bug reported by Asif Naeem. Backpatch down to 9.0, before thatplpython didn't even try these conversions.Jan Urbański, with minor comment improvements by me.
1 parentfc548b2 commitb66de4c

File tree

1 file changed

+62
-7
lines changed

1 file changed

+62
-7
lines changed

‎src/pl/plpython/plpy_util.c

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,71 @@ PLyUnicode_Bytes(PyObject *unicode)
6565
constchar*serverenc;
6666

6767
/*
68-
* Python understands almost all PostgreSQL encoding names, but it doesn't
69-
* know SQL_ASCII.
68+
* Map PostgreSQL encoding to a Python encoding name.
7069
*/
71-
if (GetDatabaseEncoding()==PG_SQL_ASCII)
72-
serverenc="ascii";
73-
else
74-
serverenc=GetDatabaseEncodingName();
70+
switch (GetDatabaseEncoding())
71+
{
72+
casePG_SQL_ASCII:
73+
/*
74+
* Mapping SQL_ASCII to Python's 'ascii' is a bit bogus. Python's
75+
* 'ascii' means true 7-bit only ASCII, while PostgreSQL's
76+
* SQL_ASCII means that anything is allowed, and the system doesn't
77+
* try to interpret the bytes in any way. But not sure what else
78+
* to do, and we haven't heard any complaints...
79+
*/
80+
serverenc="ascii";
81+
break;
82+
casePG_WIN1250:
83+
serverenc="cp1250";
84+
break;
85+
casePG_WIN1251:
86+
serverenc="cp1251";
87+
break;
88+
casePG_WIN1252:
89+
serverenc="cp1252";
90+
break;
91+
casePG_WIN1253:
92+
serverenc="cp1253";
93+
break;
94+
casePG_WIN1254:
95+
serverenc="cp1254";
96+
break;
97+
casePG_WIN1255:
98+
serverenc="cp1255";
99+
break;
100+
casePG_WIN1256:
101+
serverenc="cp1256";
102+
break;
103+
casePG_WIN1257:
104+
serverenc="cp1257";
105+
break;
106+
casePG_WIN1258:
107+
serverenc="cp1258";
108+
break;
109+
casePG_WIN866:
110+
serverenc="cp866";
111+
break;
112+
casePG_WIN874:
113+
serverenc="cp874";
114+
break;
115+
default:
116+
/* Other encodings have the same name in Python. */
117+
serverenc=GetDatabaseEncodingName();
118+
break;
119+
}
120+
75121
rv=PyUnicode_AsEncodedString(unicode,serverenc,"strict");
76122
if (rv==NULL)
77-
PLy_elog(ERROR,"could not convert Python Unicode object to PostgreSQL server encoding");
123+
{
124+
/*
125+
* Use a plain ereport instead of PLy_elog to avoid recursion, if
126+
* the traceback formatting functions try to do unicode to bytes
127+
* conversion again.
128+
*/
129+
ereport(ERROR,
130+
(errcode(ERRCODE_INTERNAL_ERROR),
131+
errmsg("could not convert Python Unicode object to PostgreSQL server encoding")));
132+
}
78133
returnrv;
79134
}
80135

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp