Output a warning if there are update/insert querys cached when exit programm
This commit is contained in:
17
mysqlred.py
17
mysqlred.py
@@ -31,6 +31,8 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
import MySQLdb as mysqldb
|
import MySQLdb as mysqldb
|
||||||
|
|
||||||
|
import atexit
|
||||||
|
|
||||||
from pywikibot import config
|
from pywikibot import config
|
||||||
|
|
||||||
import jogobot
|
import jogobot
|
||||||
@@ -72,7 +74,10 @@ class MysqlRed:
|
|||||||
user=type( self ).db_username,
|
user=type( self ).db_username,
|
||||||
passwd=type( self ).db_password,
|
passwd=type( self ).db_password,
|
||||||
db=type( self ).db_name )
|
db=type( self ).db_name )
|
||||||
|
|
||||||
|
# Register callback for warnig if exit with cached db write querys
|
||||||
|
atexit.register( type(self).warn_if_not_flushed )
|
||||||
|
|
||||||
def __del__( self ):
|
def __del__( self ):
|
||||||
"""
|
"""
|
||||||
Before deleting class, close connection to MySQL-DB
|
Before deleting class, close connection to MySQL-DB
|
||||||
@@ -108,6 +113,16 @@ class MysqlRed:
|
|||||||
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()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def warn_if_not_flushed(cls):
|
||||||
|
"""
|
||||||
|
Outputs a warning if there are db write querys cached and not flushed
|
||||||
|
before exiting programm!
|
||||||
|
"""
|
||||||
|
if cls._cached_update_data or cls._cached_insert_data:
|
||||||
|
jogobot.output( "Cached Database write querys not flushed!!! " +
|
||||||
|
"Data loss is possible!", "WARNING" )
|
||||||
|
|
||||||
|
|
||||||
class MysqlRedPage( MysqlRed ):
|
class MysqlRedPage( MysqlRed ):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user