@@ -29,8 +29,6 @@ def run(self):
29
29
if not self .query :
30
30
return
31
31
32
- queryTimerStart = time .time ()
33
-
34
32
self .args = map (str , self .args )
35
33
si = None
36
34
if os .name == 'nt' :
@@ -45,6 +43,8 @@ def run(self):
45
43
if self .silenceErrors :
46
44
stderrHandle = subprocess .PIPE
47
45
46
+ queryTimerStart = time .time ()
47
+
48
48
self .process = subprocess .Popen (self .args ,
49
49
stdout = subprocess .PIPE ,
50
50
stderr = stderrHandle ,
@@ -64,13 +64,8 @@ def run(self):
64
64
self .process .terminate ()
65
65
66
66
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 )
74
69
75
70
return
76
71
@@ -91,15 +86,21 @@ def run(self):
91
86
'replace' ).replace ('\r ' , '' )
92
87
93
88
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 )
100
91
101
92
self .callback (resultString )
102
93
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
+
103
104
@staticmethod
104
105
def createAndRun (args , query , callback , options = None , timeout = 15 , silenceErrors = False , stream = False ):
105
106
if options is None :
0 commit comments