Hi,

Here's a unified diff against the CVS version of pgdb.py (1.36).
I also optimized parsing of arrays by using substring instead of string.replace().

I also attached a bzipped version of the whole pgdb.py in case you have trouble with this patch.

I couldn't test this pgdb.py version properly, seems that it's partly incompatible with the rest of the python/postgresql/pygresql stuff I have on my Ubuntu 7.10 workstation. For example, booleans are broken for some reason.
Anyway I tested the integer array part, and it seemed to work.
I suggest that you test this before putting it into production.

-Mikko

D'Arcy J.M. Cain wrote:
On Fri, 21 Mar 2008 15:56:12 +0200
Mikko Korkalo <[EMAIL PROTECTED]> wrote:
I figured pgdb.py (version 1.33) didn't have support to read int2[] and int4[] types, so I added support for it. I don't know if this was in the CVS/SVN tree already.

When reading data, int2[] and int4[] are now converted to a list containing ints, instead of passing them as str, i.e. '{ 1, 2 }' to the program.

That's nice.  Can you submit the patch as a context diff though?
Sometimes the HEAD has changed enough so that the line numbers are only
approximate.  Context diffs allow us to confirm the position.  Even
clearer is unified diffs.  If you are using diff (or cvs diff) just add
"-u" to get unified diffs.

I don't know if this is the correct way to do this.
Maybe all of the array types should be handled at once?

There is some refactoring need in that area.  This might be a good time
to look at that.

--------
109a110,114
 >               elif typ == INTARRAY:
> tmp = value.replace("{", "").replace("}", "").split(",")
 >                       value=[]
 >                       for v in tmp:
 >                               value.append(int(v))
413a419
 > INTARRAY = pgdbType('_int2', '_int4')
--------


--- pgdb.py.cvs	2008-03-21 20:35:36.000000000 +0200
+++ pgdb.py	2008-03-21 20:47:01.000000000 +0200
@@ -107,6 +107,11 @@
 			value = (value[:1] in ['t','T'])
 		elif typ == INTEGER:
 			value = int(value)
+		elif typ == INTARRAY:
+			tmp = value[1:len(value)-1].split(",")
+			value=[]
+			for v in tmp:
+				value.append(int(v)) 
 		elif typ == LONG:
 			value = long(value)
 		elif typ == FLOAT:
@@ -456,6 +461,7 @@
 
 BOOL = pgdbType('bool')
 INTEGER = pgdbType('int2', 'int4', 'serial')
+INTARRAY = pgdbType('_int2', '_int4')
 LONG = pgdbType('int8')
 FLOAT = pgdbType('float4', 'float8', 'numeric')
 MONEY = pgdbType('money')

Attachment: pgdb.py.bz2
Description: application/bzip

_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql

Reply via email to