def add(cate, title, url, content, author): mc.delete('as:%s'%author) mc.delete('ac:%s'%cate) cursor = get_cursor() sql = 'insert into article (cate, title, url, content, author) values ' \ '(%s, %s, %s, %s, %s)' params = (cate, title, url, content, author) try: cursor.execute(sql, params) cursor.connection.commit() return True except: cursor.connection.rollback() return False
def add(cate, title, url, content, author): mc.delete('as:%s' % author) mc.delete('ac:%s' % cate) cursor = get_cursor() sql = 'insert into article (cate, title, url, content, author) values ' \ '(%s, %s, %s, %s, %s)' params = (cate, title, url, content, author) try: cursor.execute(sql, params) cursor.connection.commit() return True except: cursor.connection.rollback() return False
def delete(self): cursor = get_cursor() sql = 'delete from article where id = %s' params = (self.id) cursor.execute(sql, params) cursor.connection.commit() mc.delete('a:%s'%self.id) mc.delete('as:%s'%self.author) mc.delete('ac:%s'%self.cate)
def delete(self): cursor = get_cursor() sql = 'delete from article where id = %s' params = (self.id) cursor.execute(sql, params) cursor.connection.commit() mc.delete('a:%s' % self.id) mc.delete('as:%s' % self.author) mc.delete('ac:%s' % self.cate)
def update(self, old_cate): cursor = get_cursor() sql = 'update article set title=%s, cate=%s, url=%s, content=%s, author=%s ' \ 'where id=%s' params = (self.title, self.cate, self.url, self.content, self.author, self.id) cursor.execute(sql, params) cursor.connection.commit() mc.delete('a:%s'%self.id) if self.cate != old_cate: mc.delete('ac:%s'%self.cate) mc.delete('ac:%s'%old_cate)
def update(self, old_cate): cursor = get_cursor() sql = 'update article set title=%s, cate=%s, url=%s, content=%s, author=%s ' \ 'where id=%s' params = (self.title, self.cate, self.url, self.content, self.author, self.id) cursor.execute(sql, params) cursor.connection.commit() mc.delete('a:%s' % self.id) if self.cate != old_cate: mc.delete('ac:%s' % self.cate) mc.delete('ac:%s' % old_cate)