[Twisted-web] pgasync (was: /freeform_post!!random causes exceptions)

Andrea Arcangeli andrea at cpushare.com
Wed Jan 19 18:15:36 MST 2005

I checked out pgasync, and the ConnectionPool is already implemented, exactly
like I suggested in my last email ;).

I already fixed up my runinteractions to do this:

				if not isinstance(result, Deferred):
					return zip_description(result, cur)
				return result.addCallback(zip_description, cur)

With just the above change I'm done with the API.  So now with a single global
variable set to True or False I can switch transparently between pgasync and

Next thing I had to fix to be able to login has been to add this:

Index: pgasync/format.py
--- pgasync/format.py	(revision 37)
+++ pgasync/format.py	(working copy)
@@ -7,7 +7,7 @@
 from errors import *
 # Types that are already suitable for str() representation
 def typeCastParam(p):
 	"""Cast v to the appropriate type if possible.
@@ -30,8 +30,10 @@
 		return Date(p.year, p.month, p.day)
 	if tp is datetime.time:
 		return Time(p.hour, p.minute, p.second, p.microsecond)
+	if tp is bool:
+		return Bool(p)
-	raise ProgrammingError, ("Query parameter '%s': cannot convert %s to a PostgreSQL data type" % (k,tp))
+	raise ProgrammingError, ("Query parameter '%s': cannot convert %s to a PostgreSQL data type" % (p,tp))
 def format(s,params):
 	"""Make params appear in s correctly.
Index: pgasync/fe.py
--- pgasync/fe.py	(revision 37)
+++ pgasync/fe.py	(working copy)
@@ -80,7 +80,7 @@
 	def runOperation(self, query, args={}):
 		conn = connect(*self.params[0],**self.params[1])
 		cur = conn.cursor()
-		cursor.execute(query, args).addErrback(self._error)
+		cur.execute(query, args).addErrback(self._error)
 		d = conn.commit()
Index: pgasync/pgtypes.py
--- pgasync/pgtypes.py	(revision 37)
+++ pgasync/pgtypes.py	(working copy)
@@ -70,6 +70,15 @@
 	def _dotime(self):
 		return "%02d:%02d:%02d.%06d" % (self.hour, self.minute, self.second, self.microsecond)
+class BOOL:
+	def __init__(self, b):
+		self.__b = b
+	def __str__(self):
+		if self.__b:
+			return "'T'"
+		else:
+			return "'F'"
 def Date(y,m,d): 
 	dt = DATETIME(y,m,d)
 	dt._tm = 0
@@ -95,3 +104,5 @@
 def TimestampFromTicks(t): return DATETIME.fromtimestamp(t)
 def Binary(s): return BINARY(s)
+def Bool(b): return BOOL(b)

With the above a good part of my app started working. But it's not enough.

Here a list of the remaining issues (which I believe aren't related anymore to
the API, as far as I'm concerned the current adbapi wrapper is all I need ;).

1) the '%(xx)d' format for integeres/logs insn't recognized. I'd like to use
   "%(xx)d" to be strict for integers.

btw, is there any difference in python between %u and %d at all?

2) it cannot handle a ";" at the end of the sql string. so I deleted all the
   finals ";" and I left only the intermediate ones.

3) it doesn't print the nevow url type, note that such parameter is just
   incidentally passed down to the sql query, and pgasync should ignore it
   instead of complaining since it never gets resolved

Here's what I get:

            raise ProgrammingError, ("Query parameter '%s': cannot convert %s to a PostgreSQL data type" % (p,tp))
        pgasync.errors.ProgrammingError: Query parameter 'https://localhost:8443/verify_email': cannot convert <class 'nevow.url.URL'> to a PostgreSQL data type

So I'm going back to adbapi until I get confirmation on how to proceed. I could
change my app in theory to deal with the different API, but I've no idea what
the standard says about the above 3 points. So I prefer to wait before
making more modifications to already working code.

More information about the Twisted-web mailing list