From 9d9848668fd868a4e51f3a3f22c2807ff0e46582 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 12 Aug 2009 16:37:26 +0000 Subject: Split the plpython regression test into test cases arranged by topic, instead of the previous monolithic setup-create-run sequence, that was apparently inherited from a previous test infrastructure, but makes working with the tests and adding new ones weird. --- src/pl/plpython/sql/plpython_error.sql | 109 ++++++++++++++++++++++++++++++--- 1 file changed, 100 insertions(+), 9 deletions(-) (limited to 'src/pl/plpython/sql/plpython_error.sql') diff --git a/src/pl/plpython/sql/plpython_error.sql b/src/pl/plpython/sql/plpython_error.sql index b04b23ef95..04161bc25e 100644 --- a/src/pl/plpython/sql/plpython_error.sql +++ b/src/pl/plpython/sql/plpython_error.sql @@ -1,18 +1,109 @@ - -- test error handling, i forgot to restore Warn_restart in -- the trigger handler once. the errors and subsequent core dump were -- interesting. +/* Flat out syntax error + */ +CREATE FUNCTION sql_syntax_error() RETURNS text + AS +'plpy.execute("syntax error")' + LANGUAGE plpythonu; + +SELECT sql_syntax_error(); + + +/* check the handling of uncaught python exceptions + */ +CREATE FUNCTION exception_index_invalid(text) RETURNS text + AS +'return args[1]' + LANGUAGE plpythonu; + +SELECT exception_index_invalid('test'); + + +/* check handling of nested exceptions + */ +CREATE FUNCTION exception_index_invalid_nested() RETURNS text + AS +'rv = plpy.execute("SELECT test5(''foo'')") +return rv[0]' + LANGUAGE plpythonu; + +SELECT exception_index_invalid_nested(); + + +/* a typo + */ +CREATE FUNCTION invalid_type_uncaught(a text) RETURNS text + AS +'if not SD.has_key("plan"): + q = "SELECT fname FROM users WHERE lname = $1" + SD["plan"] = plpy.prepare(q, [ "test" ]) +rv = plpy.execute(SD["plan"], [ a ]) +if len(rv): + return rv[0]["fname"] +return None +' + LANGUAGE plpythonu; + SELECT invalid_type_uncaught('rick'); + + +/* for what it's worth catch the exception generated by + * the typo, and return None + */ +CREATE FUNCTION invalid_type_caught(a text) RETURNS text + AS +'if not SD.has_key("plan"): + q = "SELECT fname FROM users WHERE lname = $1" + try: + SD["plan"] = plpy.prepare(q, [ "test" ]) + except plpy.SPIError, ex: + plpy.notice(str(ex)) + return None +rv = plpy.execute(SD["plan"], [ a ]) +if len(rv): + return rv[0]["fname"] +return None +' + LANGUAGE plpythonu; + SELECT invalid_type_caught('rick'); + + +/* for what it's worth catch the exception generated by + * the typo, and reraise it as a plain error + */ +CREATE FUNCTION invalid_type_reraised(a text) RETURNS text + AS +'if not SD.has_key("plan"): + q = "SELECT fname FROM users WHERE lname = $1" + try: + SD["plan"] = plpy.prepare(q, [ "test" ]) + except plpy.SPIError, ex: + plpy.error(str(ex)) +rv = plpy.execute(SD["plan"], [ a ]) +if len(rv): + return rv[0]["fname"] +return None +' + LANGUAGE plpythonu; + SELECT invalid_type_reraised('rick'); -SELECT valid_type('rick'); --- --- Test Unicode error handling. --- -SELECT unicode_return_error(); -INSERT INTO unicode_test (testvalue) VALUES ('test'); -SELECT unicode_plan_error1(); -SELECT unicode_plan_error2(); +/* no typo no messing about + */ +CREATE FUNCTION valid_type(a text) RETURNS text + AS +'if not SD.has_key("plan"): + SD["plan"] = plpy.prepare("SELECT fname FROM users WHERE lname = $1", [ "text" ]) +rv = plpy.execute(SD["plan"], [ a ]) +if len(rv): + return rv[0]["fname"] +return None +' + LANGUAGE plpythonu; + +SELECT valid_type('rick'); -- cgit v1.2.1