Browse Source

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]
develop
Jonathan Golder 8 years ago
parent
commit
9481116777
  1. 23
      lib/mysqlred.py

23
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):
"""

Loading…
Cancel
Save