def get(self, id): mc_key = self.prefix % id value = mc.get(mc_key) if value is None: r = db.get("select value from %s where id=%%s" % self.table_name, id) if r: value = r.value mc.set(mc_key, value) return value
def id_by_value(self, value): _hash = hashlib.md5(value).hexdigest() mc_key = self.prefix % _hash id = mc.get(mc_key) if id is None: r = db.get('select id from %s where value=%%s' % self.table_name, value) if r: id = r.id mc.set(mc_key, id) return id
def get(self, id): mc_key = self.prefix % id r = mc.get(mc_key) if r is None: cursor = self.cursor cursor.execute("SELECT value FROM %s WHERE id=%s" % (self.table, id)) print cursor._last_executed r = cursor.fetchone() if r: r = r[0] if r is None: r = self.NULL mc.set(mc_key, r) return r
def id_by_value(self, value): mc_key = hashlib.md5(self.prefix_v % value).hexdigest() r = mc.get(mc_key) if r is None: cursor = self.cursor cursor.execute('SELECT id FROM %s WHERE value="%s"' % (self.table, value)) print cursor._last_executed r = cursor.fetchone() if r: r = r[0] mc.set(mc_key, r) else: r = 0 return r
def get(cls, id=None, **kwargs): if id is None: if not kwargs: return data = None if id: id = str(id) kwargs['id'] = id mc_key = cls.MC_KEY % id data = mc.get(mc_key) if data: data = unpackb(data) return cls._data_to_obj(data) cur = connection.cursor() values = ['='.join((k, '"%s"' % v)) for k, v in kwargs.iteritems()] sql = 'SELECT * FROM %s WHERE '+' and '.join(values)+' LIMIT 1' cur.execute(sql % cls.__table__) data = cur.fetchone() print cur._last_executed if id or data: _id = data[0] if data else id mc_key = cls.MC_KEY % _id mc.set(mc_key, packb(data)) return cls._data_to_obj(data)