Implement a class MYSQL_RED_PAGE as desecendant of MYSQL_RED for handling querys about red_pages

This commit is contained in:
2015-09-05 17:10:55 +02:00
parent 597df69275
commit f5ac6a06d3

View File

@@ -27,3 +27,34 @@ class MYSQL_RED:
""" """
type( self ).connection.close() type( self ).connection.close()
class MYSQL_RED_PAGE( MYSQL_RED ):
def __init__( self, db_hostname, db_username, db_password, db_name ):
"""
Creates a new instance, runs __init__ of parent class
"""
super().__init__( db_hostname, db_username, db_password, db_name )
def get_page( self, page_id ):
"""
Retrieves a red page row from MySQL-Database for given page_id
@param int page_id MediaWiki page_id for page to retrieve
@returns tuple Tuple with data for given page_id otherwise if none found
bool FALSE
"""
cursor = type( self ).connection.cursor()
format_str = """SELECT * FROM `red_pages` WHERE page_id={page_id};"""
query = format_str.format( page_id=int( page_id ) )
cursor.execute( query )
res = cursor.fetchone()
if res:
return res
else:
return False