def update(self, p_table_name, p_data, p_where): for key in p_data: p_data[key] = func_ext.addslashes(func_ext.uni_str(p_data[key])) for key in p_where: p_where[key] = func_ext.addslashes(func_ext.uni_str(p_where[key])) edit_sql = ",".join(["%s='%s'" % (str(x[0]), str(x[1])) for x in p_data.items()]) where_sql = " AND ".join(["%s='%s'" % (str(x[0]), str(x[1])) for x in p_where.items()]) real_sql = "UPDATE %s SET %s WHERE %s" % (p_table_name, edit_sql, where_sql) return self.query(real_sql)
def replace(self, p_table_name, p_data): for key in p_data: p_data[key] = func_ext.addslashes(func_ext.uni_str(p_data[key])) key = "`,`".join(p_data.keys()) value = "','".join(p_data.values()) real_sql = "REPLACE INTO %s (`%s`) VALUES ('%s')" % (p_table_name, key, value) return self.query(real_sql)
def isinstance(self, p_table_name, p_where): for key in p_where: p_where[key] = func_ext.addslashes(func_ext.uni_str(p_where[key])) where_sql = " AND ".join([x[0] + "='" + x[1] + "'" for x in p_where.items()]) real_sql = "SELECT count(*) as cnt FROM " + p_table_name + " WHERE " + where_sql if self.query(real_sql): res = self.fetch_assoc() return res[0] else: return 0
def fetch_assoc(self, upper=0, lower=0): if self.get_num_rows(): d = {} desc = self.cur.description self.fields = self.cur.fetchone() for i in xrange(0, len(self.fields)): if isinstance(self.fields[i], (unicode)): d[desc[i][0]] = str(func_ext.uni_str(self.fields[i], self.charset)) else: d[desc[i][0]] = self.fields[i] return d else: return None
def fetch_all(self, upper=0): if self.get_num_rows(): d = [] result = self.cur.fetchall() desc = self.cur.description for inv in result: _d = {} for i in xrange(0, len(inv)): if isinstance(inv[i], (unicode)): _d[desc[i][0]] = str(func_ext.uni_str(inv[i], self.charset)) else: _d[desc[i][0]] = inv[i] d.append(_d) return d else: return None
def delete(self, p_table_name, p_where): for key in p_where: p_where[key] = func_ext.addslashes(func_ext.uni_str(p_where[key])) where_sql = " AND ".join(["%s='%s'" % (x[0], x[1]) for x in p_where.items()]) real_sql = "DELETE FROM %s WHERE " % (p_table_name, where_sql) return self.query(real_sql)