Changeset 181 for trunk/module/pg.py


Ignore:
Timestamp:
Oct 22, 2004, 4:17:53 PM (15 years ago)
Author:
darcy
Message:

Don't crash in update method if primary key doesn't exist yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/module/pg.py

    r177 r181  
    4141
    4242        return "'%s'" % string.strip(re.sub("'", "''", \
    43                                                          re.sub("\\\\", "\\\\\\\\", "%s" % d)))
     43                                                        re.sub("\\\\", "\\\\\\\\", "%s" % d)))
    4444
    4545class DB:
     
    259259        # otherwise use the primary key.  Fail if neither.
    260260        def update(self, cl, a):
    261                 self.pkey(cl)           # make sure we have a self.__pkeys dictionary
    262 
    263261                foid = 'oid_%s' % cl
    264262                if a.has_key(foid):
    265263                        where = "oid = %s" % a[foid]
    266                 elif self.__pkeys.has_key(cl) and a.has_key(self.__pkeys[cl]):
    267                         where = "%s = '%s'" % (self.__pkeys[cl], a[self.__pkeys[cl]])
    268                 else:
    269                         raise ProgrammingError, \
     264                else:
     265                        try: pk = self.pkeys(cl)
     266                        except: raise ProgrammingError, \
    270267                                        "Update needs primary key or oid as %s" % foid
     268
     269                        where = "%s = '%s'" % (pk, a[pk])
    271270
    272271                v = []
Note: See TracChangeset for help on using the changeset viewer.