Python MySQLdb.Warning() Examples
The following are 19
code examples of MySQLdb.Warning().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
MySQLdb
, or try the search function
.
Example #1
Source File: mysql_lib.py From mysql_utils with GNU General Public License v2.0 | 6 votes |
def create_db(instance, db): """ Create a database if it does not already exist Args: instance - a hostAddr object db - the name of the db to be created """ conn = connect_mysql(instance) cursor = conn.cursor() sql = ('CREATE DATABASE IF NOT EXISTS `{}`'.format(db)) log.info(sql) # We don't care if the db already exists and this was a no-op warnings.filterwarnings('ignore', category=MySQLdb.Warning) cursor.execute(sql) warnings.resetwarnings()
Example #2
Source File: mysql_lib.py From mysql_utils with GNU General Public License v2.0 | 6 votes |
def drop_db(instance, db): """ Drop a database, if it exists. Args: instance - a hostAddr object db - the name of the db to be dropped """ conn = connect_mysql(instance) cursor = conn.cursor() sql = ('DROP DATABASE IF EXISTS `{}`'.format(db)) log.info(sql) # If the DB isn't there, we'd throw a warning, but we don't # actually care; this will be a no-op. warnings.filterwarnings('ignore', category=MySQLdb.Warning) cursor.execute(sql) warnings.resetwarnings()
Example #3
Source File: mysql_lib.py From mysql_utils with GNU General Public License v2.0 | 6 votes |
def start_event_scheduler(instance): """ Enable the event scheduler on a given MySQL server. Args: instance: The hostAddr object to act upon. """ cmd = 'SET GLOBAL event_scheduler=ON' # We don't use the event scheduler in many places, but if we're # not able to start it when we want to, that could be a big deal. try: conn = connect_mysql(instance) cursor = conn.cursor() warnings.filterwarnings('ignore', category=MySQLdb.Warning) log.info(cmd) cursor.execute(cmd) except Exception as e: log.error('Unable to start event scheduler: {}'.format(e)) raise finally: warnings.resetwarnings()
Example #4
Source File: mysql_lib.py From mysql_utils with GNU General Public License v2.0 | 6 votes |
def stop_event_scheduler(instance): """ Disable the event scheduler on a given MySQL server. Args: instance: The hostAddr object to act upon. """ cmd = 'SET GLOBAL event_scheduler=OFF' # If for some reason we're unable to disable the event scheduler, # that isn't likely to be a big deal, so we'll just pass after # logging the exception. try: conn = connect_mysql(instance) cursor = conn.cursor() warnings.filterwarnings('ignore', category=MySQLdb.Warning) log.info(cmd) cursor.execute(cmd) except Exception as e: log.error('Unable to stop event scheduler: {}'.format(e)) pass finally: warnings.resetwarnings()
Example #5
Source File: sqlhandler.py From lightbulb-framework with MIT License | 6 votes |
def query_database(self, query): """ Perform a database query Args: query (str): The SQL query Returns: list: Mysql Rows """ try: self.cursor.execute(query) return self.cursor.fetchall() except MySQLdb.Error as err: # print("Failed executing query: {}".format(err)) return 0 except MySQLdb.Warning as wrn: return 0
Example #6
Source File: volatility_parser.py From vortessence with GNU General Public License v2.0 | 6 votes |
def vadinfo_parser(json_file): with open(json_file) as input_file: data = json.load(input_file) for i in data: process = utils.get_process_by_pid(data[i]["UniqueProcessId"]) for v in data[i]["VADs"]: try: Vad(process=process, start=v["VadShort"]["Start"], end=v["VadShort"]["End"], vad_type=", ".join(v["VadShort"]["VadType"]), protection=v["VadShort"]["Protection"], fileobject=v["VadControl"]["FileObject"]["FileName"] if v["VadControl"] and v["VadControl"][ "FileObject"] else "").save() except MySQLdb.Warning as details: logger.error( "Parsing error: unable to read VAD line for process {} with start {} and end {}. Message: {}".format( process.id, v["VadShort"]["Start"], v["VadShort"]["End"], details), {"snapshot": utils.item_store.snapshot})
Example #7
Source File: loadcalaccesscampaignfilers.py From django-calaccess-campaign-browser with MIT License | 6 votes |
def handle(self, *args, **options): self.header("Loading filers and committees") # Ignore MySQL warnings so this can be run with DEBUG=True warnings.filterwarnings("ignore", category=MySQLdb.Warning) self.conn = connection.cursor() self.drop_temp_tables() self.create_temp_tables() self.load_cycles() self.load_candidate_filers() self.create_temp_candidate_committee_tables() self.load_candidate_committees() self.create_temp_pac_tables() self.load_pac_filers() self.load_pac_committees() self.drop_temp_tables()
Example #8
Source File: chdb.py From citationhunt with MIT License | 5 votes |
def ignore_warnings(): warnings.filterwarnings('ignore', category = MySQLdb.Warning) yield warnings.resetwarnings()
Example #9
Source File: database.py From Penny-Dreadful-Tools with GNU General Public License v3.0 | 5 votes |
def __init__(self, db: str) -> None: warnings.filterwarnings('error', category=MySQLdb.Warning) self.name = db self.host = configuration.get_str('mysql_host') self.port = configuration.get_int('mysql_port') self.user = configuration.get_str('mysql_user') self.passwd = configuration.get_str('mysql_passwd') self.open_transactions: List[str] = [] self.connect()
Example #10
Source File: trojan_manager.py From trojan-manager with GNU General Public License v3.0 | 5 votes |
def catch_mysql_errors(function): """ Catch mysqldb warnings and errors """ def wrapper(*args, **kwargs): try: function(*args, **kwargs) except (MySQLdb.Error, MySQLdb.Warning) as e: Avalon.error(e) return 1 return wrapper
Example #11
Source File: locustfile.py From edx-load-tests with Apache License 2.0 | 5 votes |
def __init__(self): '''Constructor. DATABASE environment variables must be set (via locustsetting.py) prior to constructing this object.''' super(UserStateClientClient, self).__init__() # Without this, the greenlets will halt for database warnings filterwarnings('ignore', category=Database.Warning) self.client = UserStateClient(user=UserFactory.create()) # Help the template loader find our template.
Example #12
Source File: loadcalaccesscampaignsummaries.py From django-calaccess-campaign-browser with MIT License | 5 votes |
def load_csv(self): self.log(" Loading transformed CSV") # Ignore MySQL warnings so this can be run with DEBUG=True warnings.filterwarnings("ignore", category=MySQLdb.Warning) c = connection.cursor() sql = """ LOAD DATA LOCAL INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\\r\\n' IGNORE 1 LINES ( filing_id_raw, amend_id, itemized_monetary_contributions, unitemized_monetary_contributions, total_monetary_contributions, non_monetary_contributions, total_contributions, itemized_expenditures, unitemized_expenditures, total_expenditures, ending_cash_balance, outstanding_debts ) """ % (self.target_csv, Summary._meta.db_table) c.execute(sql)
Example #13
Source File: loadcalaccesscampaignfilings.py From django-calaccess-campaign-browser with MIT License | 5 votes |
def handle(self, *args, **options): """ Loads raw filings into consolidated tables """ self.header("Loading filings") # Ignore MySQL warnings so this can be run with DEBUG=True warnings.filterwarnings("ignore", category=MySQLdb.Warning) if options['flush']: self.flush() self.load_filings() self.mark_duplicates()
Example #14
Source File: loadcalaccesscampaigncontributions.py From django-calaccess-campaign-browser with MIT License | 5 votes |
def handle(self, *args, **options): self.header("Loading contributions") self.set_options(*args, **options) # Ignore MySQL warnings so this can be run with DEBUG=True warnings.filterwarnings("ignore", category=MySQLdb.Warning) self.log(" Quarterly filings") self.transform_quarterly_contributions_csv() self.load_quarterly_contributions() self.log(" Late filings") self.transform_late_contributions_csv() self.load_late_contributions()
Example #15
Source File: loadcalaccesscampaignexpenditures.py From django-calaccess-campaign-browser with MIT License | 5 votes |
def handle(self, *args, **options): self.header("Loading expenditures") self.set_options(*args, **options) warnings.filterwarnings("ignore", category=MySQLdb.Warning) self.log(" Quarterly filings") if options['transform_quarterly']: self.transform_quarterly_expenditures_csv() if options['load_quarterly']: self.load_quarterly_expenditures()
Example #16
Source File: volatility_parser.py From vortessence with GNU General Public License v2.0 | 5 votes |
def parse_json(plugin, voloutput_folder, snapshot_id, options): filename = voloutput_folder + os.sep + plugin + "_" + str(snapshot_id) try: if options is not None: globals()[plugin + "_parser"](filename, options) else: globals()[plugin + "_parser"](filename) except IOError: logger.error("Parsing Error: file {} not found".format(filename), {"snapshot": utils.item_store.snapshot}) except ValueError as e: logger.warning("Parsing Warning in file {0}: {1}".format(filename, e), {"snapshot": utils.item_store.snapshot})
Example #17
Source File: sqlhandler.py From lightbulb-framework with MIT License | 5 votes |
def initialize(self): """Initialize SQL database in the correct state""" for name, ddl in self.DROP.iteritems(): try: print "Drop table {}:".format(name), self.cursor.execute(ddl) except MySQLdb.Error as err: print err except MySQLdb.Warning as wrn: pass finally: print 'OK' for name, ddl in self.TABLES.iteritems(): try: print "Creating table {}:".format(name), self.cursor.execute(ddl) except MySQLdb.Error as err: print err except MySQLdb.Warning as wrn: pass finally: print 'OK' for name, ddl in self.INSERT.iteritems(): try: print "Inserting into table {}:".format(name), self.cursor.execute(ddl) except MySQLdb.Error as err: print err except MySQLdb.Warning as wrn: pass finally: print 'OK'
Example #18
Source File: mysql_lib.py From mysql_utils with GNU General Public License v2.0 | 5 votes |
def stop_replication(instance, thread_type=REPLICATION_THREAD_ALL): """ Stop replication, if running Args: instance - A hostAddr object thread - Which thread to stop. Options are in REPLICATION_THREAD_TYPES. """ if thread_type not in REPLICATION_THREAD_TYPES: raise Exception('Invalid input for arg thread: {thread}' ''.format(thread=thread_type)) conn = connect_mysql(instance) cursor = conn.cursor() ss = get_slave_status(instance) if (ss['Slave_IO_Running'] != 'No' and ss['Slave_SQL_Running'] != 'No' and thread_type == REPLICATION_THREAD_ALL): cmd = 'STOP SLAVE' elif ss['Slave_IO_Running'] != 'No' and thread_type != REPLICATION_THREAD_SQL: cmd = 'STOP SLAVE IO_THREAD' elif ss['Slave_SQL_Running'] != 'No' and thread_type != REPLICATION_THREAD_IO: cmd = 'STOP SLAVE SQL_THREAD' else: log.info('Replication already stopped') return warnings.filterwarnings('ignore', category=MySQLdb.Warning) log.info(cmd) cursor.execute(cmd) warnings.resetwarnings()
Example #19
Source File: database.py From Penny-Dreadful-Tools with GNU General Public License v3.0 | 5 votes |
def execute_anything(self, sql: str, args: Optional[List[ValidSqlArgumentDescription]] = None, fetch_rows: bool = True) -> Tuple[int, List[Dict[str, ValidSqlArgumentDescription]]]: if args is None: args = [] try: return self.execute_with_reconnect(sql, args, fetch_rows) except MySQLdb.Warning as e: if e.args[0] == 1050 or e.args[0] == 1051: return (0, []) # we don't care if a CREATE IF NOT EXISTS raises an "already exists" warning or DROP TABLE IF NOT EXISTS raises an "unknown table" warning. if e.args[0] == 1062: return (0, []) # We don't care if an INSERT IGNORE INTO didn't do anything. raise DatabaseException('Failed to execute `{sql}` with `{args}` because of `{e}`'.format(sql=sql, args=args, e=e)) except MySQLdb.Error as e: raise DatabaseException('Failed to execute `{sql}` with `{args}` because of `{e}`'.format(sql=sql, args=args, e=e))