Mercurial > kallithea
comparison pylons_app/lib/timerproxy.py @ 172:83c7ee1b5f5c
improved timerproxy with sqllogging, and new way of sqlformat queries
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 21 May 2010 03:01:31 +0200 |
parents | a5a3bcc5ee89 |
children | 5ba66bb4ca95 |
comparison
equal
deleted
inserted
replaced
171:52bbeb1e813f | 172:83c7ee1b5f5c |
---|---|
8 COLOR_SEQ = "\033[1;%dm" | 8 COLOR_SEQ = "\033[1;%dm" |
9 COLOR_SQL = YELLOW | 9 COLOR_SQL = YELLOW |
10 normal = '\x1b[0m' | 10 normal = '\x1b[0m' |
11 return COLOR_SEQ % COLOR_SQL + sql + normal | 11 return COLOR_SEQ % COLOR_SQL + sql + normal |
12 | 12 |
13 def one_space_trim(s): | |
14 if s.find(" ") == -1: | |
15 return s | |
16 else: | |
17 s = s.replace(' ', ' ') | |
18 return one_space_trim(s) | |
19 | |
13 def format_sql(sql): | 20 def format_sql(sql): |
14 sql = color_sql(sql) | 21 sql = color_sql(sql) |
15 sql = sql.replace('SELECT', '\n SELECT \n\t')\ | 22 sql = sql.replace('\n', '') |
16 .replace('FROM', '\n FROM')\ | 23 sql = one_space_trim(sql) |
17 .replace('ORDER BY', '\n ORDER BY')\ | 24 sql = sql\ |
18 .replace('LIMIT', '\n LIMIT')\ | 25 .replace('SELECT', '\n\tSELECT \n\t')\ |
19 .replace('WHERE', '\n WHERE')\ | 26 .replace('FROM', '\n\tFROM')\ |
20 .replace('AND', '\n AND')\ | 27 .replace('ORDER BY', '\n\tORDER BY')\ |
21 .replace('LEFT', '\n LEFT')\ | 28 .replace('LIMIT', '\n\tLIMIT')\ |
22 .replace('INNER', '\n INNER')\ | 29 .replace('WHERE', '\n\tWHERE')\ |
23 .replace('INSERT', '\n INSERT')\ | 30 .replace('AND', '\n\tAND')\ |
24 .replace('DELETE', '\n DELETE') | 31 .replace('LEFT', '\n\tLEFT')\ |
32 .replace('INNER', '\n\tINNER')\ | |
33 .replace('INSERT', '\n\tINSERT')\ | |
34 .replace('DELETE', '\n\tDELETE') | |
25 return sql | 35 return sql |
26 | 36 |
27 | 37 |
28 class TimerProxy(ConnectionProxy): | 38 class TimerProxy(ConnectionProxy): |
29 def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): | 39 def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): |