Skip to content

Commit 1dd9578

Browse files
committed
added conditional print statement to only print number of drops removed if more than 0
1 parent a08ce0f commit 1dd9578

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

mysql/toolkit/components/advanced.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ def truncate_database(self):
9797
self._printer('\t' + str(len(tables)), 'tables truncated')
9898
return tables
9999

100-
def execute_script(self, sql_script, commands=None, split_func=True, split_char=';'):
100+
def execute_script(self, sql_script, commands=None, split_func=True, split_char=';', dump_fails=True):
101101
"""Wrapper method for ExecuteScript class."""
102-
ExecuteScript(self, sql_script, commands, split_func, split_char)
102+
ExecuteScript(self, sql_script, commands, split_func, split_char, dump_fails)

mysql/toolkit/components/execute.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class ExecuteScript:
8-
def __init__(self, mysql_instance, sql_script, commands=None, split_func=True, split_char=';'):
8+
def __init__(self, mysql_instance, sql_script, commands=None, split_func=True, split_char=';', dump_fails=True):
99
"""Execute a sql file one command at a time."""
1010
# Pass MySQL instance from execute_script method to ExecuteScript class
1111
self.MySQL = mysql_instance
@@ -27,7 +27,7 @@ def __init__(self, mysql_instance, sql_script, commands=None, split_func=True, s
2727
self.execute_commands()
2828

2929
# Dump failed commands to text file
30-
if len(self.fail) > 1:
30+
if len(self.fail) > 1 and dump_fails:
3131
self.dump_fails()
3232

3333
def _get_commands(self, sql_script):
@@ -46,7 +46,9 @@ def execute_commands(self):
4646
# Remove 'DROP' commands
4747
commands_with_drops = len(self.commands)
4848
self.commands = [c for c in self.commands if not c.startswith('DROP')]
49-
print("\tDROP commands removed", commands_with_drops - len(self.commands))
49+
removed = commands_with_drops - len(self.commands)
50+
if removed > 0:
51+
print("\tDROP commands removed", removed)
5052

5153
# Execute every command from the input file
5254
print('\t' + str(len(self.commands)), 'commands')

0 commit comments

Comments
 (0)