*** /Users/chris/Desktop/pg.py.orig	Wed Sep 24 11:07:03 2008
--- /Users/chris/Desktop/pg.py	Wed Sep 24 11:12:07 2008
***************
*** 21,30 ****
  from _pg import *
  from types import *
  try:
!     from decimal import Decimal
!     set_decimal(Decimal)
  except ImportError:
!     pass # Python < 2.4
  
  # Auxiliary functions which are independent from a DB connection:
  
--- 21,30 ----
  from _pg import *
  from types import *
  try:
! 	from decimal import Decimal
! 	set_decimal(Decimal)
  except ImportError:
! 	pass # Python < 2.4
  
  # Auxiliary functions which are independent from a DB connection:
  
***************
*** 111,117 ****
  	"""Wrapper class for the _pg connection type."""
  
  	def __init__(self, *args, **kw):
! 		self.db = connect(*args, **kw)
  		self.dbname = self.db.db
  		self.__attnames = {}
  		self.__pkeys = {}
--- 111,138 ----
  	"""Wrapper class for the _pg connection type."""
  
  	def __init__(self, *args, **kw):
! 
! 		# First check to see if the caller gave us a keyword
! 		# argument with index 'db'. If so then assume(!) that
! 		# argument is a connected database from
! 		# _pg.connect(). This allows a DB-API 2.0 user
! 		# establish a pg.DB wrapper for his connection which
! 		# allows the use of the classic features: COPY table
! 		# FROM stdin for example within his session. If we do
! 		# get a pre-established connection disable the close()
! 		# and reopen() methods as it would be rude to close()
! 		# the connection outside of the context of the DB-API
! 		# 2.0 owner.
! 
! 		if 'db' in kw.keys():
! 			self.db = kw['db']
! 			args = ( (), )
! 			kw = { }
! 			self._closeable = False
! 		else:
! 			self.db = connect(*args, **kw)
! 			self._closeable = True
! 
  		self.dbname = self.db.db
  		self.__attnames = {}
  		self.__pkeys = {}
***************
*** 143,149 ****
  		"""Close the database connection."""
  		# Wraps shared library function so we can track state.
  
! 		if self.db:
  			self.db.close()
  			self.db = None
  		else:
--- 164,172 ----
  		"""Close the database connection."""
  		# Wraps shared library function so we can track state.
  
! 		if not self._closeable:
! 			raise InternalError, 'Cannot close a pre-openned connection'
! 		elif self.db:
  			self.db.close()
  			self.db = None
  		else:
***************
*** 156,162 ****
  		Note that we can still reopen a database that we have closed.
  
  		"""
! 		if self.db:
  			self.db.close()
  		try:
  			self.db = connect(*self.__args[0], **self.__args[1])
--- 179,187 ----
  		Note that we can still reopen a database that we have closed.
  
  		"""
! 		if not self._closeable:
! 			raise InternalError, 'Cannot reopen a pre-openned connection'
! 		elif self.db:
  			self.db.close()
  		try:
  			self.db = connect(*self.__args[0], **self.__args[1])
***************
*** 224,230 ****
  		"""This method gets or sets the primary key of a class.
  
  		If newpkey 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.
  
  		"""
--- 249,255 ----
  		"""This method gets or sets the primary key of a class.
  
  		If newpkey 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.
  
  		"""
***************
*** 350,356 ****
  	def get(self, cl, arg, keyname = None, view = 0):
  		"""Get a tuple from a database table or view.
  
! 		This method is the basic mechanism to get a single row.  It assumes
  		that the key specifies a unique row.  If keyname is not specified
  		then the primary key for the table is used.  If arg is a dictionary
  		then the value for the key is taken from it and it is modified to
--- 375,381 ----
  	def get(self, cl, arg, keyname = None, view = 0):
  		"""Get a tuple from a database table or view.
  
! 		This method is the basic mechanism to get a single row.	 It assumes
  		that the key specifies a unique row.  If keyname is not specified
  		then the primary key for the table is used.  If arg is a dictionary
  		then the value for the key is taken from it and it is modified to
***************
*** 442,448 ****
  	def update(self, cl, d = None, **kw):
  		"""Update an existing row in a database table.
  
! 		Similar to insert but updates an existing row.  The update is based
  		on the OID value as munged by get.  The array returned is the
  		one sent modified to reflect any changes caused by the update due
  		to triggers, rules, defaults, etc.
--- 467,473 ----
  	def update(self, cl, d = None, **kw):
  		"""Update an existing row in a database table.
  
! 		Similar to insert but updates an existing row.	The update is based
  		on the OID value as munged by get.  The array returned is the
  		one sent modified to reflect any changes caused by the update due
  		to triggers, rules, defaults, etc.
