From e55213a5a8ff7ecad60e81ae476f31f5d0ab8e51 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Mon, 17 May 1999 06:15:31 +0000 Subject: Re-add python. --- src/interfaces/python/pgsqldb.py | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/interfaces/python/pgsqldb.py (limited to 'src/interfaces/python/pgsqldb.py') diff --git a/src/interfaces/python/pgsqldb.py b/src/interfaces/python/pgsqldb.py new file mode 100644 index 00000000000..df768b68b2f --- /dev/null +++ b/src/interfaces/python/pgsqldb.py @@ -0,0 +1,46 @@ +# pgsqldb.py +# Written by D'Arcy J.M. Cain + +# This library implements the DB-SIG API +# It includes the pg module and builds on it + +from _pg import * + +import string + +class _cursor: + """For cursor object""" + + def __init__(self, conn): + self.conn = conn + self.cursor = None + self.arraysize = 1 + self.description = None + self.name = string.split(`self`)[3][:-1] + + def close(self): + if self.conn == None: raise self.conn.error, "Cursor has been closed" + if self.cursor == None: raise self.conn.error, "No cursor created" + self.conn.query('CLOSE %s' % self.name) + self.conn = None + + def __del__(self): + if self.cursor != None and self.conn != None: + self.conn.query('CLOSE %s' % self.name) + + +class pgsqldb: + """This class wraps the pg connection type in a DB-SIG API interface""" + + def __init__(self, *args, **kw): + self.db = apply(connect, args, kw) + + # Create convience methods, in a way that is still overridable. + for e in ('query', 'reset', 'close', 'getnotify', 'inserttable', + 'putline', 'getline', 'endcopy', + 'host', 'port', 'db', 'options', + 'tty', 'error', 'status', 'user', + 'locreate', 'getlo', 'loimport'): + if not hasattr(self,e) and hasattr(self.db,e): + exec 'self.%s = self.db.%s' % ( e, e ) + -- cgit v1.2.3