Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
13a0e910
Commit
13a0e910
authored
Aug 01, 2003
by
Marc G. Fournier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parent
2c018f9b
Changes
14
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
0 additions
and
5581 deletions
+0
-5581
src/interfaces/python/Announce
src/interfaces/python/Announce
+0
-158
src/interfaces/python/ChangeLog
src/interfaces/python/ChangeLog
+0
-125
src/interfaces/python/GNUmakefile
src/interfaces/python/GNUmakefile
+0
-59
src/interfaces/python/PyGreSQL.spec
src/interfaces/python/PyGreSQL.spec
+0
-57
src/interfaces/python/README
src/interfaces/python/README
+0
-264
src/interfaces/python/Setup.in.raw
src/interfaces/python/Setup.in.raw
+0
-3
src/interfaces/python/pg.py
src/interfaces/python/pg.py
+0
-302
src/interfaces/python/pgdb.py
src/interfaces/python/pgdb.py
+0
-452
src/interfaces/python/pgmodule.c
src/interfaces/python/pgmodule.c
+0
-3257
src/interfaces/python/setup.py
src/interfaces/python/setup.py
+0
-56
src/interfaces/python/tutorial/advanced.py
src/interfaces/python/tutorial/advanced.py
+0
-198
src/interfaces/python/tutorial/basics.py
src/interfaces/python/tutorial/basics.py
+0
-296
src/interfaces/python/tutorial/func.py
src/interfaces/python/tutorial/func.py
+0
-205
src/interfaces/python/tutorial/syscat.py
src/interfaces/python/tutorial/syscat.py
+0
-149
No files found.
src/interfaces/python/Announce
deleted
100644 → 0
View file @
2c018f9b
Announce: Release of PyGreSQL version 3.3
=========================================
PyGreSQL v3.3 has been released.
It is available at: ftp://ftp.druid.net/pub/distrib/PyGreSQL.tgz. If
you are running NetBSD, look in the packages directory under databases.
There is also a package in the FreeBSD ports collection.
From March 1 2001 the PyGreSQL development has moved into the PostgreSQL
development tree.
PostgreSQL is a database system derived from Postgres4.2. It conforms
to (most of) ANSI SQL and offers many interesting capabilities (C
dynamic linking for functions or type definition, etc.). This package
is copyright by the Regents of the University of California, and is
freely distributable.
Python is an interpreted programming language. It is object oriented,
simple to use (light syntax, simple and straightforward statements), and
has many extensions for building GUIs, interfacing with WWW, etc. An
intelligent web browser (HotJava like) is currently under development
(November 1995), and this should open programmers many doors. Python is
copyrighted by Stichting S Mathematisch Centrum, Amsterdam, The
Netherlands, and is freely distributable.
PyGreSQL is a python module that interfaces to a PostgreSQL database. It
embeds the PostgreSQL query library to allow easy use of the powerful
PostgreSQL features from a Python script.
This release fixes a few bugs, adds a few minor features and makes a
few speedups in the code.
The next release (unless serious bugs are found) will be to match PyGreSQL
to version 2.0 of Python.
See the other changes below or in the Changelog file.
PyGreSQL 2.0 was developed and tested on a NetBSD 1.3_BETA system. It
is based on the PyGres95 code written by Pascal Andre,
andre@chimay.via.ecp.fr. I changed the version to 2.0 and updated the
code for Python 1.5 and PostgreSQL 6.2.1. While I was at it I upgraded
the code to use full ANSI style prototypes and changed the order of
arguments to connect. Later versions are fixes and enhancements to that.
The latest version of PyGreSQL works with Python 1.5.2 and PostgreSQL 7.0.x
Important changes from PyGreSQL 3.2 to PyGreSQL 3.3
- Added NUMERICOID to list of returned types. This fixes a bug when
returning aggregates in the latest version of PostgreSQL.
Important changes from PyGreSQL 3.1 to PyGreSQL 3.2
Note that there are very few changes to PostgreSQL between 3.1 and
3.2. The main reason for the release is the move into the PostgreSQL
development tree. Even the WIN32 changes are pretty minor.
- Add WIN32 support (gerhard@bigfoot.de)
- Fix some DB-API quoting problems (niall.smart@ebeon.com)
- Moved development into PostgreSQL development tree.
Important changes from PyGreSQL 3.0 to PyGreSQL 3.1
- Fix some quoting functions. In particular handle NULLs better.
- Use a method to add primary key information rather than direct
manipulation of the class structures.
- Break decimal out in _quote (in pg.py) and treat it as float.
- Treat timestamp like date for quoting purposes.
- Remove a redundant SELECT from the get method speeding it, and insert
since it calls get, up a little.
- Add test for BOOL type in typecast method to pgdbTypeCache class.
(tv@beamnet.de)
- Fix pgdb.py to send port as integer to lower level function
(dildog@l0pht.com)
- Change pg.py to speed up some operations
- Allow updates on tables with no primary keys.
Important changes from PyGreSQL 2.4 to PyGreSQL 3.0:
- Remove strlen() call from pglarge_write() and get size from object.
(Richard@Bouska.cz)
- Add a little more error checking to the quote function in the wrapper
- Add extra checking in _quote function
- Wrap query in pg.py for debugging
- Add DB-API 2.0 support to pgmodule.c (andre@via.ecp.fr)
- Add DB-API 2.0 wrapper pgdb.py (andre@via.ecp.fr)
- Correct keyword clash (temp) in tutorial
- Clean up layout of tutorial
- Return NULL values as None (rlawrence@lastfoot.com) (WARNING: This
will cause backwards compatibility issues.)
- Change None to NULL in insert and update
- Change hash-bang lines to use /usr/bin/env
- Clearing date should be blank (NULL) not TODAY
- Quote backslashes in strings in _quote (brian@CSUA.Berkeley.EDU)
- Expanded and clarified build instructions (tbryan@starship.python.net)
- Make code thread safe (Jerome.Alet@unice.fr)
- Add README.distutils (mwa@gate.net & jeremy@cnri.reston.va.us)
- Many fixes and increased DB-API compliance by chifungfan@yahoo.com,
tony@printra.net, jeremy@alum.mit.edu and others to get the final
version ready to release.
Important changes from PyGreSQL 2.3 to PyGreSQL 2.4:
- Insert returns None if the user doesn't have select permissions
on the table. It can (and does) happen that one has insert but
not select permissions on a table.
- Added ntuples() method to query object (brit@druid.net)
- Corrected a bug related to getresult() and the money type
- Corrected a bug related to negative money amounts
- Allow update based on primary key if munged oid not available and
table has a primary key
- Add many __doc__ strings. (andre@via.ecp.fr)
- Get method works with views if key specified
Important changes from PyGreSQL 2.2 to PyGreSQL 2.3:
- connect.host returns "localhost" when connected to Unix socket
(torppa@tuhnu.cutery.fi)
- Use PyArg_ParseTupleAndKeywords in connect() (torppa@tuhnu.cutery.fi)
- fixes and cleanups (torppa@tuhnu.cutery.fi)
- Fixed memory leak in dictresult() (terekhov@emc.com)
- Deprecated pgext.py - functionality now in pg.py
- More cleanups to the tutorial
- Added fileno() method - terekhov@emc.com (Mikhail Terekhov)
- added money type to quoting function
- Compiles cleanly with more warnings turned on
- Returns PostgreSQL error message on error
- Init accepts keywords (Jarkko Torppa)
- Convenience functions can be overridden (Jarkko Torppa)
- added close() method
Important changes from PyGreSQL 2.1 to PyGreSQL 2.2:
- Added user and password support thanks to Ng Pheng Siong <ngps@post1.com>
- Insert queries return the inserted oid
- Add new pg wrapper (C module renamed to _pg)
- Wrapped database connection in a class.
- Cleaned up some of the tutorial. (More work needed.)
- Added version and __version__. Thanks to thilo@eevolute.com for
the suggestion.
Important changes from PyGreSQL 2.0 to PyGreSQL 2.1:
- return fields as proper Python objects for field type
- Cleaned up pgext.py
- Added dictresult method
Important changes from Pygres95 1.0b to PyGreSQL 2.0:
- Updated code for PostgreSQL 6.2.1 and Python 1.5.
- Reformatted code and converted to ANSI .
- Changed name to PyGreSQL (from PyGres95.)
- Changed order of arguments to connect function.
- Created new type pgqueryobject and moved certain methods to it.
- Added a print function for pgqueryobject
- Various code changes - mostly stylistic.
For more information about each package, please have a look to their
web pages:
- Python : http://www.python.org/
- PostgreSQL : http://www.PostgreSQL.org/
- PyGreSQL : http://www.druid.net/pygresql/
D'Arcy J.M. Cain
darcy@druid.net
src/interfaces/python/ChangeLog
deleted
100644 → 0
View file @
2c018f9b
PyGreSQL changelog.
===================
This software is copyright (c) 1995, Pascal Andre (andre@via.ecp.fr)
Further copyright 1997, 1998 and 1999 by D'Arcy J.M. Cain (darcy@druid.net)
See file README for copyright information.
Version 3.3
A few cleanups. Mostly there was some confusion about the latest version
and so I am bumping the number to keep it straight.
- Added NUMERICOID to list of returned types. This fixes a bug when
returning aggregates.
Version 3.2
- Add WIN32 support (gerhard@bigfoot.de)
- Fix some DB-API quoting problems (niall.smart@ebeon.com)
- Moved development into PostgreSQL development tree.
Version 3.1
- Fix some quoting functions. In particular handle NULLs better.
- Use a method to add primary key information rather than direct
manipulation of the class structures.
- Break decimal out in _quote (in pg.py) and treat it as float.
- Treat timestamp like date for quoting purposes.
- Remove a redundant SELECT from the get method speeding it, and insert
since it calls get, up a little.
- Add test for BOOL type in typecast method to pgdbTypeCache class.
(tv@beamnet.de)
- Fix pgdb.py to send port as integer to lower level function
(dildog@l0pht.com)
- Change pg.py to speed up some operations
- Allow updates on tables with no primary keys.
Version 3.0
- Remove strlen() call from pglarge_write() and get size from object.
(Richard@Bouska.cz)
- Add a little more error checking to the quote function in the wrapper
- Add extra checking in _quote function
- Wrap query in pg.py for debugging
- Add DB-API 2.0 support to pgmodule.c (andre@via.ecp.fr)
- Add DB-API 2.0 wrapper pgdb.py (andre@via.ecp.fr)
- Correct keyword clash (temp) in tutorial
- Clean up layout of tutorial
- Return NULL values as None (rlawrence@lastfoot.com)
- Change None to NULL in insert and update
- Change hash-bang lines to use /usr/bin/env
- Clearing date should be blank (NULL) not TODAY
- Quote backslashes in strings in _quote (brian@CSUA.Berkeley.EDU)
- Expanded and clarified build instructions (tbryan@starship.python.net)
- Make code thread safe (Jerome.Alet@unice.fr)
- Add README.distutils (mwa@gate.net & jeremy@cnri.reston.va.us)
- Many fixes and increased DB-API compliance by chifungfan@yahoo.com,
tony@printra.net, jeremy@alum.mit.edu and others to get the final
version ready to release.
Version 2.4
- Insert returns None if the user doesn't have select permissions
on the table. It can (and does) happen that one has insert but
not select permissions on a table.
- Added ntuples() method to query object (brit@druid.net)
- Corrected a bug related to getresult() and the money type
- Corrected a bug related to negative money amounts
- Allow update based on primary key if munged oid not available and
table has a primary key
- Add many __doc__ strings. (andre@via.ecp.fr)
- Get method works with views if key specified
Version 2.3
- connect.host returns "localhost" when connected to Unix socket
(torppa@tuhnu.cutery.fi)
- Use PyArg_ParseTupleAndKeywords in connect() (torppa@tuhnu.cutery.fi)
- fixes and cleanups (torppa@tuhnu.cutery.fi)
- Fixed memory leak in dictresult() (terekhov@emc.com)
- Deprecated pgext.py - functionality now in pg.py
- More cleanups to the tutorial
- Added fileno() method - terekhov@emc.com (Mikhail Terekhov)
- added money type to quoting function
- Compiles cleanly with more warnings turned on
- Returns PostgreSQL error message on error
- Init accepts keywords (Jarkko Torppa)
- Convenience functions can be overridden (Jarkko Torppa)
- added close() method
Version 2.2
- Added user and password support thanks to Ng Pheng Siong <ngps@post1.com>
- Insert queries return the inserted oid
- Add new pg wrapper (C modile renamed to _pg)
- Wrapped database connection in a class.
- Cleaned up some of the tutorial. (More work needed.)
- Added version and __version__. Thanks to thilo@eevolute.com for
the suggestion.
Version 2.1
- return fields as proper Python objects for field type
- Cleaned up pgext.py
- Added dictresult method
Version 2.0 (23/12/1997):
- updated code for PostgreSQL 6.2.1 and Python 1.5
- reformatted code and converted to ANSI
- Changed name to PyGreSQL (from PyGres95)
- changed order of arguments to connect function
- Created new type pgqueryobject and moved certain methods to it.
- Added a print function for pgqueryobject
Version 1.0b (4/11/1995):
- keyword support for connect function moved from library file to C code
and taken away from library.
- rewrote documentation
- bug fix in connect function
- enhancements in large objects interface methods
Version 1.0a (30/10/1995) (limited release):
- module adapted to standard Python syntax
- keyword support for connect function in library file
- rewrote default parameters interface (internal use of strings)
- fixed minor bugs in module interface
- redefinition of error messages
Version 0.9b (10/10/1995) (first public release):
- large objects implementation
- many bug fixes, enhancements, ...
Version 0.1a (7/10/1995):
- basic libpq functions (SQL access)
src/interfaces/python/GNUmakefile
deleted
100644 → 0
View file @
2c018f9b
# $Header: /cvsroot/pgsql/src/interfaces/python/Attic/GNUmakefile,v 1.16 2003/03/21 17:18:34 petere Exp $
subdir
=
src/interfaces/python
top_builddir
=
../../..
include
$(top_builddir)/src/Makefile.global
NAME
=
_pgmodule
SO_MAJOR_VERSION
=
2
SO_MINOR_VERSION
=
4
OBJS
=
pgmodule.o
SHLIB_LINK
=
$(libpq)
ifeq
($(PORTNAME), cygwin)
override
CPPFLAGS
+=
-DUSE_DL_IMPORT
SHLIB_LINK
+=
$(python_libspec)
endif
include
$(top_srcdir)/src/Makefile.shlib
override CPPFLAGS
:
= -I$(libpq_srcdir) $(CPPFLAGS) $(python_includespec)
all
:
all-lib
all-lib
:
libpq-all
.PHONY
:
libpq-all
libpq-all
:
$(MAKE)
-C
$(libpq_builddir)
all
install-warning-msg
:=
{
\
echo
"*** Skipping the installation of the Python interface module for lack"
;
\
echo
"*** of permissions. To install it, change to the directory"
;
\
echo
"***
`
pwd
`
,"
;
\
echo
"*** become the appropriate user, and do '
$(MAKE)
install'."
;
}
install
:
all installdirs
@
if
test
-w
$(DESTDIR)$(python_moduleexecdir)
&&
test
-w
$(DESTDIR)$(python_moduledir)
;
then
\
echo
"
$(INSTALL_SHLIB)
$(shlib)
$(DESTDIR)$(python_moduleexecdir)
/_pgmodule
$(DLSUFFIX)
"
;
\
$(INSTALL_SHLIB)
$(shlib)
$(DESTDIR)$(python_moduleexecdir)
/_pgmodule
$(DLSUFFIX)
;
\
\
echo
"
$(INSTALL_DATA)
$(srcdir)
/pg.py
$(DESTDIR)$(python_moduledir)
/pg.py"
;
\
$(INSTALL_DATA)
$(srcdir)
/pg.py
$(DESTDIR)$(python_moduledir)
/pg.py
;
\
\
echo
"
$(INSTALL_DATA)
$(srcdir)
/pgdb.py
$(DESTDIR)$(python_moduledir)
/pgdb.py"
;
\
$(INSTALL_DATA)
$(srcdir)
/pgdb.py
$(DESTDIR)$(python_moduledir)
/pgdb.py
;
\
else
\
$
(
install-warning-msg
)
;
\
fi
installdirs
:
$(mkinstalldirs)
$(DESTDIR)$(python_moduleexecdir)
$(DESTDIR)$(python_moduledir)
uninstall
:
rm
-f
$(DESTDIR)$(python_moduleexecdir)
/_pgmodule
$(DLSUFFIX)
\
$(DESTDIR)$(python_moduledir)
/pg.py
\
$(DESTDIR)$(python_moduledir)
/pgdb.py
clean distclean maintainer-clean
:
clean-lib
rm
-f
$(OBJS)
src/interfaces/python/PyGreSQL.spec
deleted
100644 → 0
View file @
2c018f9b
%define version 3.0
%define release pre20000310
%define name PyGreSQL
%define pythonversion 1.5
Source: %{name}-%{version}-%{release}.tgz
Summary: A Python interface for PostgreSQL database.
Name: %{name}
Version: %{version}
Release: %{release}
#Patch:
Group: Applications/Databases
BuildRoot: /tmp/rpmbuild_%{name}
Copyright: GPL-like
Requires: python >= %{pythonversion}, postgresql
Packager: Hartmut Goebel <hartmut@goebel.noris.de>
Vendor: D'Arcy J.M. Cain <darcy@druid.net>
URL: http://www.druid.net/pygresql/
%changelog
#* Tue Oct 06 1998 Fabio Coatti <cova@felix.unife.it>
#- fixed installation directory files list
%description
PyGreSQL is a python module that interfaces to a PostgreSQL database. It
embeds the PostgreSQL query library to allow easy use of the powerful
PostgreSQL features from a Python script.
Version 3.0 includes DB-API 2.0 support.
%prep
rm -rf $RPM_BUILD_ROOT
%setup -n %{name}-%{version}-%{release}
#%patch
%build
mkdir -p $RPM_BUILD_ROOT/usr/lib/python%{pythonversion}/lib-dynload
cc -fpic -shared -o $RPM_BUILD_ROOT/usr/lib/python%{pythonversion}/lib-dynload/_pg.so -I/usr/include/pgsql/ -I/usr/include/python1.5 pgmodule.c -lpq
## import fails, since _pg is not yet installed
python -c 'import pg' || true
python -c 'import pgdb' || true
%install
cp *.py *.pyc $RPM_BUILD_ROOT/usr/lib/python%{pythonversion}/
cd $RPM_BUILD_ROOT
find . -type f | sed 's,^\.,\%attr(-\,root\,root) ,' > $RPM_BUILD_DIR/file.list.%{name}
find . -type l | sed 's,^\.,\%attr(-\,root\,root) ,' >> $RPM_BUILD_DIR/file.list.%{name}
%files -f ../file.list.%{name}
%doc %attr(-,root,root) Announce ChangeLog README tutorial
%clean
rm -rf $RPM_BUILD_ROOT
cd $RPM_BUILD_DIR
rm -rf %{name}-%{version}-%{release} file.list.%{name}
src/interfaces/python/README
deleted
100644 → 0
View file @
2c018f9b
This diff is collapsed.
Click to expand it.
src/interfaces/python/Setup.in.raw
deleted
100644 → 0
View file @
2c018f9b
*shared*
_pg pgmodule.c -I@libpq_srcdir@ @INCLUDES@ -L@libpq_builddir@ -lpq @EXTRA_LIBS@
src/interfaces/python/pg.py
deleted
100644 → 0
View file @
2c018f9b
# pg.py
# Written by D'Arcy J.M. Cain
# This library implements some basic database management stuff. It
# includes the pg module and builds on it. This is known as the
# "Classic" interface. For DB-API compliance use the pgdb module.
from
_pg
import
*
from
types
import
*
import
string
,
re
,
sys
# utility function
# We expect int, seq, decimal, text or date (more later)
def
_quote
(
d
,
t
):
if
d
==
None
:
return
"NULL"
if
t
in
[
'int'
,
'seq'
]:
if
d
==
""
:
return
"NULL"
return
"
%
d"
%
long
(
d
)
if
t
==
'decimal'
:
if
d
==
""
:
return
"NULL"
return
"
%
f"
%
float
(
d
)
if
t
==
'money'
:
if
d
==
""
:
return
"NULL"
return
"'
%.2
f'"
%
float
(
d
)
if
t
==
'bool'
:
# Can't run upper() on these
if
d
in
(
0
,
1
):
return
(
"'f'"
,
"'t'"
)[
d
]
if
string
.
upper
(
d
)
in
[
'T'
,
'TRUE'
,
'Y'
,
'YES'
,
'1'
,
'ON'
]:
return
"'t'"
else
:
return
"'f'"
if
t
==
'date'
and
d
==
''
:
return
"NULL"
if
t
in
(
'inet'
,
'cidr'
)
and
d
==
''
:
return
"NULL"
return
"'
%
s'"
%
string
.
strip
(
re
.
sub
(
"'"
,
"''"
,
\
re
.
sub
(
"
\\\\
"
,
"
\\\\\\\\
"
,
"
%
s"
%
d
)))
class
DB
:
"""This class wraps the pg connection type"""
def
__init__
(
self
,
*
args
,
**
kw
):
self
.
db
=
apply
(
connect
,
args
,
kw
)
# Create convience methods, in a way that is still overridable
# (members are not copied because they are actually functions)
for
e
in
self
.
db
.
__methods__
:
setattr
(
self
,
e
,
getattr
(
self
.
db
,
e
))
self
.
__attnames__
=
{}
self
.
__pkeys__
=
{}
self
.
debug
=
None
# For debugging scripts, set to output format
# that takes a single string arg. For example
# in a CGI set to "%s<BR>"
def
_do_debug
(
self
,
s
):
if
not
self
.
debug
:
return
if
type
(
self
.
debug
)
==
StringType
:
print
self
.
debug
%
s
if
type
(
self
.
debug
)
==
FunctionType
:
self
.
debug
(
s
)
if
type
(
self
.
debug
)
==
FileType
:
print
>>
self
.
debug
,
s
# wrap query for debugging
def
query
(
self
,
qstr
):
self
.
_do_debug
(
qstr
)
return
self
.
db
.
query
(
qstr
)
def
pkey
(
self
,
cl
,
newpkey
=
None
):
"""This method returns the primary key of a class. If newpkey
is set and is set and is not a dictionary then set that
value as the primary key of the class. If it is a dictionary
then replace the __pkeys__ dictionary with it."""
# Get all the primary keys at once
if
type
(
newpkey
)
==
DictType
:
self
.
__pkeys__
=
newpkey
return
if
newpkey
:
self
.
__pkeys__
[
cl
]
=
newpkey
return
newpkey
if
self
.
__pkeys__
==
{}:
for
rel
,
att
in
self
.
db
.
query
(
"""SELECT
pg_class.relname, pg_attribute.attname
FROM pg_class, pg_attribute, pg_index
WHERE pg_class.oid = pg_attribute.attrelid AND
pg_class.oid = pg_index.indrelid AND
pg_index.indkey[0] = pg_attribute.attnum AND
pg_index.indisprimary = 't' AND
pg_attribute.attisdropped = 'f'"""
)
.
getresult
():
self
.
__pkeys__
[
rel
]
=
att
# will raise an exception if primary key doesn't exist
return
self
.
__pkeys__
[
cl
]
def
get_databases
(
self
):
l
=
[]
for
n
in
self
.
db
.
query
(
"SELECT datname FROM pg_database"
)
.
getresult
():
l
.
append
(
n
[
0
])
return
l
def
get_tables
(
self
):
l
=
[]
for
n
in
self
.
db
.
query
(
"""SELECT relname FROM pg_class
WHERE relkind = 'r' AND
relname !~ '^Inv' AND
relname !~ '^pg_'"""
)
.
getresult
():
l
.
append
(
n
[
0
])
return
l
def
get_attnames
(
self
,
cl
,
newattnames
=
None
):
"""This method gets a list of attribute names for a class. If
the optional newattnames exists it must be a dictionary and
will become the new attribute names dictionary."""
if
type
(
newattnames
)
==
DictType
:
self
.
__attnames__
=
newattnames
return
elif
newattnames
:
raise
error
,
"If supplied, newattnames must be a dictionary"
# May as well cache them
if
self
.
__attnames__
.
has_key
(
cl
):
return
self
.
__attnames__
[
cl
]
query
=
"""SELECT pg_attribute.attname, pg_type.typname
FROM pg_class, pg_attribute, pg_type
WHERE pg_class.relname = '
%
s' AND
pg_attribute.attnum > 0 AND
pg_attribute.attrelid = pg_class.oid AND
pg_attribute.atttypid = pg_type.oid AND
pg_attribute.attisdropped = 'f'"""
l
=
{}
for
attname
,
typname
in
self
.
db
.
query
(
query
%
cl
)
.
getresult
():
if
re
.
match
(
"^int"
,
typname
):
l
[
attname
]
=
'int'
elif
re
.
match
(
"^oid"
,
typname
):
l
[
attname
]
=
'int'
elif
re
.
match
(
"^text"
,
typname
):
l
[
attname
]
=
'text'
elif
re
.
match
(
"^char"
,
typname
):
l
[
attname
]
=
'text'
elif
re
.
match
(
"^name"
,
typname
):
l
[
attname
]
=
'text'
elif
re
.
match
(
"^abstime"
,
typname
):
l
[
attname
]
=
'date'
elif
re
.
match
(
"^date"
,
typname
):
l
[
attname
]
=
'date'
elif
re
.
match
(
"^timestamp"
,
typname
):
l
[
attname
]
=
'date'
elif
re
.
match
(
"^bool"
,
typname
):
l
[
attname
]
=
'bool'
elif
re
.
match
(
"^float"
,
typname
):
l
[
attname
]
=
'decimal'
elif
re
.
match
(
"^money"
,
typname
):
l
[
attname
]
=
'money'
else
:
l
[
attname
]
=
'text'
l
[
'oid'
]
=
'int'
# every table has this
self
.
__attnames__
[
cl
]
=
l
# cache it
return
self
.
__attnames__
[
cl
]
# return a tuple from a database
def
get
(
self
,
cl
,
arg
,
keyname
=
None
,
view
=
0
):
if
cl
[
-
1
]
==
'*'
:
# need parent table name
xcl
=
cl
[:
-
1
]
else
:
xcl
=
cl
if
keyname
==
None
:
# use the primary key by default
keyname
=
self
.
pkey
(
xcl
)
fnames
=
self
.
get_attnames
(
xcl
)
if
type
(
arg
)
==
DictType
:
# To allow users to work with multiple tables we munge the
# name when the key is "oid"
if
keyname
==
'oid'
:
k
=
arg
[
'oid_
%
s'
%
xcl
]
else
:
k
=
arg
[
keyname
]
else
:
k
=
arg
arg
=
{}
# We want the oid for later updates if that isn't the key
if
keyname
==
'oid'
:
q
=
"SELECT * FROM
%
s WHERE oid =
%
s"
%
(
cl
,
k
)
elif
view
:
q
=
"SELECT * FROM
%
s WHERE
%
s =
%
s"
%
\
(
cl
,
keyname
,
_quote
(
k
,
fnames
[
keyname
]))
else
:
q
=
"SELECT oid AS oid_
%
s,
%
s FROM
%
s WHERE
%
s =
%
s"
%
\
(
xcl
,
string
.
join
(
fnames
.
keys
(),
','
),
\
cl
,
keyname
,
_quote
(
k
,
fnames
[
keyname
]))
self
.
_do_debug
(
q
)
res
=
self
.
db
.
query
(
q
)
.
dictresult
()
if
res
==
[]:
raise
error
,
\
"No such record in
%
s where
%
s is
%
s"
%
\
(
cl
,
keyname
,
_quote
(
k
,
fnames
[
keyname
]))
return
None
for
k
in
res
[
0
]
.
keys
():
arg
[
k
]
=
res
[
0
][
k
]
return
arg
# Inserts a new tuple into a table
# We currently don't support insert into views although PostgreSQL does
def
insert
(
self
,
cl
,
a
):
fnames
=
self
.
get_attnames
(
cl
)
l
=
[]
n
=
[]
for
f
in
fnames
.
keys
():
if
f
!=
'oid'
and
a
.
has_key
(
f
):
l
.
append
(
_quote
(
a
[
f
],
fnames
[
f
]))
n
.
append
(
f
)
try
:
q
=
"INSERT INTO
%
s (
%
s) VALUES (
%
s)"
%
\
(
cl
,
string
.
join
(
n
,
','
),
string
.
join
(
l
,
','
))
self
.
_do_debug
(
q
)
a
[
'oid_
%
s'
%
cl
]
=
self
.
db
.
query
(
q
)
except
:
raise
error
,
"Error inserting into
%
s:
%
s"
%
(
cl
,
sys
.
exc_value
)
# reload the dictionary to catch things modified by engine
# note that get() changes 'oid' below to oid_table
# if no read perms (it can and does happen) return None
try
:
return
self
.
get
(
cl
,
a
,
'oid'
)
except
:
return
None
# Update always works on the oid which get returns if available
# otherwise use the primary key. Fail if neither.
def
update
(
self
,
cl
,
a
):
self
.
pkey
(
cl
)
# make sure we have a self.__pkeys__ dictionary
foid
=
'oid_
%
s'
%
cl
if
a
.
has_key
(
foid
):
where
=
"oid =
%
s"
%
a
[
foid
]
elif
self
.
__pkeys__
.
has_key
(
cl
)
and
a
.
has_key
(
self
.
__pkeys__
[
cl
]):
where
=
"
%
s = '
%
s'"
%
(
self
.
__pkeys__
[
cl
],
a
[
self
.
__pkeys__
[
cl
]])
else
:
raise
error
,
"Update needs primary key or oid as
%
s"
%
foid
v
=
[]
k
=
0
fnames
=
self
.
get_attnames
(
cl
)
for
ff
in
fnames
.
keys
():
if
ff
!=
'oid'
and
a
.
has_key
(
ff
):
v
.
append
(
"
%
s =
%
s"
%
(
ff
,
_quote
(
a
[
ff
],
fnames
[
ff
])))
if
v
==
[]:
return
None
try
:
q
=
"UPDATE
%
s SET
%
s WHERE
%
s"
%
\
(
cl
,
string
.
join
(
v
,
','
),
where
)
self
.
_do_debug
(
q
)
self
.
db
.
query
(
q
)
except
:
raise
error
,
"Can't update
%
s:
%
s"
%
(
cl
,
sys
.
exc_value
)
# reload the dictionary to catch things modified by engine
if
a
.
has_key
(
foid
):
return
self
.
get
(
cl
,
a
,
'oid'
)
else
:
return
self
.
get
(
cl
,
a
)
# At some point we will need a way to get defaults from a table
def
clear
(
self
,
cl
,
a
=
{}):
fnames
=
self
.
get_attnames
(
cl
)
for
ff
in
fnames
.
keys
():
if
fnames
[
ff
]
in
[
'int'
,
'decimal'
,
'seq'
,
'money'
]:
a
[
ff
]
=
0
else
:
a
[
ff
]
=
""
a
[
'oid'
]
=
0
return
a
# Like update, delete works on the oid
# one day we will be testing that the record to be deleted
# isn't referenced somewhere (or else PostgreSQL will)
def
delete
(
self
,
cl
,
a
):
try
:
q
=
"DELETE FROM
%
s WHERE oid =
%
s"
%
(
cl
,
a
[
'oid_
%
s'
%
cl
])
self
.
_do_debug
(
q
)
self
.
db
.
query
(
q
)
except
:
raise
error
,
"Can't delete
%
s:
%
s"
%
(
cl
,
sys
.
exc_value
)
return
None
src/interfaces/python/pgdb.py
deleted
100644 → 0
View file @
2c018f9b
This diff is collapsed.
Click to expand it.
src/interfaces/python/pgmodule.c
deleted
100644 → 0
View file @
2c018f9b
This diff is collapsed.
Click to expand it.
src/interfaces/python/setup.py
deleted
100755 → 0
View file @
2c018f9b
#!/usr/bin/env python
# Setup script for the PyGreSQL version 3
# created 2000/04 Mark Alexander <mwa@gate.net>
# tweaked 2000/05 Jeremy Hylton <jeremy@cnri.reston.va.us>
# win32 support 2001/01 Gerhard Haering <gerhard@bigfoot.de>
# requires distutils; standard in Python 1.6, otherwise download from
# http://www.python.org/sigs/distutils-sig/download.html
# You may have to change the first 3 variables (include_dirs,
# library_dirs, optional_libs) to match your postgres distribution.
# Now, you can:
# python setup.py build # to build the module
# python setup.py install # to install it
# See http://www.python.org/sigs/distutils-sig/doc/ for more information
# on using distutils to install Python programs.
from
distutils.core
import
setup
from
distutils.extension
import
Extension
import
sys
if
sys
.
platform
==
"win32"
:
# If you want to build from source; you must have built a win32 native libpq # before and copied libpq.dll into the PyGreSQL root directory.
win_pg_build_root
=
'd:/dev/pg/postgresql-7.0.2/'
include_dirs
=
[
win_pg_build_root
+
'src/include'
,
win_pg_build_root
+
'/src/include/libpq'
,
win_pg_build_root
+
'src'
,
win_pg_build_root
+
'src/interfaces/libpq'
]
library_dirs
=
[
win_pg_build_root
+
'src/interfaces/libpq/Release'
]
optional_libs
=
[
'libpqdll'
,
'wsock32'
,
'advapi32'
]
data_files
=
[
'libpq.dll'
]
else
:
include_dirs
=
[
'../../include'
,
'../libpq'
,
'/usr/include/pgsql'
]
library_dirs
=
[
'../libpq'
,
'/usr/lib/pgsql'
]
optional_libs
=
[
'pq'
]
data_files
=
[]
setup
(
name
=
"PyGreSQL"
,
version
=
"3.3"
,
description
=
"Python PostgreSQL Interfaces"
,
author
=
"D'Arcy J. M. Cain"
,
author_email
=
"darcy@druid.net"
,
url
=
"http://www.druid.net/pygresql/"
,
licence
=
"Python"
,
py_modules
=
[
'pg'
,
'pgdb'
],
ext_modules
=
[
Extension
(
name
=
'_pg'
,
sources
=
[
'pgmodule.c'
],
include_dirs
=
include_dirs
,
library_dirs
=
library_dirs
,
libraries
=
optional_libs
)],
data_files
=
data_files
)
src/interfaces/python/tutorial/advanced.py
deleted
100755 → 0
View file @
2c018f9b
#! /usr/bin/env python
# advanced.py - demo of advanced features of PostGres. Some may not be ANSI.
# inspired from the Postgres tutorial
# adapted to Python 1995 by Pascal Andre
print
"""
__________________________________________________________________
MODULE ADVANCED.PY : ADVANCED POSTGRES SQL COMMANDS TUTORIAL
This module is designed for being imported from python prompt
In order to run the samples included here, first create a connection
using : cnx = advanced.DB(...)
The "..." should be replaced with whatever arguments you need to open an
existing database. Usually all you need is the name of the database and,
in fact, if it is the same as your login name, you can leave it empty.
then start the demo with: advanced.demo(cnx)
__________________________________________________________________
"""
from
pg
import
DB
import
sys
# waits for a key
def
wait_key
():
print
"Press <enter>"
sys
.
stdin
.
read
(
1
)
# inheritance features
def
inherit_demo
(
pgcnx
):
print
"-----------------------------"
print
"-- Inheritance:"
print
"-- a table can inherit from zero or more tables. A query"
print
"-- can reference either all rows of a table or all rows "
print
"-- of a table plus all of its descendants."
print
"-----------------------------"
print
print
"-- For example, the capitals table inherits from cities table."
print
"-- (It inherits all data fields from cities.)"
print
print
"CREATE TABLE cities ("
print
" name text,"
print
" population float8,"
print
" altitude int"
print
")"
print
print
"CREATE TABLE capitals ("
print
" state varchar(2)"
print
") INHERITS (cities)"
pgcnx
.
query
(
"""CREATE TABLE cities (
name text,
population float8,
altitude int)"""
)
pgcnx
.
query
(
"""CREATE TABLE capitals (
state varchar(2)) INHERITS (cities)"""
)
wait_key
()
print
print
"-- now, let's populate the tables"
print
print
"INSERT INTO cities VALUES ('San Francisco', 7.24E+5, 63)"
print
"INSERT INTO cities VALUES ('Las Vegas', 2.583E+5, 2174)"
print
"INSERT INTO cities VALUES ('Mariposa', 1200, 1953)"
print
print
"INSERT INTO capitals VALUES ('Sacramento', 3.694E+5, 30, 'CA')"
print
"INSERT INTO capitals VALUES ('Madison', 1.913E+5, 845, 'WI')"
print
pgcnx
.
query
(
"INSERT INTO cities VALUES ('San Francisco', 7.24E+5, 63)"
)
pgcnx
.
query
(
"INSERT INTO cities VALUES ('Las Vegas', 2.583E+5, 2174)"
)
pgcnx
.
query
(
"INSERT INTO cities VALUES ('Mariposa', 1200, 1953)"
)
pgcnx
.
query
(
"INSERT INTO capitals VALUES ('Sacramento',3.694E+5,30,'CA')"
)
pgcnx
.
query
(
"INSERT INTO capitals VALUES ('Madison', 1.913E+5, 845, 'WI')"
)
print
print
"SELECT * FROM cities"
print
pgcnx
.
query
(
"SELECT * FROM cities"
)
print
"SELECT * FROM capitals"
print
pgcnx
.
query
(
"SELECT * FROM capitals"
)
print
print
"-- like before, a regular query references rows of the base"
print
"-- table only"
print
print
"SELECT name, altitude"
print
"FROM cities"
print
"WHERE altitude > 500;"
print
pgcnx
.
query
(
"""SELECT name, altitude
FROM cities
WHERE altitude > 500"""
)
print
print
"-- on the other hand, you can find all cities, including "
print
"-- capitals, that are located at an altitude of 500 'ft "
print
"-- or higher by:"
print
print
"SELECT c.name, c.altitude"
print
"FROM cities* c"
print
"WHERE c.altitude > 500"
print
pgcnx
.
query
(
"""SELECT c.name, c.altitude
FROM cities* c
WHERE c.altitude > 500"""
)
# arrays attributes
def
array_demo
(
pgcnx
):
print
"----------------------"
print
"-- Arrays:"
print
"-- attributes can be arrays of base types or user-defined "
print
"-- types"
print
"----------------------"
print
print
"CREATE TABLE sal_emp ("
print
" name text,"
print
" pay_by_quarter int4[],"
print
" pay_by_extra_quarter int8[],"
print
" schedule text[][]"
print
")"
pgcnx
.
query
(
"""CREATE TABLE sal_emp (
name text,
pay_by_quarter int4[],
pay_by_extra_quarter int8[],
schedule text[][])"""
)
wait_key
()
print
print
"-- insert instances with array attributes. "
print
" Note the use of braces"
print
print
"INSERT INTO sal_emp VALUES ("
print
" 'Bill',"
print
" '{10000,10000,10000,10000}',"
print
" '{9223372036854775800,9223372036854775800,9223372036854775800}',"
print
" '{{
\"
meeting
\"
,
\"
lunch
\"
}, {}}')"
print
print
"INSERT INTO sal_emp VALUES ("
print
" 'Carol',"
print
" '{20000,25000,25000,25000}',"
print
" '{9223372036854775807,9223372036854775807,9223372036854775807}',"
print
" '{{
\"
talk
\"
,
\"
consult
\"
}, {
\"
meeting
\"
}}')"
print
pgcnx
.
query
(
"""INSERT INTO sal_emp VALUES (
'Bill', '{10000,10000,10000,10000}',
'{9223372036854775800,9223372036854775800,9223372036854775800}',
'{{
\"
meeting
\"
,
\"
lunch
\"
}, {}}')"""
)
pgcnx
.
query
(
"""INSERT INTO sal_emp VALUES (
'Carol', '{20000,25000,25000,25000}',
'{9223372036854775807,9223372036854775807,9223372036854775807}',
'{{
\"
talk
\"
,
\"
consult
\"
}, {
\"
meeting
\"
}}')"""
)
wait_key
()
print
print
"----------------------"
print
"-- queries on array attributes"
print
"----------------------"
print
print
"SELECT name FROM sal_emp WHERE"
print
" sal_emp.pay_by_quarter[1] <> sal_emp.pay_by_quarter[2]"
print
print
pgcnx
.
query
(
"""SELECT name FROM sal_emp WHERE
sal_emp.pay_by_quarter[1] <> sal_emp.pay_by_quarter[2]"""
)
print
print
pgcnx
.
query
(
"""SELECT name FROM sal_emp WHERE
sal_emp.pay_by_extra_quarter[1] <> sal_emp.pay_by_extra_quarter[2]"""
)
print
print
"-- retrieve third quarter pay of all employees"
print
print
"SELECT sal_emp.pay_by_quarter[3] FROM sal_emp"
print
print
pgcnx
.
query
(
"SELECT sal_emp.pay_by_quarter[3] FROM sal_emp"
)
print
print
"-- retrieve third quarter extra pay of all employees"
print
print
"SELECT sal_emp.pay_by_extra_quarter[3] FROM sal_emp"
print
pgcnx
.
query
(
"SELECT sal_emp.pay_by_extra_quarter[3] FROM sal_emp"
)
print
print
"-- retrieve first two quarters of extra quarter pay of all employees"
print
print
"SELECT sal_emp.pay_by_extra_quarter[1:2] FROM sal_emp"
print
print
pgcnx
.
query
(
"SELECT sal_emp.pay_by_extra_quarter[1:2] FROM sal_emp"
)
print
print
"-- select subarrays"
print
print
"SELECT sal_emp.schedule[1:2][1:1] FROM sal_emp WHERE"
print
" sal_emp.name = 'Bill'"
print
pgcnx
.
query
(
"SELECT sal_emp.schedule[1:2][1:1] FROM sal_emp WHERE "
\
"sal_emp.name = 'Bill'"
)
# base cleanup
def
demo_cleanup
(
pgcnx
):
print
"-- clean up (you must remove the children first)"
print
"DROP TABLE sal_emp"
print
"DROP TABLE capitals"
print
"DROP TABLE cities;"
pgcnx
.
query
(
"DROP TABLE sal_emp"
)
pgcnx
.
query
(
"DROP TABLE capitals"
)
pgcnx
.
query
(
"DROP TABLE cities"
)
# main demo function
def
demo
(
pgcnx
):
inherit_demo
(
pgcnx
)
array_demo
(
pgcnx
)
demo_cleanup
(
pgcnx
)
src/interfaces/python/tutorial/basics.py
deleted
100755 → 0
View file @
2c018f9b
This diff is collapsed.
Click to expand it.
src/interfaces/python/tutorial/func.py
deleted
100755 → 0
View file @
2c018f9b
This diff is collapsed.
Click to expand it.
src/interfaces/python/tutorial/syscat.py
deleted
100755 → 0
View file @
2c018f9b
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment