def add_ltg(self, ltid, ltgid): table_name = "ltg" l_ss = [] l_ss.append(db_common.setstate("ltid", "ltid")) l_ss.append(db_common.setstate("ltgid", "ltgid")) args = {"ltid" : ltid, "ltgid" : ltgid} sql = self.db.insert_sql(table_name, l_ss) self.db.execute(sql, args)
def _init_area(self): if self.areafn is None or self.areafn == "": return areadict = config.GroupDef(self.areafn) table_name = "area" l_ss = [db_common.setstate("host", "host"), db_common.setstate("area", "area")] sql = self.db.insert_sql(table_name, l_ss) for area, host in areadict.iter_def(): args = { "host" : host, "area" : area } self.db.execute(sql, args) self.commit()
def update_log(self, d_cond, d_update): if len(d_cond) == 0: _logger.warn("called update with empty condition") #raise ValueError("called update with empty condition") args = d_cond.copy() table_name = "log" l_ss = [] for k, v in d_update.iteritems(): #assert k in ("ltid", "top_dt", "end_dt", "host") keyname = "update_" + k l_ss.append(db_common.setstate(k, keyname)) args[keyname] = v l_cond = [] for c in d_cond.keys(): if c == "ltgid": sql= self.db.select_sql("ltg", ["ltid"], [db_common.cond(c, "=", c)]) l_cond.append(db_common.cond("ltid", "in", sql, False)) elif c == "area": sql= self.db.select_sql("area", ["host"], [db_common.cond(c, "=", c)]) l_cond.append(db_common.cond("host", "in", sql, False)) elif c == "top_dt": l_cond.append(db_common.cond("dt", ">=", c)) args[c] = self.db.strftime(d_cond[c]) elif c == "end_dt": l_cond.append(db_common.cond("dt", "<", c)) args[c] = self.db.strftime(d_cond[c]) else: l_cond.append(db_common.cond(c, "=", c)) sql = self.db.update_sql(table_name, l_ss, l_cond) self.db.execute(sql, args)
def update_log(self, d_cond, d_update): if len(d_cond) == 0: raise ValueError("called update with empty condition") args = d_cond.copy() table_name = "log" l_ss = [] for k, v in d_update.iteritems(): assert k in ("ltid", "top_dt", "end_dt", "host") keyname = "update_" + k l_ss.append(db_common.setstate(k, keyname)) args[keyname] = v l_cond = [] for c in d_cond.keys(): if c == "ltgid": sql= self.db.select_sql("ltg", ["ltid"], [db_common.cond(c, "=", c)]) l_cond.append(db_common.cond("ltid", "in", sql, False)) elif c == "area": sql= self.db.select_sql("area", ["host"], [db_common.cond(c, "=", c)]) l_cond.append(db_common.cond("host", "in", sql, False)) elif c == "top_dt": l_cond.append(db_common.cond("dt", ">=", c)) args[c] = self.db.strftime(d_cond[c]) elif c == "end_dt": l_cond.append(db_common.cond("dt", "<", c)) args[c] = self.db.strftime(d_cond[c]) else: l_cond.append(db_common.cond(c, "=", c)) sql = self.db.update_sql(table_name, l_ss, l_cond) self.db.execute(sql, args)
def update_lt(self, ltid, ltw, lts, count): table_name = "lt" l_ss = [] args = {} if ltw is not None: l_ss.append(db_common.setstate("ltw", "ltw")) args["ltw"] = self._splitter.join(ltw) if lts is not None: l_ss.append(db_common.setstate("lts", "lts")) args["lts"] = self._splitter.join(lts) if count is not None: l_ss.append(db_common.setstate("count", "count")) args["count"] = count l_cond = [db_common.cond("ltid", "=", "ltid")] args["ltid"] = ltid sql = self.db.update_sql(table_name, l_ss, l_cond) self.db.execute(sql, args)
def add_line(self, ltid, dt, host, l_w): table_name = "log" d_val = { "ltid" : ltid, "dt" : self.db.strftime(dt), "host" : host, "words" : self._splitter.join(l_w), } l_ss = [db_common.setstate(k, k) for k in d_val.keys()] sql = self.db.insert_sql(table_name, l_ss) self.db.execute(sql, d_val)
def add_lt(self, ltline): table_name = "lt" l_ss = [] l_ss.append(db_common.setstate("ltid", "ltid")) l_ss.append(db_common.setstate("ltw", "ltw")) l_ss.append(db_common.setstate("lts", "lts")) l_ss.append(db_common.setstate("count", "count")) if ltline.lts is None: lts = None else: lts = self._splitter.join(ltline.lts) args = { "ltid" : ltline.ltid, "ltw" : self._splitter.join(ltline.ltw), "lts" : lts, "count" : ltline.cnt, } sql = self.db.insert_sql(table_name, l_ss) self.db.execute(sql, args) self.add_ltg(ltline.ltid, ltline.ltgid)