Bring python up to date ...

From: D'Arcy J.M. Cain <darcy@druid.net>
This commit is contained in:
Marc G. Fournier 1999-05-19 14:46:54 +00:00
parent 77ebed09f5
commit 9487ad8409
5 changed files with 492 additions and 246 deletions

View File

@ -1,8 +1,8 @@
Announce: Release of PyGreSQL version 2.3
Announce: Release of PyGreSQL version 2.4
===============================================
PyGreSQL v2.3 has been released.
PyGreSQL v2.4 has been released.
It is available at: ftp://ftp.druid.net/pub/distrib/PyGreSQL.tgz. If
you are on NetBSD, look in the packages directory under databases. If
it isn't there yet, it should be there shortly. You can also pick up the
@ -31,6 +31,9 @@ PostgreSQL features from a Python script.
I wanted to have DB-SIG API support in the next release but there are
enough fixes and improvements to make one more release before starting
on that. The next version will be 3.0 and have the DB-SIG API support.
Note that I said this for 2.4 but some required changes from others have
been slow in coming (I'm not complaining, people do have lives) and
there were enough fixes that I didn't want to keep them from a release.
PyGreSQL 2.3 was developed and tested on a NetBSD 1.3_BETA system. It
is based on the PyGres95 code written by Pascal Andre,
@ -39,6 +42,17 @@ 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.
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 but 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)
Important changes from PyGreSQL 2.2 to PyGreSQL 2.3:
- connect.host returns "localhost" when connected to Unix socket
(torppa@tuhnu.cutery.fi)

View File

@ -5,6 +5,17 @@ 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 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 but 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)
Version 2.3
- connect.host returns "localhost" when connected to Unix socket
(torppa@tuhnu.cutery.fi)

View File

@ -1,11 +1,11 @@
PyGreSQL - v2.3: PostgreSQL module for Python
PyGreSQL - v2.4: PostgreSQL module for Python
==============================================
0. Copyright notice
===================
PyGreSQL, version 2.3
PyGreSQL, version 2.4
A Python interface for PostgreSQL database.
Written by D'Arcy J.M. Cain, darcy@druid.net<BR>
Based heavily on code written by Pascal Andre, andre@chimay.via.ecp.fr.
@ -129,12 +129,13 @@ style prototypes and changed the order of arguments to connect.
The home sites of the different packages are:
- Python: ftp://ftp.python.org:/pub/python
- PosgreSQL: ftp://ftp.PostgreSQL.org/pub/postgresql-6.4.tar.gz
- PyGreSQL: ftp://ftp.druid.net/pub/distrib/pygresql-2.2.tgz
- Python: http://www.python.org/
- PosgreSQL: http://www.PostgreSQL.org/
- PyGreSQL: http://www.druid.net/pygresql/
A Linux RPM can be picked up from ftp://www.eevolute.com/pub/python/.
A NetBSD package thould be in the distribution soon and is available
at ftp://ftp.druid.net/pub/distrib/pygresql.pkg.tgz.
1.5. Information and support
----------------------------
@ -164,6 +165,10 @@ and all the requests to the database, the pglargeobject that handles
all the accesses to Postgres large objects and pgqueryobject that handles
query results.
If you want to see a simple example of the use of some of these functions,
see http://www.druid.net/rides/ where I have a link at the bottom to the
actual Python code for the page.
2.1. pg module description
----------------------------
@ -471,6 +476,16 @@ methods are specified by the tag [LO].
type, using a hardcoded table definition. The number returned is the
field rank in the result values list.
2.2.1.5 ntuples - return number of tuples in query object
---------------------------------------------------------
Syntax: ntuples()
Parameters: None
Return type: integer
Description:
This method returns the number of tuples found in a query.
2.2.2. reset - resets the connection
------------------------------------
@ -847,25 +862,7 @@ The following describes the methods and variables of this class.
Name of field which is the primary key of the table.
Description:
This method returns the primary key of a table. Note that this raises
an exception if the table doesn't have a primary key. Further, in the
currently released implementation of PostgreSQL the 'PRIMARY KEY' syntax
doesn't actually fill in the necessary tables to determine primary keys.
You can do this yourself with the following query.
# Set up table and primary_field variables...
"""UPDATE pg_index SET indisprimary = 't'
WHERE pg_index.oid in (SELECT pg_index.oid
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_class.relname = '%(table)s' AND
pg_attribute.attname = '%(primary_field)');""" % locals()
This will be fixed in the upcoming 6.5 release of PostgreSQL or
you can download the current sources now. Downloading current
is, as usual, at your own risk.
an exception if the table doesn't have a primary key.
3.3. get_databases - get list of databases in the system
--------------------------------------------------------

View File

@ -25,7 +25,7 @@ def _quote(d, t):
return "'f'"
if d == "": return "null"
return "'%s'" % string.strip(re.sub('\'', '\'\'', "%s" % d))
return "'%s'" % string.strip(re.sub("'", "''", "%s" % d))
class DB:
"""This class wraps the pg connection type"""
@ -175,16 +175,30 @@ class DB:
# reload the dictionary to catch things modified by engine
# note that get() changes 'oid' below to oid_table
return self.get(cl, a, 'oid')
# 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
# Update always works on the oid which get returns if available
# otherwise use the primary key. Fail if neither.
def update(self, cl, a):
q = "SELECT oid FROM %s WHERE oid = %s" % (cl, a['oid_%s' % cl])
foid = 'oid_%s' % cl
pk = self.pkeys[cl]
if a.has_key(foid):
where = "oid = %s" % a[foid]
elif a.has_key(pk):
where = "%s = '%s'" % (pk, a[pk])
else:
raise error, "Update needs key (%s) or oid as %s" % (pk, foid)
q = "SELECT oid FROM %s WHERE %s" % (cl, where)
if self.debug != None: print self.debug % q
res = self.db.query(q).getresult()
if len(res) < 1:
raise error, "No record in %s where oid = %s (%s)" % \
(cl, a['oid_%s' % cl], sys.exc_value)
raise error, "No record in %s where %s (%s)" % \
(cl, where, sys.exc_value)
else: a[foid] = res[0][0]
v = []
k = 0
@ -199,7 +213,7 @@ class DB:
try:
q = "UPDATE %s SET %s WHERE oid = %s" % \
(cl, string.join(v, ','), a['oid_%s' % cl])
(cl, string.join(v, ','), a[foid])
if self.debug != None: print self.debug % q
self.db.query(q)
except:

File diff suppressed because it is too large Load Diff