def launch_queries(directory, server):
"""
Launch the queries found in the specified folder
Param directory string Folder containing the SQL files
Param server dict describing a server
Returns: Bool value of whether we get query output or not
"""
query_folder = os.path.join(directory, server['name'])
files = get_query_files(query_folder)
produced_output = False
for filename in files:
query_filename = os.path.join(directory, server['name'], filename)
output = None
with open(query_filename, 'r') as opened_file:
query = opened_file.read()
start_time = time.time()
try:
output = get_query_output(server, query)
except DBAPIError:
print "The following SQL query got interrupted:"
print query
print
continue
query_time = round(time.time() - start_time, 3)
syslog.syslog('{} successfully ran in {} sec.'.format(filename,
query_time))
if output:
produced_output = True
# Announce that this query has results
print "-----===== /!\ INCOMING BAD DATA /!\ =====-----"
print
print "Server: {}".format(server['name'])
print "File: {}".format(filename)
print
# Display the raw query
print "SQL Query:"
print query
# Display the results of the query
print output
print
return produced_output
评论列表
文章目录