[PyGreSQL] Version 3.0 PyGreSQL
Tony Lownds
tony at printra.net
Mon Apr 24 10:00:41 EDT 2000
Here it is again... sorry bout that -Tony
*** pgdb.orig Tue Apr 18 08:43:24 2000
--- pgdb.py Tue Apr 18 09:57:43 2000
***************
*** 4,10 ****
See package documentation for further information on copyright.
This is beta software. Inline documentation is currently inexistant.
! See DB-SIG 2.0 specification for usage informations.
"""
import _pg
--- 4,56 ----
See package documentation for further information on copyright.
This is beta software. Inline documentation is currently inexistant.
! See DB-SIG 2.0 specification for usage information.
!
! basic usage:
!
! pgdb.connect(connect_string) -> connection
! connect_string = 'host:database:user:password:opt:tty'
! All parts are optional. You may also pass host through
! password as keyword arguments. To pass a port, pass it in
! the host keyword parameter:
! pgdb.connect(host='localhost:5432')
!
! connection.cursor() -> cursor
!
! connection.commit()
!
! connection.close()
!
! connection.rollback()
!
! cursor.execute(query[, params])
! execute a query, binding params (a dictionary) if it is
! passed. The binding syntax is the same as the % operator
! for dictionaries, and no quoting is done.
!
! cursor.executemany(query, list of params)
! execute a query many times, binding each param dictionary
! from the list.
!
! cursor.fetchone() -> [value, value, ...]
!
! cursor.fetchall() -> [[value, value, ...], ...]
!
! cursor.fetchmany([size]) -> [[value, value, ...], ...]
! returns size or cursor.arraysize number of rows from result
! set. Default cursor.arraysize is 1.
!
! cursor.description -> [(column_name, type_name, display_size,
! internal_size, precision, scale, null_ok), ...]
!
! Note that precision, scale and null_ok are not implemented.
!
! cursor.rowcount
! number of rows available in the result set. Available after
! a call to execute.
!
! cursor.close()
!
"""
import _pg
***************
*** 27,60 ****
### exception hierarchy
! class pgWarning(StandardError):
pass
! class pgError(StandardError):
pass
! class pgInterfaceError(pgError):
pass
! class pgDatabaseError(pgError):
pass
! class pgDataError(pgDatabaseError):
pass
! class pgOperationalError(pgDatabaseError):
pass
! class pgIntegrityError(pgDatabaseError):
pass
! class pgInternalError(pgDatabaseError):
pass
! class pgProgrammingError(pgDatabaseError):
pass
! class pgNotSupportedError(pgDatabaseError):
pass
### internal type handling class
--- 73,106 ----
### exception hierarchy
! class Warning(StandardError):
pass
! class Error(StandardError):
pass
! class InterfaceError(Error):
pass
! class DatabaseError(Error):
pass
! class DataError(DatabaseError):
pass
! class OperationalError(DatabaseError):
pass
! class IntegrityError(DatabaseError):
pass
! class InternalError(DatabaseError):
pass
! class ProgrammingError(DatabaseError):
pass
! class NotSupportedError(DatabaseError):
pass
### internal type handling class
***************
*** 94,102 ****
"FROM pg_type WHERE oid = %s" % oid
)
res = self.__source.fetch(1)[0]
! # name is used for type (see types definition below)
res = (
! res[0], res[0],
string.atoi(res[1]), string.atoi(res[2]),
None, None, None
)
--- 140,149 ----
"FROM pg_type WHERE oid = %s" % oid
)
res = self.__source.fetch(1)[0]
! # column name is omitted from the return value. It will
! # have to be prepended by the caller.
res = (
! res[0],
string.atoi(res[1]), string.atoi(res[2]),
None, None, None
)
***************
*** 110,123 ****
def __init__(self, src, cache):
self.__cache = cache
self.__source = src
! self.__internal_attr = {
! 'description': None, 'rowcount': -1, 'arraysize': 5
! }
def close(self):
self.__source.close()
! self.__internal_attr['description'] = None
! self.__internal_attr['rowcount'] = -1
def execute(self, operation, params = None):
if type(params) == types.TupleType or type(params) ==
types.ListType:
--- 157,171 ----
def __init__(self, src, cache):
self.__cache = cache
self.__source = src
! self.description = None
! self.rowcount = -1
! self.description = None
! self.arraysize = 1
def close(self):
self.__source.close()
! self.description = None
! self.rowcount = -1
def execute(self, operation, params = None):
if type(params) == types.TupleType or type(params) ==
types.ListType:
***************
*** 125,132 ****
self.executemany(operation, (params,))
def executemany(self, operation, param_seq):
! self.__internal_attr['description'] = None
! self.__internal_attr['rowcount'] = -1
# first try to execute all queries
totrows = 0
--- 173,180 ----
self.executemany(operation, (params,))
def executemany(self, operation, param_seq):
! self.description = None
! self.rowcount = -1
# first try to execute all queries
totrows = 0
***************
*** 141,160 ****
if rows != None: # true is __source
is NOT a DQL
totrows = totrows + rows
except _pg.error, msg:
! raise pgDatabaseError, "error '%s' in '%s'" %
( msg, sql )
except:
! raise pgOperationalError, "internal error in
'%s'" % sql
# then initialize result raw count and description
if self.__source.resulttype == _pg.RESULT_DQL:
! self.__internal_attr['rowcount'] =
self.__source.ntuples
d = []
for typ in self.__source.listinfo():
! d.append(self.__cache.getdescr(typ[2]))
! self.__internal_attr['description'] = d
else:
! self.__internal_attr['rowcount'] = totrows
! self.__internal_attr['description'] = None
def fetchone(self):
res = self.fetchmany(1, 0)
--- 189,213 ----
if rows != None: # true is __source
is NOT a DQL
totrows = totrows + rows
except _pg.error, msg:
! raise DatabaseError, "error '%s' in '%s'" % (
msg, sql )
except:
! raise OperationalError, "internal error in '%s'" % sql
# then initialize result raw count and description
if self.__source.resulttype == _pg.RESULT_DQL:
! self.rowcount = self.__source.ntuples
d = []
for typ in self.__source.listinfo():
! # listinfo is a sequence of
! # (index, column_name, type_oid)
! # getdescr returns all items needed for a
! # description tuple except the column_name.
! desc = typ[1:2]+self.__cache.getdescr(typ[2])
! d.append(desc)
! self.description = d
else:
! self.rowcount = totrows
! self.description = None
def fetchone(self):
res = self.fetchmany(1, 0)
***************
*** 168,190 ****
def fetchmany(self, size = None, keep = 1):
if size == None:
! size = self.__internal_attr['arraysize']
if keep == 1:
! self.__internal_attr['arraysize'] = size
res = self.__source.fetch(size)
result = []
for r in res:
row = []
for i in range(len(r)):
row.append(self.__cache.typecast(
!
self.__internal_attr['description'][i][1],
r[i]
)
)
result.append(row)
return result
! def setinputsize(self, sizes):
pass
def setoutputsize(self, size, col = 0):
--- 221,243 ----
def fetchmany(self, size = None, keep = 1):
if size == None:
! size = self.arraysize
if keep == 1:
! self.arraysize = size
res = self.__source.fetch(size)
result = []
for r in res:
row = []
for i in range(len(r)):
row.append(self.__cache.typecast(
! self.description[i][1],
r[i]
)
)
result.append(row)
return result
! def setinputsizes(self, sizes):
pass
def setoutputsize(self, size, col = 0):
***************
*** 201,207 ****
src = self.__cnx.source()
src.execute("BEGIN")
except:
! raise pgOperationalError, "invalid connection."
def close(self):
self.__cnx.close()
--- 254,260 ----
src = self.__cnx.source()
src.execute("BEGIN")
except:
! raise OperationalError, "invalid connection."
def close(self):
self.__cnx.close()
***************
*** 212,218 ****
src.execute("COMMIT")
src.execute("BEGIN")
except:
! raise pgOperationalError, "can't commit."
def rollback(self):
try:
--- 265,271 ----
src.execute("COMMIT")
src.execute("BEGIN")
except:
! raise OperationalError, "can't commit."
def rollback(self):
try:
***************
*** 220,233 ****
src.execute("ROLLBACK")
src.execute("BEGIN")
except:
! raise pgOperationalError, "can't rollback."
def cursor(self):
try:
src = self.__cnx.source()
return pgdbCursor(src, self.__cache)
except:
! raise pgOperationalError, "invalid connection."
### module interface
--- 273,286 ----
src.execute("ROLLBACK")
src.execute("BEGIN")
except:
! raise OperationalError, "can't rollback."
def cursor(self):
try:
src = self.__cnx.source()
return pgdbCursor(src, self.__cache)
except:
! raise OperationalError, "invalid connection."
### module interface
--
tony at printra.net / 206-923-1818
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.vex.net/pipermail/pygresql/attachments/20000424/97926abc/attachment.htm
More information about the PyGreSQL
mailing list