On Tue, Sep 05, 2006 at 05:39:28PM -0400, Cristian Gafton wrote:
>
> To make a longer story shorter, as I progressed through this task, the
> changes I have been making to PyGreSQL became more and more extensive,
> modifying the original's behavior in incompatible ways. I didn't solve the
> challenge of preserving PyGreSQL's existing behavior, seeing how the
> native PostgreSQL bind parameters syntax ($1, $2, etc) is very different
> from what PyGreSQL simulated (python-style %s or %(var)s). (although it
> would be possible to do with some regexp foo)
Or even better, with my RiggedDict class :-)
class RiggedDict(dict):
"""Dictionary that will always return an object generated by a counter"""
def __init__(self):
dict.__init__(self)
self._counter = 0
self._map = {}
def __getitem__(self, k):
if k in self._map:
return self._map[k]
# Generate a value for this key, store it and return it
self._counter += 1
val = self._map[k] = '$%d' % self._counter
return val
def get_map(self):
# utility function to check the maps that were generated so far
return self._map
s = "select %(foo1)s, %(foo2)s, %(foo1)s from dual"
d = RiggedDict()
print s % d
Misa
_______________________________________________
DB-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/db-sig