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

Commit66f5038

Browse files
committed
Make plpython cope with funny characters in function names.
A function name that's double-quoted in SQL can contain almost anycharacters, but we were using that name directly as part of the namegenerated for the Python-level function, and Python doesn't likeanything that isn't pretty much a standard identifier. To fix,replace anything that isn't an ASCII letter or digit with an underscorein the generated name. This doesn't create any risk of duplicate Pythonfunction names because we were already appending the function OID tothe generated name to ensure uniqueness. Per bug #13960 from Jim Nasby.Patch by Jim Nasby, modified a bit by me. Back-patch to allsupported branches.
1 parenta65313f commit66f5038

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

‎src/pl/plpython/expected/plpython_test.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ select stupidn();
1616
zarkon
1717
(1 row)
1818

19-
-- test multiple arguments
20-
CREATE FUNCTIONargument_test_one(u users, a1 text, a2 text) RETURNS text
19+
-- test multiple arguments and odd characters in function name
20+
CREATE FUNCTION"Argument test #1"(u users, a1 text, a2 text) RETURNS text
2121
AS
2222
'keys = list(u.keys())
2323
keys.sort()
@@ -27,8 +27,8 @@ for key in keys:
2727
words = a1 + " " + a2 + " => {" + ", ".join(out) + "}"
2828
return words'
2929
LANGUAGE plpythonu;
30-
selectargument_test_one(users, fname, lname) from users where lname = 'doe' order by 1;
31-
argument_test_one
30+
select"Argument test #1"(users, fname, lname) from users where lname = 'doe' order by 1;
31+
Argument test #1
3232
-----------------------------------------------------------------------
3333
jane doe => {fname: jane, lname: doe, userid: 1, username: j_doe}
3434
john doe => {fname: john, lname: doe, userid: 2, username: johnd}

‎src/pl/plpython/plpy_procedure.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ PLy_procedure_create(HeapTuple procTup, Oid fn_oid, bool is_trigger)
146146
MemoryContextcxt;
147147
MemoryContextoldcxt;
148148
intrv;
149+
char*ptr;
149150

150151
procStruct= (Form_pg_proc)GETSTRUCT(procTup);
151152
rv=snprintf(procName,sizeof(procName),
@@ -155,6 +156,15 @@ PLy_procedure_create(HeapTuple procTup, Oid fn_oid, bool is_trigger)
155156
if (rv >=sizeof(procName)||rv<0)
156157
elog(ERROR,"procedure name would overrun buffer");
157158

159+
/* Replace any not-legal-in-Python-names characters with '_' */
160+
for (ptr=procName;*ptr;ptr++)
161+
{
162+
if (!((*ptr >='A'&&*ptr <='Z')||
163+
(*ptr >='a'&&*ptr <='z')||
164+
(*ptr >='0'&&*ptr <='9')))
165+
*ptr='_';
166+
}
167+
158168
cxt=AllocSetContextCreate(TopMemoryContext,
159169
procName,
160170
ALLOCSET_DEFAULT_MINSIZE,

‎src/pl/plpython/sql/plpython_test.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ CREATE FUNCTION stupidn() RETURNS text AS 'return "zarkon"' LANGUAGE plpython2u;
1111

1212
select stupidn();
1313

14-
-- test multiple arguments
15-
CREATEFUNCTIONargument_test_one(u users, a1text, a2text) RETURNStext
14+
-- test multiple arguments and odd characters in function name
15+
CREATE FUNCTION"Argument test #1"(u users, a1text, a2text) RETURNStext
1616
AS
1717
'keys = list(u.keys())
1818
keys.sort()
@@ -23,7 +23,7 @@ words = a1 + " " + a2 + " => {" + ", ".join(out) + "}"
2323
return words'
2424
LANGUAGE plpythonu;
2525

26-
selectargument_test_one(users, fname, lname)from userswhere lname='doe'order by1;
26+
select"Argument test #1"(users, fname, lname)from userswhere lname='doe'order by1;
2727

2828

2929
-- check module contents

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp