Exemple #1
0
    def __setitem__(self, key, value):
        if not isinstance(value, dict) and not isinstance(value, UserDictCase):
            raise TypeError("Expected value to be a hash")
        if self.__hashid in value:  # we don't need that
            if key is None:
                key = value[self.__hashid]
            del value[self.__hashid]

        if key is None:
            raise KeyError("Can not insert entry with NULL key")
        items = value.items()
        if items == []:  # quick check for noop
            return
        sql = None
        if self.has_key(key):
            sql, pdict = sql_lib.build_sql_update(self.__table, self.__hashid, items)
        else:
            sql, pdict = sql_lib.build_sql_insert(self.__table, self.__hashid, items)
        # import the value of the hash key
        pdict["p0"] = key
        h = self.__db.prepare(sql)
        h.execute(**pdict)
        try:
            value[self.__hashid] = key
            self.__cache[key] = value
        except:
            pass
Exemple #2
0
 def save(self, with_updates=1):
     """ now save an entry """
     if self.hashname not in self.data:
         raise AttributeError("Table does not have a hash `%s' key" %
                              self.hashname)
     # get a list of fields to be set
     items = [(a[0], a[1][0])
              for a in [b for b in list(self.data.items()) if b[1][1] == 1]]
     if not items:  # if there is nothing for us to do, avoid doing it.
         return
     # and now build the SQL statements
     if self.real:  # Update
         if not with_updates:
             raise sql_base.ModifiedRowError()
         sql, pdict = sql_lib.build_sql_update(self.table, self.hashname,
                                               items)
     else:
         sql, pdict = sql_lib.build_sql_insert(self.table, self.hashname,
                                               items)
     h = self.db.prepare(sql)
     pdict["p0"] = self.data[self.hashname][0]
     # and now do it
     h.execute(**pdict)
     self.real = 1
     return
Exemple #3
0
    def __setitem__(self, key, value):
        if not isinstance(value, dict) and not isinstance(value, UserDictCase):
            raise TypeError("Expected value to be a hash")
        if self.__hashid in value:  # we don't need that
            if key is None:
                key = value[self.__hashid]
            del value[self.__hashid]

        if key is None:
            raise KeyError("Can not insert entry with NULL key")
        items = value.items()
        if items == []:  # quick check for noop
            return
        sql = None
        if self.has_key(key):
            sql, pdict = sql_lib.build_sql_update(self.__table, self.__hashid,
                                                  items)
        else:
            sql, pdict = sql_lib.build_sql_insert(self.__table, self.__hashid,
                                                  items)
        # import the value of the hash key
        pdict["p0"] = key
        h = self.__db.prepare(sql)
        h.execute(**pdict)
        try:
            value[self.__hashid] = key
            self.__cache[key] = value
        except:
            pass
Exemple #4
0
 def save(self, with_updates=1):
     """ now save an entry """
     if self.hashname not in self.data:
         raise AttributeError("Table does not have a hash `%s' key" % self.hashname)
     # get a list of fields to be set
     items = [(a[0], a[1][0]) for a in [b for b in list(self.data.items()) if b[1][1] == 1]]
     if not items:  # if there is nothing for us to do, avoid doing it.
         return
     # and now build the SQL statements
     if self.real:  # Update
         if not with_updates:
             raise sql_base.ModifiedRowError()
         sql, pdict = sql_lib.build_sql_update(self.table, self.hashname, items)
     else:
         sql, pdict = sql_lib.build_sql_insert(self.table, self.hashname, items)
     h = self.db.prepare(sql)
     pdict["p0"] = self.data[self.hashname][0]
     # and now do it
     h.execute(**pdict)
     self.real = 1
     return
Exemple #5
0
 def save(self, with_updates=1):
     if not self.data.has_key(self.hashname):
         raise AttributeError, "Table does not have a hash `%s' key" % self.hashname
     # get a list of fields to be set
     items = map(lambda a: (a[0], a[1][0]),
                 filter(lambda b: b[1][1] == 1, self.data.items()))        
     if not items: # if there is nothing for us to do, avoid doing it.
         return
     # and now build the SQL statements
     if self.real: # Update
         if not with_updates:
             raise sql_base.ModifiedRowError()
         sql, pdict = sql_lib.build_sql_update(self.table, self.hashname, items)
     else:
         sql, pdict = sql_lib.build_sql_insert(self.table, self.hashname, items)
     h = self.db.prepare(sql)
     pdict["p0"] = self.data[self.hashname][0]
     # and now do it
     apply(h.execute, (), pdict)
     self.real = 1
     return