本文整理汇总了Python中MySQLdb.Warning方法的典型用法代码示例。如果您正苦于以下问题:Python MySQLdb.Warning方法的具体用法?Python MySQLdb.Warning怎么用?Python MySQLdb.Warning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySQLdb
的用法示例。
在下文中一共展示了MySQLdb.Warning方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_db
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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()
示例2: drop_db
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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()
示例3: start_event_scheduler
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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()
示例4: stop_event_scheduler
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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()
示例5: query_database
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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
示例6: vadinfo_parser
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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})
示例7: handle
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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()
开发者ID:california-civic-data-coalition,项目名称:django-calaccess-campaign-browser,代码行数:20,代码来源:loadcalaccesscampaignfilers.py
示例8: __init__
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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()
示例9: execute_anything
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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))
示例10: stop_replication
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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()
示例11: initialize
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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'
示例12: parse_json
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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})
示例13: handle
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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()
开发者ID:california-civic-data-coalition,项目名称:django-calaccess-campaign-browser,代码行数:14,代码来源:loadcalaccesscampaignexpenditures.py
示例14: handle
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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()
开发者ID:california-civic-data-coalition,项目名称:django-calaccess-campaign-browser,代码行数:15,代码来源:loadcalaccesscampaigncontributions.py
示例15: handle
# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import Warning [as 别名]
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()
开发者ID:california-civic-data-coalition,项目名称:django-calaccess-campaign-browser,代码行数:13,代码来源:loadcalaccesscampaignfilings.py