# "Classic" interface. For DB-API compliance use the pgdb module.
from _pg import *
+from types import *
import string, re, sys
# utility function
pg_attribute.attisdropped = 'f'""").getresult():
self.__pkeys__[rel] = att
+ 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):
- if self.debug != None:
- print self.debug % qstr
+ self._do_debug(qstr)
return self.db.query(qstr)
# If third arg supplied set primary key to it
fnames = self.get_attnames(xcl)
- if type(arg) == type({}):
+ 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]
(xcl, string.join(fnames.keys(), ','),\
cl, keyname, _quote(k, fnames[keyname]))
- if self.debug != None: print self.debug % q
+ self._do_debug(q)
res = self.db.query(q).dictresult()
if res == []:
raise error, \
try:
q = "INSERT INTO %s (%s) VALUES (%s)" % \
(cl, string.join(n, ','), string.join(l, ','))
- if self.debug != None: print self.debug % q
+ self._do_debug(q)
a['oid_%s' % cl] = self.db.query(q)
except:
raise error, "Error inserting into %s: %s" % (cl, sys.exc_value)
try:
q = "UPDATE %s SET %s WHERE %s" % \
(cl, string.join(v, ','), where)
- if self.debug != None: print self.debug % q
+ self._do_debug(q)
self.db.query(q)
except:
raise error, "Can't update %s: %s" % (cl, sys.exc_value)
def delete(self, cl, a):
try:
q = "DELETE FROM %s WHERE oid = %s" % (cl, a['oid_%s' % cl])
- if self.debug != None: print self.debug % q
+ self._do_debug(q)
self.db.query(q)
except:
raise error, "Can't delete %s: %s" % (cl, sys.exc_value)