PL/Python integration: support in create/droplang, add CVS keywords,

remove useless files, beat some sense into Makefile.  For me it builds
and sort of runs, so it's a start.
This commit is contained in:
Peter Eisentraut 2001-05-12 01:30:30 +00:00
parent bb30d49a2a
commit c51b00a213
15 changed files with 84 additions and 343 deletions

View File

@ -7,7 +7,7 @@
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.24 2001/05/09 22:08:19 petere Exp $
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.25 2001/05/12 01:30:30 petere Exp $
#
#-------------------------------------------------------------------------
@ -209,9 +209,15 @@ case "$langname" in
handler="plperl_call_handler"
object="plperl"
;;
plpython)
lancomp="PL/Python"
trusted="TRUSTED "
handler="plpython_call_handler"
object="plpython"
;;
*)
echo "$CMDNAME: unsupported language '$langname'" 1>&2
echo "Supported languages are 'plpgsql', 'pltcl', 'pltclu', and 'plperl'." 1>&2
echo "Supported languages are 'plpgsql', 'pltcl', 'pltclu', 'plperl', and 'plpython'." 1>&2
exit 1
;;
esac

View File

@ -7,7 +7,7 @@
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.14 2001/05/09 22:08:19 petere Exp $
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.15 2001/05/12 01:30:30 petere Exp $
#
#-------------------------------------------------------------------------
@ -177,9 +177,13 @@ case "$langname" in
lancomp="PL/Perl"
handler="plperl_call_handler"
;;
plpython)
lancomp="PL/Python"
handler="plpython_call_handler"
;;
*)
echo "$CMDNAME: unsupported language '$langname'" 1>&2
echo "Supported languages are 'plpgsql', 'pltcl', 'pltclu', and 'plperl'." 1>&2
echo "Supported languages are 'plpgsql', 'pltcl', 'pltclu', 'plperl', and 'plpython'." 1>&2
exit 1
;;
esac

View File

@ -4,7 +4,7 @@
#
# Copyright (c) 1994, Regents of the University of California
#
# $Header: /cvsroot/pgsql/src/pl/Makefile,v 1.19 2001/05/10 03:00:11 momjian Exp $
# $Header: /cvsroot/pgsql/src/pl/Makefile,v 1.20 2001/05/12 01:30:30 petere Exp $
#
#-------------------------------------------------------------------------
@ -22,12 +22,12 @@ ifeq ($(with_perl), yes)
DIRS += plperl
endif
# Doesn't build portably yet.
#ifeq ($(with_python), yes)
#DIRS += plpython
#endif
all install installdirs uninstall depend distprep:
@echo "PL/Python disabled until merged into our Makefile system, bjm 2001-05-09"
@for dir in $(DIRS); do $(MAKE) -C $$dir $@ || exit; done
clean distclean maintainer-clean:

View File

@ -1,69 +1,60 @@
# $Header: /cvsroot/pgsql/src/pl/plpython/Makefile,v 1.4 2001/05/12 01:30:30 petere Exp $
# cflags. pick your favorite
subdir = src/pl/plpython
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
# These things ought to go into $(top_srcdir)/config/python.m4 sometime.
PYTHON_VERSION := $(shell $(PYTHON) -c 'import sys; print sys.version[:3]')
PYTHON_INCLUDE := $(shell $(PYTHON) -c 'import sys; print sys.prefix')/include/python$(PYTHON_VERSION)
override CPPFLAGS := -I$(srcdir) -I$(PYTHON_INCLUDE) $(CPPFLAGS)
PYTHON_LIB := $(shell $(PYTHON) -c 'import sys; print sys.exec_prefix')/lib/python$(PYTHON_VERSION)
NAME = plpython
SO_MAJOR_VERSION = 0
SO_MINOR_VERSION = 0
OBJS = plpython.o
# This static version might work on most ELF systems...
SHLIB_LINK += $(PYTHON_LIB)/config/libpython$(PYTHON_VERSION).a
# ...otherwise you need a shared version, but you need to build that yourself.
#SHLIB_LINK += -lpython$(PYTHON_VERSION)
# Python uses this. Should become a configure check.
SHLIB_LINK += -lpthread
# Python 2 seems to want libdb.
#SHLIB_LINK += -ldb2
# Hopefully you won't need this utter crap. But if you can't patch
# the appropriate dynloader file, try this. You may have to add other
# modules.
#
CC=gcc
CFLAGS=-g -O0 -Wall -Wmissing-declarations -fPIC
#DLDIR=$(PYTHON_LIB)/lib-dynload
#DLHACK=$(DLDIR)/arraymodule.so $(DLDIR)/timemodule.so $(DLDIR)/cmathmodule.so $(DLDIR)/errnomodule.so $(DLDIR)/mathmodule.so $(DLDIR)/md5module.so $(DLDIR)/operator.so $(DLDIR)/shamodule.so
#SHLIB_LINK += $(DLDIR)
# build info for python, alter as needed
#
include $(top_srcdir)/src/Makefile.shlib
# python headers
#
#INCPYTHON=/usr/include/python1.5
INCPYTHON=/usr/include/python2.0
# python shared library
#
#LIBPYTHON=python1.5
LIBPYTHON=python2.0
all: all-lib
# if python is someplace odd
#
LIBPYTHONPATH=/usr/lib
install: all installdirs
$(INSTALL_SHLIB) $(shlib) $(DESTDIR)$(libdir)/plpython$(DLSUFFIX)
# python 2 seems to want libdb
# various db libs are still messed on my system
#
#LIBPYTHONEXTRA=/usr/lib/libdb2.so.2.7.7
#LIBPYTHONEXTRA=-ldb2
installdirs:
$(mkinstalldirs) $(DESTDIR)$(libdir)
LDPYTHON=-L$(LIBPYTHONPATH) -l$(LIBPYTHON) $(LIBPYTHONEXTRA)
uninstall:
rm -f $(DESTDIR)$(libdir)/plpython$(DLSUFFIX)
# build info for postgres
#
# postgres headers. the installed include directory doesn't work for me
#
#INCPOSTGRES=/usr/include/postgres
INCPOSTGRES=/home/andrew/builds/postgresql/src/include
# hopefully you won't need this utter crap...
# but if you can't patch the appropriate dynloader file, try this. you
# may have to add other modules.
#
#DLDIR=/usr/lib/python1.5/lib-dynload
#DLHACK=$(DLDIR)/arraymodule.so $(DLDIR)/timemodule.so $(DLDIR)/cmathmodule.so $(DLDIR)/errnomodule.so $(DLDIR)/mathmodule.so $(DLDIR)/md5module.so $(DLDIR)/operator.so
# $(DLDIR)/shamodule.so
# shouldn't need to alter anything below here
#
INCLUDES=-I$(INCPYTHON) -I$(INCPOSTGRES) -I./
# dynamic linker flags.
#
#LDFLAGS=--shared -Wl,-Bshareable -Wl,-E -Wl,-soname,$@
LDFLAGS=--shared -Wl,-E -Wl,-soname,$@
.PHONY: clean
all: plpython.so
plpython.o: plpython.c plpython.h
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
plpython.so: plpython.o
$(CC) $(LDFLAGS) -o $@ $^ $(LDPYTHON) $(DLHACK) -ldl -lpthread -lm
clean:
rm -f plpython.so *.o
clean distclean maintainer-clean: clean-lib
rm -f $(OBJS)
@rm -f error.diff feature.diff error.output feature.output test.log
installcheck:
PATH=$(bindir):$$PATH $(SHELL) $(srcdir)/test.sh

View File

@ -1,18 +0,0 @@
--- error.expected Sat Mar 31 16:15:31 2001
+++ error.output Thu Apr 19 23:47:53 2001
@@ -1,5 +1,5 @@
SELECT invalid_type_uncaught('rick');
-ERROR: plpython: Call of function `__plpython_procedure_invalid_type_uncaught_1175341' failed.
+ERROR: plpython: Call of function `__plpython_procedure_invalid_type_uncaught_1289666' failed.
plpy.SPIError: Cache lookup for type `test' failed.
SELECT invalid_type_caught('rick');
NOTICE: ("Cache lookup for type `test' failed.",)
@@ -9,7 +9,7 @@
(1 row)
SELECT invalid_type_reraised('rick');
-ERROR: plpython: Call of function `__plpython_procedure_invalid_type_reraised_1175343' failed.
+ERROR: plpython: Call of function `__plpython_procedure_invalid_type_reraised_1289668' failed.
plpy.Error: ("Cache lookup for type `test' failed.",)
SELECT valid_type('rick');
valid_type

View File

@ -1,19 +0,0 @@
SELECT invalid_type_uncaught('rick');
ERROR: plpython: Call of function `__plpython_procedure_invalid_type_uncaught_1289666' failed.
plpy.SPIError: Cache lookup for type `test' failed.
SELECT invalid_type_caught('rick');
NOTICE: ("Cache lookup for type `test' failed.",)
invalid_type_caught
---------------------
(1 row)
SELECT invalid_type_reraised('rick');
ERROR: plpython: Call of function `__plpython_procedure_invalid_type_reraised_1289668' failed.
plpy.Error: ("Cache lookup for type `test' failed.",)
SELECT valid_type('rick');
valid_type
------------
(1 row)

View File

@ -1,11 +0,0 @@
--- feature.expected Sat Mar 31 16:15:31 2001
+++ feature.output Thu Apr 19 23:47:52 2001
@@ -29,7 +29,7 @@
(1 row)
SELECT import_fail();
-NOTICE: ('import socket failed -- untrusted dynamic module: socket',)
+NOTICE: ('import socket failed -- untrusted dynamic module: _socket',)
import_fail
--------------------
failed as expected

View File

@ -1,139 +0,0 @@
select stupid();
stupid
--------
zarkon
(1 row)
SELECT static_test();
static_test
-------------
1
(1 row)
SELECT static_test();
static_test
-------------
2
(1 row)
SELECT global_test_one();
global_test_one
--------------------------------------------------------
SD: set by global_test_one, GD: set by global_test_one
(1 row)
SELECT global_test_two();
global_test_two
--------------------------------------------------------
SD: set by global_test_two, GD: set by global_test_one
(1 row)
SELECT import_fail();
NOTICE: ('import socket failed -- untrusted dynamic module: _socket',)
import_fail
--------------------
failed as expected
(1 row)
SELECT import_succeed();
import_succeed
------------------------
succeeded, as expected
(1 row)
SELECT import_test_one('sha hash of this string');
import_test_one
------------------------------------------
a04e23cb9b1a09cd1051a04a7c571aae0f90346c
(1 row)
select import_test_two(users) from users where fname = 'willem';
import_test_two
-------------------------------------------------------------------
sha hash of willemdoe is 3cde6b574953b0ca937b4d76ebc40d534d910759
(1 row)
select argument_test_one(users, fname, lname) from users where lname = 'doe';
argument_test_one
-------------------------------------------------------------------------------------
willem doe => {'fname': 'willem', 'userid': 3, 'lname': 'doe', 'username': 'w_doe'}
john doe => {'fname': 'john', 'userid': 2, 'lname': 'doe', 'username': 'johnd'}
jane doe => {'fname': 'jane', 'userid': 1, 'lname': 'doe', 'username': 'j_doe'}
(3 rows)
select nested_call_one('pass this along');
nested_call_one
-----------------------------------------------------------------
{'nested_call_two': "{'nested_call_three': 'pass this along'}"}
(1 row)
select spi_prepared_plan_test_one('doe');
spi_prepared_plan_test_one
----------------------------
there are 3 does
(1 row)
select spi_prepared_plan_test_one('smith');
spi_prepared_plan_test_one
----------------------------
there are 1 smiths
(1 row)
select spi_prepared_plan_test_nested('smith');
spi_prepared_plan_test_nested
-------------------------------
there are 1 smiths
(1 row)
SELECT * FROM users;
fname | lname | username | userid
--------+-------+----------+--------
jane | doe | j_doe | 1
john | doe | johnd | 2
willem | doe | w_doe | 3
rick | smith | slash | 4
(4 rows)
UPDATE users SET fname = 'william' WHERE fname = 'willem';
INSERT INTO users (fname, lname) VALUES ('william', 'smith');
INSERT INTO users (fname, lname, username) VALUES ('charles', 'darwin', 'beagle');
SELECT * FROM users;
fname | lname | username | userid
---------+--------+----------+--------
jane | doe | j_doe | 1
john | doe | johnd | 2
willem | doe | w_doe | 3
rick | smith | slash | 4
willem | smith | w_smith | 5
charles | darwin | beagle | 6
(6 rows)
SELECT join_sequences(sequences) FROM sequences;
join_sequences
----------------
ABCDEFGHIJKL
ABCDEF
ABCDEF
ABCDEF
ABCDEF
ABCDEF
(6 rows)
SELECT join_sequences(sequences) FROM sequences
WHERE join_sequences(sequences) ~* '^A';
join_sequences
----------------
ABCDEFGHIJKL
ABCDEF
ABCDEF
ABCDEF
ABCDEF
ABCDEF
(6 rows)
SELECT join_sequences(sequences) FROM sequences
WHERE join_sequences(sequences) ~* '^B';
join_sequences
----------------
(0 rows)

View File

@ -1,44 +0,0 @@
/*-------------------------------------------------------------------------
*
* port_protos.h
* port-specific prototypes for Linux
*
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: linux.h,v 1.1 2001/05/09 19:54:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H
#include "fmgr.h"
#include "utils/dynamic_loader.h"
#ifdef __ELF__
#include <dlfcn.h>
#endif
/* dynloader.c */
#ifndef __ELF__
#ifndef HAVE_DLD_H
#define pg_dlsym(handle, funcname) (NULL)
#define pg_dlclose(handle) ({})
#else
#define pg_dlsym(handle, funcname) ((PGFunction) dld_get_func((funcname)))
#define pg_dlclose(handle) ({ dld_unlink_by_file(handle, 1); free(handle); })
#endif
#else
/* #define pg_dlopen(f) dlopen(f, 1) */
/* #define pg_dlopen(f) dlopen(f, 2) */
#define pg_dlopen(f) dlopen(f, (RTLD_NOW|RTLD_GLOBAL))
#define pg_dlsym dlsym
#define pg_dlclose dlclose
#define pg_dlerror dlerror
#endif
/* port.c */
#endif /* PORT_PROTOS_H */

View File

@ -1,5 +1,6 @@
/* -*- C -*-
*
/* $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.2 2001/05/12 01:30:30 petere Exp $ */
/*
* plpython.c - python as a procedural language for PostgreSQL
*
* IDENTIFICATION
@ -33,6 +34,8 @@
*
**********************************************************************/
#include "postgres.h"
/* system stuff
*/
#include <dlfcn.h>

View File

@ -1,5 +1,7 @@
#ifndef PLPYTHON_NEW_H
#define PLPYTHON_NEW_H
/* $Header: /cvsroot/pgsql/src/pl/plpython/Attic/plpython.h,v 1.2 2001/05/12 01:30:30 petere Exp $ */
#ifndef PLPYTHON_H
#define PLPYTHON_H
#define DEBUG_EXC 0
#define DEBUG_LEVEL 0
@ -63,4 +65,4 @@
# define refc(O)
#endif
#endif
#endif /* PLPYTHON_H */

View File

@ -1,9 +0,0 @@
CREATE FUNCTION plpython_call_handler() RETURNS opaque
AS '/usr/local/lib/postgresql/langs/plpython.so'
LANGUAGE 'c';
CREATE TRUSTED PROCEDURAL LANGUAGE 'plpython'
HANDLER plpython_call_handler
LANCOMPILER 'plpython';

View File

@ -1,16 +0,0 @@
DROP DATABASE
CREATE DATABASE
NOTICE: CREATE TABLE will create implicit sequence 'users_userid_seq' for SERIAL column 'users.userid'
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'users_userid_key' for table 'users'
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'users_pkey' for table 'users'
NOTICE: CREATE TABLE will create implicit sequence 'taxonomy_id_seq' for SERIAL column 'taxonomy.id'
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'taxonomy_pkey' for table 'taxonomy'
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'taxonomy_name_key' for table 'taxonomy'
NOTICE: CREATE TABLE will create implicit sequence 'entry_eid_seq' for SERIAL column 'entry.eid'
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'entry_pkey' for table 'entry'
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'entry_eid_key' for table 'entry'
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
NOTICE: CREATE TABLE will create implicit sequence 'sequences_pid_seq' for SERIAL column 'sequences.pid'
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'sequences_pkey' for table 'sequences'
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)

View File

@ -1,36 +1,33 @@
#!/bin/sh
DBNAME=pltest
DBUSER=postgres
PATH=$PATH:/usr/local/pgsql/bin
export DBNAME DBUSER
echo -n "*** Destroy $DBNAME."
dropdb -U$DBUSER $DBNAME > test.log 2>&1
dropdb $DBNAME > test.log 2>&1
echo " Done. ***"
echo -n "*** Create $DBNAME."
createdb -U$DBUSER $DBNAME >> test.log 2>&1
createdb $DBNAME >> test.log 2>&1
echo " Done. ***"
echo -n "*** Create plpython."
psql -U$DBUSER -q $DBNAME < plpython_create.sql >> test.log 2>&1
createlang plpython $DBNAME >> test.log 2>&1
echo " Done. ***"
echo -n "*** Create tables"
psql -U$DBUSER -q $DBNAME < plpython_schema.sql >> test.log 2>&1
psql -q $DBNAME < plpython_schema.sql >> test.log 2>&1
echo -n ", data"
psql -U$DBUSER -q $DBNAME < plpython_populate.sql >> test.log 2>&1
psql -q $DBNAME < plpython_populate.sql >> test.log 2>&1
echo -n ", and functions and triggers."
psql -U$DBUSER -q $DBNAME < plpython_function.sql >> test.log 2>&1
psql -q $DBNAME < plpython_function.sql >> test.log 2>&1
echo " Done. ***"
echo -n "*** Running feature tests."
psql -U$DBUSER -q -e $DBNAME < plpython_test.sql > feature.output 2>&1
psql -q -e $DBNAME < plpython_test.sql > feature.output 2>&1
echo " Done. ***"
echo -n "*** Running error handling tests."
psql -U$DBUSER -q -e $DBNAME < plpython_error.sql > error.output 2>&1
psql -q -e $DBNAME < plpython_error.sql > error.output 2>&1
echo " Done. ***"
echo -n "*** Checking the results of the feature tests"
@ -49,4 +46,3 @@ echo " any differences are due only to the oid encoded in the "
echo " python function name. ***"
# or write a fancier error checker...

View File

@ -1,5 +0,0 @@
#!/bin/sh
cd /usr/local/lib/postgresql/langs
cp /home/andrew/projects/pg/plpython/plpython.so ./
cd /home/andrew/projects/pg/plpython