@@ -29,8 +29,6 @@ def run(self):
2929 if not self .query :
3030 return
3131
32- queryTimerStart = time .time ()
33-
3432 self .args = map (str , self .args )
3533 si = None
3634 if os .name == 'nt' :
@@ -45,6 +43,8 @@ def run(self):
4543 if self .silenceErrors :
4644 stderrHandle = subprocess .PIPE
4745
46+ queryTimerStart = time .time ()
47+
4848 self .process = subprocess .Popen (self .args ,
4949 stdout = subprocess .PIPE ,
5050 stderr = stderrHandle ,
@@ -64,13 +64,8 @@ def run(self):
6464 self .process .terminate ()
6565
6666 if 'show_query' in self .options and self .options ['show_query' ]:
67- resultInfo = "/*\n -- Executed querie(s) at {0} took {1:.3f}ms --" .format (
68- str (time .strftime ("%Y-%m-%d %H:%M:%S" , time .localtime (queryTimerStart ))),
69- (queryTimerEnd - queryTimerStart ))
70- resultLine = "-" * (len (resultInfo ) - 3 )
71- resultString = "{0}\n {1}\n {2}\n {3}\n */" .format (
72- resultInfo , resultLine , self .query , resultLine )
73- return self .callback (resultString )
67+ formattedQueryInfo = self ._formatShowQuery (self .query , queryTimerStart , queryTimerEnd )
68+ self .callback (formattedQueryInfo )
7469
7570 return
7671
@@ -91,15 +86,21 @@ def run(self):
9186 'replace' ).replace ('\r ' , '' )
9287
9388 if 'show_query' in self .options and self .options ['show_query' ]:
94- resultInfo = "/*\n -- Executed querie(s) at {0} took {1:.3f}ms --" .format (
95- str (time .strftime ("%Y-%m-%d %H:%M:%S" , time .localtime (queryTimerStart ))),
96- (queryTimerEnd - queryTimerStart ))
97- resultLine = "-" * (len (resultInfo ) - 3 )
98- resultString = "{0}\n {1}\n {2}\n {3}\n */\n {4}" .format (
99- resultInfo , resultLine , self .query , resultLine , resultString )
89+ formattedQueryInfo = self ._formatShowQuery (self .query , queryTimerStart , queryTimerEnd )
90+ resultString = "{0}\n {1}" .format (formattedQueryInfo , resultString )
10091
10192 self .callback (resultString )
10293
94+ @staticmethod
95+ def _formatShowQuery (query , queryTimeStart , queryTimeEnd ):
96+ resultInfo = "/*\n -- Executed querie(s) at {0} took {1:.3f} s --" .format (
97+ str (time .strftime ("%Y-%m-%d %H:%M:%S" , time .localtime (queryTimeStart ))),
98+ (queryTimeEnd - queryTimeStart ))
99+ resultLine = "-" * (len (resultInfo ) - 3 )
100+ resultString = "{0}\n {1}\n {2}\n {3}\n */" .format (
101+ resultInfo , resultLine , query , resultLine )
102+ return resultString
103+
103104 @staticmethod
104105 def createAndRun (args , query , callback , options = None , timeout = 15 , silenceErrors = False , stream = False ):
105106 if options is None :
0 commit comments