Ejemplo n.º 1
0
 def update(self, adict):
     """ Part of dictionary interface for field access"""
     if not self.mutable:
         raise ValueError, "instance isn't mutable!"
     if not self._unique:
         raise ValueError, "cannot update without unique index!"
     # call (normally empty) hook for modifying the update
     d=self.onUpdate(adict)
     # Check that the fields in the dictionary are kosher
     self._validateFields(d)
     # do the actual update
     self._update_raw(d)
     # if successful, modify the object's field data,
     # taking any wrapped values out of their wrappers
     unwrapped=dict((k, unwrap(v)) for k,v in d.iteritems())
     super(PyDO, self).update(unwrapped)
Ejemplo n.º 2
0
 def update(self, adict):
     """ Part of dictionary interface for field access"""
     if not self.mutable:
         raise ValueError, "instance isn't mutable!"
     if not self._unique:
         raise ValueError, "cannot update without unique index!"
     # call (normally empty) hook for modifying the update
     d = self.onUpdate(adict)
     # Check that the fields in the dictionary are kosher
     self._validateFields(d)
     # do the actual update
     self._update_raw(d)
     # if successful, modify the object's field data,
     # taking any wrapped values out of their wrappers
     unwrapped = dict((k, unwrap(v)) for k, v in d.iteritems())
     super(PyDO, self).update(unwrapped)
Ejemplo n.º 3
0
    def _new(cls, fieldData, refetch):
        if not cls.mutable:
            raise ValueError, 'cannot make a new immutable object!'
        if refetch and not cls._unique:
            raise ValueError, "cannot refetch without a unique index!"
        # sanity check the field data
        cls._validateFields(fieldData)
        
        conn = cls.getDBI()

        if not conn.auto_increment:
            for s, sn in cls._sequenced.items():
                if not fieldData.has_key(s):
                    fieldData[s] = conn.getSequence(sn)
        cols=fieldData.keys()
        vals=[fieldData[c] for c in cols]
        converter=conn.getConverter()
        converted=map(converter, vals)
        
        sql = 'INSERT INTO %s (%s) VALUES  (%s)' \
              % (cls.getTable(),
                 ', '.join(cols),
                 ', '.join(converted))
        res = conn.execute(sql, converter.values)
        if res != 1:
            raise PyDOError, "inserted %s rows instead of 1" % res
        
        if conn.auto_increment:
            for k, v in cls._sequenced.items():
                if not fieldData.has_key(k):
                    fieldData[k] = conn.getAutoIncrement(v)
        # unwrap any wrapped values in fieldData
        fieldData=dict((k, unwrap(v)) for k,v in fieldData.iteritems())
        if not refetch:
            return cls(fieldData)
        return cls.getUnique(**fieldData)
Ejemplo n.º 4
0
    def _new(cls, fieldData, refetch):
        if not cls.mutable:
            raise ValueError, 'cannot make a new immutable object!'
        if refetch and not cls._unique:
            raise ValueError, "cannot refetch without a unique index!"
        # sanity check the field data
        cls._validateFields(fieldData)

        conn = cls.getDBI()

        if not conn.auto_increment:
            for s, sn in cls._sequenced.items():
                if not fieldData.has_key(s):
                    fieldData[s] = conn.getSequence(sn)
        cols = fieldData.keys()
        vals = [fieldData[c] for c in cols]
        converter = conn.getConverter()
        converted = map(converter, vals)

        sql = 'INSERT INTO %s (%s) VALUES  (%s)' \
              % (cls.getTable(),
                 ', '.join(cols),
                 ', '.join(converted))
        res = conn.execute(sql, converter.values)
        if res != 1:
            raise PyDOError, "inserted %s rows instead of 1" % res

        if conn.auto_increment:
            for k, v in cls._sequenced.items():
                if not fieldData.has_key(k):
                    fieldData[k] = conn.getAutoIncrement(v)
        # unwrap any wrapped values in fieldData
        fieldData = dict((k, unwrap(v)) for k, v in fieldData.iteritems())
        if not refetch:
            return cls(fieldData)
        return cls.getUnique(**fieldData)