Commit Graph

211 Commits

Author SHA1 Message Date
Magnus Hagander 9f2e211386 Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
Peter Eisentraut c76a4f8dea Catch null pointer returns from PyCObject_AsVoidPtr and PyCObject_FromVoidPtr
This is reproducibly possible in Python 2.7 if the user turned
PendingDeprecationWarning into an error, but it's theoretically also possible
in earlier versions in case of exceptional conditions.

backpatched to 8.0
2010-08-25 19:37:56 +00:00
Peter Eisentraut 3f11971916 Remove extra newlines at end and beginning of files, add missing newlines
at end of files.
2010-08-19 05:57:36 +00:00
Tom Lane 6d297e0551 Minor kibitzing on previous patch: no need to run check more than once.
(_PG_init should be called only once anyway, but as long as it's got an
internal guard against repeat calls, that should be in front of the
version check.)
2010-07-08 19:00:11 +00:00
Peter Eisentraut 803716013d Install safeguard against running PL/Python 2 and 3 in the same session 2010-07-08 18:42:12 +00:00
Bruce Momjian 239d769e7e pgindent run for 9.0, second run 2010-07-06 19:19:02 +00:00
Peter Eisentraut a3401bea9c Use different function names for plpython3 handlers, to avoid clashes in
pg_pltemplate

This should have a catversion bump, but it's still being debated whether
it's worth it during beta.
2010-06-29 00:18:11 +00:00
Peter Eisentraut cc3c4a2407 Update Python version information 2010-06-12 06:05:48 +00:00
Peter Eisentraut 6b72aa5154 Add a regression test case for bug #5497 2010-06-12 06:05:20 +00:00
Tom Lane 4ddf151c49 Fix quite-bogus handling of arrays in plpython datum-to-PyObject
conversion.  Per bug #5497 from David Gardner.
2010-06-10 04:05:01 +00:00
Peter Eisentraut f1ac08daee Translation update 2010-05-13 15:56:43 +00:00
Tom Lane f5c23ca208 Fix leakage of proc-related storage in plpython's inline handler.
Per report from Andres Freund.
2010-05-01 17:04:38 +00:00
Tom Lane b1bc2f0425 Fix multiple memory leaks in PLy_spi_execute_fetch_result: it would leak
memory if the result had zero rows, and also if there was any sort of error
while converting the result tuples into Python data.  Reported and partially
fixed by Andres Freund.

Back-patch to all supported versions.  Note: I haven't tested the 7.4 fix.
7.4's configure check for python is so obsolete it doesn't work on my
current machines :-(.  The logic change is pretty straightforward though.
2010-04-30 19:15:45 +00:00
Peter Eisentraut a401226bd8 Prevent the injection of invalidly encoded strings by PL/Python into PostgreSQL
with a few strategically placed pg_verifymbstr calls.
2010-03-18 19:43:03 +00:00
Peter Eisentraut 12c2f2f66c Use data-type specific conversion functions also in plpy.execute
In PLy_spi_execute_plan, use the data-type specific Python-to-PostgreSQL
conversion function instead of passing everything through InputFunctionCall
as a string.  The equivalent fix was already done months ago for function
parameters and return values, but this other gateway between Python and
PostgreSQL was apparently forgotten.  As a result, data types that need
special treatment, such as bytea, would misbehave when used with
plpy.execute.
2010-03-18 13:23:57 +00:00
Bruce Momjian 65e806cba1 pgindent run for 9.0 2010-02-26 02:01:40 +00:00
Peter Eisentraut a39f02e369 Translation updates for 9.0alpha4 2010-02-19 00:40:05 +00:00
Tom Lane a232f30f05 Volatile-ize all five places where we expect a PG_TRY block to restore
old memory context in plpython.  Before only one of them was marked
volatile, but per report from Zdenek Kotala, some compilers do the
wrong thing here.
2010-02-18 23:50:06 +00:00
Robert Haas e26c539e9f Wrap calls to SearchSysCache and related functions using macros.
The purpose of this change is to eliminate the need for every caller
of SearchSysCache, SearchSysCacheCopy, SearchSysCacheExists,
GetSysCacheOid, and SearchSysCacheList to know the maximum number
of allowable keys for a syscache entry (currently 4).  This will
make it far easier to increase the maximum number of keys in a
future release should we choose to do so, and it makes the code
shorter, too.

Design and review by Tom Lane.
2010-02-14 18:42:19 +00:00
Peter Eisentraut adb7764030 PL/Python DO handler
Also cleaned up some redundancies between the primary error messages and the
error context in PL/Python.

Hannu Valtonen
2010-01-22 15:45:15 +00:00
Peter Eisentraut 44e03742d8 Improved printing of Python exceptions in PL/Python
Mimic the Python interpreter's own logic for printing exceptions instead
of just using the straight str() call, so that
you get

    plpy.SPIError

instead of

    <class 'plpy.SPIError'>

and for built-in exceptions merely

    UnicodeEncodeError

Besides looking better this cuts down on the endless version differences
in the regression test expected files.
2010-01-16 11:03:51 +00:00
Peter Eisentraut baab7a0427 Translation updates 2009-12-19 20:23:26 +00:00
Peter Eisentraut dd4cd55c15 Python 3 support in PL/Python
Behaves more or less unchanged compared to Python 2, but the new language
variant is called plpython3u.  Documentation describing the naming scheme
is included.
2009-12-15 22:59:55 +00:00
Peter Eisentraut db7386187f PL/Python array support
Support arrays as parameters and return values of PL/Python functions.
2009-12-10 20:43:40 +00:00
Peter Eisentraut 2e3b16c8ba Improve PL/Python elog output
When the elog functions (plpy.info etc.) get a single argument, just print
that argument instead of printing the single-member tuple like ('foo',).
2009-11-03 11:05:03 +00:00
Peter Eisentraut 9e41114676 Fix obscure segfault condition in PL/Python
In PLy_output(), when the elog() call in the TRY branch throws an exception
(this can happen when a statement timeout kicks in, for example), the
PyErr_SetString() call in the CATCH branch can cause a segfault, because the
Py_XDECREF(so) call before it releases memory that is still used by the sv
variable that PyErr_SetString() uses as argument, because sv points into
memory owned by so.

Backpatched back to 8.0, where this code was introduced.

I also threw in a couple of volatile declarations for variables that are used
before and after the TRY.  I don't think they caused the crash that I
observed, but they could become issues.
2009-11-03 09:35:18 +00:00
Peter Eisentraut ef8df75e67 Translations update for 8.5alpha2 2009-10-20 18:23:27 +00:00
Tom Lane 198483a2e4 First committed version of plpython_unicode_0.out did not actually contain the
required \200 bytes.  Let's see if this commit works, or if CVS is messing it up.
2009-10-15 23:39:13 +00:00
Peter Eisentraut ea2467d78b Add alternative expected file for unicode test for client encoding not UTF8 2009-10-14 21:42:58 +00:00
Peter Eisentraut eb62398f39 Fix Unicode support in PL/Python
Check calls of PyUnicode_AsEncodedString() for NULL return, probably
because the encoding name is not known.  Add special treatment for
SQL_ASCII, which Python definitely does not know.

Since using SQL_ASCII produces errors in the regression tests when
non-ASCII characters are involved, we have to put back various regression
test result variants.
2009-09-13 22:07:06 +00:00
Peter Eisentraut 4ab6ebf3f4 Add Unicode support in PL/Python
PL/Python now accepts Unicode objects where it previously only accepted string
objects (for example, as return value).  Unicode objects are converted to the
PostgreSQL server encoding as necessary.

This change is also necessary for future Python 3 support, which treats all
strings as Unicode objects.

Since this removes the error conditions that the plpython_unicode test file
tested for, the alternative result files are no longer necessary.
2009-09-12 22:13:12 +00:00
Peter Eisentraut 762140f600 Remove TODO file; it has been added to the main Todo list in the wiki. 2009-09-12 15:21:27 +00:00
Peter Eisentraut 3ab8b7fa6f Fix/improve bytea and boolean support in PL/Python
Before, PL/Python converted data between SQL and Python by going
through a C string representation.  This broke for bytea in two ways:

- On input (function parameters), you would get a Python string that
  contains bytea's particular external representation with backslashes
  etc., instead of a sequence of bytes, which is what you would expect
  in a Python environment.  This problem is exacerbated by the new
  bytea output format.

- On output (function return value), null bytes in the Python string
  would cause truncation before the data gets stored into a bytea
  datum.

This is now fixed by converting directly between the PostgreSQL datum
and the Python representation.

The required generalized infrastructure also allows for other
improvements in passing:

- When returning a boolean value, the SQL datum is now true if and
  only if Python considers the value that was passed out of the
  PL/Python function to be true.  Previously, this determination was
  left to the boolean data type input function.  So, now returning
  'foo' results in true, because Python considers it true, rather than
  false because PostgreSQL considers it false.

- On input, we can convert the integer and float types directly to
  their Python equivalents without having to go through an
  intermediate string representation.

original patch by Caleb Welton, with updates by myself
2009-09-09 19:00:09 +00:00
Peter Eisentraut 27c405d61a Enhanced error context support in PL/Python
Extract the "while creating return value" and "while modifying trigger
row" parts of some error messages into another layer of error context.
This will simplify the upcoming patch to improve data type support, but
it can stand on its own.
2009-08-25 12:44:59 +00:00
Peter Eisentraut 983d10833e Use generic attribute management in PL/Python
Switch the implementation of the plan and result types to generic attribute
management, as described at <http://docs.python.org/extending/newtypes.html>.
This modernizes and simplifies the code a bit and prepares for Python 3.1,
where the old way doesn't work anymore.
2009-08-25 08:14:42 +00:00
Peter Eisentraut 5dff93638c Make PL/Python tests more compatible with Python 3
This changes a bunch of incidentially used constructs in the PL/Python
regression tests to equivalent constructs in cases where Python 3 no longer
supports the old syntax.  Support for older Python versions is unchanged.
2009-08-24 20:25:25 +00:00
Peter Eisentraut efc1aeb85a Remove the test case that depends on the platform's float output format. 2009-08-14 23:25:51 +00:00
Peter Eisentraut 0c738084fb PL/Python regression tests for data type handling
Add some checks on various data types are converted into and out of Python.
This is extracted from Caleb Welton's patch for improved bytea support,
but much expanded.
2009-08-14 13:42:16 +00:00
Peter Eisentraut c74d8a7708 Domain support in PL/Python
When examining what Python type to convert a PostgreSQL type to on input,
look at the base type of the input type, otherwise all domains end up
defaulting to string.
2009-08-14 13:12:21 +00:00
Peter Eisentraut cfe380a6dd Augment test coverage in PL/Python, especially for error conditions. 2009-08-13 20:50:05 +00:00
Peter Eisentraut 9d9848668f 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.
2009-08-12 16:37:26 +00:00
Peter Eisentraut 5106bdc450 Use errcontext mechanism in PL/Python
Error messages from PL/Python now always mention the function name in the
CONTEXT: field.  This also obsoletes the few places that tried to do the
same manually.

Regression test files are updated to work with Python 2.4-2.6.  I don't have
access to older versions right now.
2009-07-20 08:01:07 +00:00
Peter Eisentraut a6667d96c5 Translation updates for 8.4 release.
File that are translated less than 80% have been removed, as per new
translation team policy.
2009-06-26 19:33:52 +00:00
Bruce Momjian d747140279 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list
provided by Andrew.
2009-06-11 14:49:15 +00:00
Peter Eisentraut 0b7b908882 Translation updates 2009-06-10 23:42:44 +00:00
Tom Lane 76d4abf2d9 Improve the recently-added support for properly pluralized error messages
by extending the ereport() API to cater for pluralization directly.  This
is better than the original method of calling ngettext outside the elog.c
code because (1) it avoids double translation, which wastes cycles and in
the worst case could give a wrong result; and (2) it avoids having to use
a different coding method in PL code than in the core backend.  The
client-side uses of ngettext are not touched since neither of these concerns
is very pressing in the client environment.  Per my proposal of yesterday.
2009-06-04 18:33:08 +00:00
Alvaro Herrera f97017068f Translation updates 2009-05-14 21:41:53 +00:00
Peter Eisentraut 80a836cab4 Translation updates for 8.4 beta 2009-04-09 19:38:53 +00:00
Tom Lane cd331e4b84 Defend against possible crash if a plpython function does not specify names
for its arguments.  Also add a regression test, since someone apparently
changed every single plpython test case to use only named parameters; else
we'd have noticed this sooner.

Euler Taveira de Oliveira, per a report from Alvaro
2009-04-03 16:59:43 +00:00
Peter Eisentraut 8032d76b5b Gettext plural support
In the backend, I changed only a handful of exemplary or important-looking
instances to make use of the plural support; there is probably more work
there.  For the rest of the source, this should cover all relevant cases.
2009-03-26 22:26:08 +00:00