Fix bug (Cached querys not executed) caused by class attribute protection level --> changed from private to protected
Reformat MySQL querys to remove whitespace generated by indetation
This commit is contained in:
72
mysqlred.py
72
mysqlred.py
@@ -52,10 +52,10 @@ class MysqlRed:
|
|||||||
db_name = config.db_username + jogobot.db_namesuffix
|
db_name = config.db_username + jogobot.db_namesuffix
|
||||||
|
|
||||||
# Class variables for storing cached querys
|
# Class variables for storing cached querys
|
||||||
__cached_update_data = []
|
_cached_update_data = []
|
||||||
__update_query = ''
|
_update_query = ''
|
||||||
__cached_insert_data = []
|
_cached_insert_data = []
|
||||||
__insert_query = ''
|
_insert_query = ''
|
||||||
|
|
||||||
def __init__( self ):
|
def __init__( self ):
|
||||||
"""
|
"""
|
||||||
@@ -88,18 +88,18 @@ class MysqlRed:
|
|||||||
cursor = cls.connection.cursor()
|
cursor = cls.connection.cursor()
|
||||||
|
|
||||||
# Execute insert query
|
# Execute insert query
|
||||||
if cls.__cached_insert_data:
|
if cls._cached_insert_data:
|
||||||
cursor.execute( cls.__insert_query, cls.__cached_insert_data )
|
cursor.executemany( cls._insert_query, cls._cached_insert_data )
|
||||||
cls.__cached_insert_data = []
|
cls._cached_insert_data = []
|
||||||
|
|
||||||
# Execute update query
|
# Execute update query
|
||||||
# Use executemany since update could not be reduced to one query
|
# Use executemany since update could not be reduced to one query
|
||||||
if cls.__cached_update_data:
|
if cls._cached_update_data:
|
||||||
cursor.executemany( cls.__update_query, cls.__cached_update_data )
|
cursor.executemany( cls._update_query, cls._cached_update_data )
|
||||||
cls.__cached_update_data = []
|
cls._cached_update_data = []
|
||||||
|
|
||||||
# Commit db changes
|
# Commit db changes
|
||||||
if cls.__cached_insert_data or cls.__cached_update_data:
|
if cls._cached_insert_data or cls._cached_update_data:
|
||||||
cls.connection.commit()
|
cls.connection.commit()
|
||||||
|
|
||||||
|
|
||||||
@@ -109,14 +109,13 @@ class MysqlRedPage( MysqlRed ):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Class variables for storing cached querys
|
# Class variables for storing cached querys
|
||||||
__cached_update_data = []
|
_cached_update_data = []
|
||||||
__update_query = 'UPDATE `red_pages` \
|
_update_query = 'UPDATE `red_pages` \
|
||||||
SET `page_title` = ?, `rev_id` = ?, `status`= ? \
|
SET `page_title` = ?, `rev_id` = ?, `status`= ? WHERE `page_id` = ?;'
|
||||||
WHERE `page_id` = ?;'
|
|
||||||
__cached_insert_data = []
|
_cached_insert_data = []
|
||||||
__insert_query = 'INSERT INTO `red_pages` \
|
_insert_query = 'INSERT INTO `red_pages` \
|
||||||
( page_id, page_title, rev_id, status ) \
|
( page_id, page_title, rev_id, status ) VALUES ( ?, ?, ?, ? );'
|
||||||
VALUES ( ?, ?, ?, ? );'
|
|
||||||
|
|
||||||
def __init__( self, page_id ):
|
def __init__( self, page_id ):
|
||||||
"""
|
"""
|
||||||
@@ -162,7 +161,7 @@ class MysqlRedPage( MysqlRed ):
|
|||||||
@param int status Page parsing status
|
@param int status Page parsing status
|
||||||
"""
|
"""
|
||||||
|
|
||||||
type( self ).__cached_insert_data.apend( ( self.__page_id, page_title,
|
type( self )._cached_insert_data.append( ( self.__page_id, page_title,
|
||||||
rev_id, status ) )
|
rev_id, status ) )
|
||||||
|
|
||||||
# Manualy construct self.data dict
|
# Manualy construct self.data dict
|
||||||
@@ -183,25 +182,26 @@ class MysqlRedPage( MysqlRed ):
|
|||||||
if not rev_id:
|
if not rev_id:
|
||||||
rev_id = self.data[ 'rev_id' ]
|
rev_id = self.data[ 'rev_id' ]
|
||||||
|
|
||||||
type( self ).__cached_update_data.append( ( page_title, rev_id,
|
type( self )._cached_update_data.append( ( page_title, rev_id,
|
||||||
status, self.__page_id ) )
|
status, self.__page_id ) )
|
||||||
|
|
||||||
|
|
||||||
class MysqlRedFam( MysqlRed ):
|
class MysqlRedFam( MysqlRed ):
|
||||||
"""
|
"""
|
||||||
MySQL-db Interface for handling querys for RedFams
|
MySQL-db Interface for handling querys for RedFams
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Class variables for storing cached querys
|
# Class variables for storing cached querys
|
||||||
__cached_update_data = []
|
_cached_update_data = []
|
||||||
__update_query = 'UPDATE `red_families` \
|
_update_query = 'UPDATE `red_families` \
|
||||||
SET `red_page_id` = ?, `heading` = ?, `beginning` = ?, \
|
SET `red_page_id` = ?, `heading` = ?, `beginning` = ?, `ending` = ?, \
|
||||||
`ending` = ?, `status`= ? WHERE `fam_hash` = ?;'
|
`status`= ? WHERE `fam_hash` = ?;'
|
||||||
__cached_insert_data = []
|
|
||||||
__insert_query = 'INSERT INTO `red_families` \
|
_cached_insert_data = []
|
||||||
( fam_hash, red_page_id, beginning, ending, status, \
|
_insert_query = 'INSERT INTO `red_families` \
|
||||||
heading, article0, article1, article2, article3, \
|
( fam_hash, red_page_id, beginning, ending, status, heading, \
|
||||||
article4, article5, article6, article7 ) \
|
article0, article1, article2, article3, article4, article5, article6, \
|
||||||
VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );'
|
article7 ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );'
|
||||||
|
|
||||||
def __init__( self, fam_hash ):
|
def __init__( self, fam_hash ):
|
||||||
"""
|
"""
|
||||||
@@ -250,7 +250,7 @@ class MysqlRedFam( MysqlRed ):
|
|||||||
|
|
||||||
data = tuple( data )
|
data = tuple( data )
|
||||||
|
|
||||||
type( self ).__cached_insert_data.append( data )
|
type( self )._cached_insert_data.append( data )
|
||||||
|
|
||||||
# Manualy construct self.data dict
|
# Manualy construct self.data dict
|
||||||
data_keys = ( 'fam_hash', 'red_page_id', 'beginning', 'ending',
|
data_keys = ( 'fam_hash', 'red_page_id', 'beginning', 'ending',
|
||||||
@@ -269,6 +269,6 @@ class MysqlRedFam( MysqlRed ):
|
|||||||
@param int status red_fam status
|
@param int status red_fam status
|
||||||
"""
|
"""
|
||||||
|
|
||||||
type( self ).__cached_update_data.append( ( red_page_id, heading,
|
type( self )._cached_update_data.append( ( red_page_id, heading,
|
||||||
beginning, ending, status,
|
beginning, ending, status,
|
||||||
self.__fam_hash ) )
|
self.__fam_hash ) )
|
||||||
|
|||||||
Reference in New Issue
Block a user