mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-06 19:27:34 +08:00
PL/Python: Fix crash when colnames() etc. called without result set
The result object methods colnames() etc. would crash when called after a command that did not produce a result set. Now they throw an exception. discovery and initial patch by Jean-Baptiste Quenot
This commit is contained in:
@ -115,9 +115,9 @@ SELECT join_sequences(sequences) FROM sequences
|
||||
--
|
||||
-- plan and result objects
|
||||
--
|
||||
CREATE FUNCTION result_nrows_test() RETURNS int
|
||||
CREATE FUNCTION result_metadata_test(cmd text) RETURNS int
|
||||
AS $$
|
||||
plan = plpy.prepare("SELECT 1 AS foo, '11'::text AS bar UNION SELECT 2, '22'")
|
||||
plan = plpy.prepare(cmd)
|
||||
plpy.info(plan.status()) # not really documented or useful
|
||||
result = plpy.execute(plan)
|
||||
if result.status() > 0:
|
||||
@ -128,20 +128,28 @@ if result.status() > 0:
|
||||
else:
|
||||
return None
|
||||
$$ LANGUAGE plpythonu;
|
||||
SELECT result_nrows_test();
|
||||
SELECT result_metadata_test($$SELECT 1 AS foo, '11'::text AS bar UNION SELECT 2, '22'$$);
|
||||
INFO: True
|
||||
CONTEXT: PL/Python function "result_nrows_test"
|
||||
CONTEXT: PL/Python function "result_metadata_test"
|
||||
INFO: ['foo', 'bar']
|
||||
CONTEXT: PL/Python function "result_nrows_test"
|
||||
CONTEXT: PL/Python function "result_metadata_test"
|
||||
INFO: [23, 25]
|
||||
CONTEXT: PL/Python function "result_nrows_test"
|
||||
CONTEXT: PL/Python function "result_metadata_test"
|
||||
INFO: [-1, -1]
|
||||
CONTEXT: PL/Python function "result_nrows_test"
|
||||
result_nrows_test
|
||||
-------------------
|
||||
2
|
||||
CONTEXT: PL/Python function "result_metadata_test"
|
||||
result_metadata_test
|
||||
----------------------
|
||||
2
|
||||
(1 row)
|
||||
|
||||
SELECT result_metadata_test($$CREATE TEMPORARY TABLE foo1 (a int, b text)$$);
|
||||
INFO: True
|
||||
CONTEXT: PL/Python function "result_metadata_test"
|
||||
ERROR: plpy.Error: command did not produce a result set
|
||||
CONTEXT: Traceback (most recent call last):
|
||||
PL/Python function "result_metadata_test", line 6, in <module>
|
||||
plpy.info(result.colnames())
|
||||
PL/Python function "result_metadata_test"
|
||||
-- cursor objects
|
||||
CREATE FUNCTION simple_cursor_test() RETURNS int AS $$
|
||||
res = plpy.cursor("select fname, lname from users")
|
||||
|
||||
Reference in New Issue
Block a user