From 9481116777ba73f84f9b47d5425516467f637764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Wed, 2 Mar 2016 16:48:56 +0100 Subject: [PATCH] Add new generator-method to fetch RedFams by Status and Ending Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=26 FS#26] --- lib/mysqlred.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/mysqlred.py b/lib/mysqlred.py index 499816f..0be345e 100644 --- a/lib/mysqlred.py +++ b/lib/mysqlred.py @@ -246,6 +246,7 @@ class MysqlRedFam( MysqlRed ): _update_query = 'UPDATE `{prefix}_red_families` \ SET `red_page_id` = ?, `heading` = ?, `beginning` = ?, `ending` = ?, \ `status`= ? WHERE `fam_hash` = ?;' + _cached_insert_data = {} _insert_query = 'INSERT INTO `{prefix}_red_families` \ ( fam_hash, red_page_id, beginning, ending, status, heading, \ @@ -259,9 +260,6 @@ article7 ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );' super().__init__( ) - def __del__( self ): - pass - def get_fam( self, fam_hash ): """ Retrieves a red family row from MySQL-Database for given fam_hash @@ -335,6 +333,25 @@ article7 ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );' for row in res: yield row + def get_by_status_and_ending( self, status, ending ): + """ + Generator witch fetches redFams with given status from DB + """ + + cursor = type( self ).connection.cursor( mysqldb.DictCursor ) + + cursor.execute( + 'SELECT * FROM `{prefix}_red_families` WHERE `status` = ? AND'. + format(prefix=type( self ).db_table_prefix) + + '`ending` >= ?;', ( status, ending ) ) + + while True: + res = cursor.fetchmany( 1000 ) + if not res: + break + for row in res: + yield row + class MysqlRedError(Exception): """