--- /dev/null
+-- test error handling, i forgot to restore Warn_restart in
+-- the trigger handler once. the errors and subsequent core dump were
+-- interesting.
+SELECT invalid_type_uncaught('rick');
+WARNING: plpython: in function invalid_type_uncaught:
+DETAIL: <class 'plpy.SPIError'>: Unknown error in PLy_spi_prepare
+ERROR: type "test" does not exist
+SELECT invalid_type_caught('rick');
+WARNING: plpython: in function invalid_type_caught:
+DETAIL: <class 'plpy.SPIError'>: Unknown error in PLy_spi_prepare
+ERROR: type "test" does not exist
+SELECT invalid_type_reraised('rick');
+WARNING: plpython: in function invalid_type_reraised:
+DETAIL: <class 'plpy.SPIError'>: Unknown error in PLy_spi_prepare
+ERROR: type "test" does not exist
+SELECT valid_type('rick');
+ valid_type
+------------
+
+(1 row)
+
+--
+-- Test Unicode error handling.
+--
+SELECT unicode_return_error();
+ERROR: plpython: function "unicode_return_error" could not create return value
+DETAIL: <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
+INSERT INTO unicode_test (testvalue) VALUES ('test');
+ERROR: plpython: function "unicode_trigger_error" could not modify tuple
+DETAIL: <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
+SELECT unicode_plan_error1();
+WARNING: plpython: in function unicode_plan_error1:
+DETAIL: <class 'plpy.Error'>: Unknown error in PLy_spi_execute_plan
+ERROR: plpython: function "unicode_plan_error1" could not execute plan
+DETAIL: <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
+SELECT unicode_plan_error2();
+ERROR: plpython: function "unicode_plan_error2" could not execute plan
+DETAIL: <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
/**********************************************************************
* plpython.c - python as a procedural language for PostgreSQL
*
- * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.89 2006/10/04 00:30:14 momjian Exp $
+ * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.90 2006/11/21 21:51:05 tgl Exp $
*
*********************************************************************
*/
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- 0, /* tp_xxx4 */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
PLy_plan_doc, /* tp_doc */
};
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- 0, /* tp_xxx4 */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
PLy_result_doc, /* tp_doc */
};
PLy_free(ob->args);
}
- PyMem_DEL(arg);
+ arg->ob_type->tp_free(arg);
}
Py_XDECREF(ob->rows);
Py_XDECREF(ob->status);
- PyMem_DEL(ob);
+ arg->ob_type->tp_free(arg);
}
static PyObject *
/*
* initialize plpy module
*/
- PLy_PlanType.ob_type = PLy_ResultType.ob_type = &PyType_Type;
+ if (PyType_Ready(&PLy_PlanType) < 0)
+ elog(ERROR, "could not init PLy_PlanType");
+ if (PyType_Ready(&PLy_ResultType) < 0)
+ elog(ERROR, "could not init PLy_ResultType");
+
plpy = Py_InitModule("plpy", PLy_methods);
plpy_dict = PyModule_GetDict(plpy);