(self, sql)
| 100 | ''' |
| 101 | |
| 102 | def execute_sql(self, sql): |
| 103 | fail = 1 |
| 104 | self.conn = self.resetConn(timeout=2) |
| 105 | cur = self.conn.cursor() |
| 106 | i = 0 |
| 107 | cnt = 5 # retry times |
| 108 | while fail == 1 and i < cnt: |
| 109 | try: |
| 110 | fail = 0 |
| 111 | print("========== start execution time:", time.time()) |
| 112 | cur.execute(sql) |
| 113 | except BaseException: |
| 114 | fail = 1 |
| 115 | time.sleep(1) |
| 116 | res = [] |
| 117 | if fail == 0: |
| 118 | res = cur.fetchall() |
| 119 | i = i + 1 |
| 120 | logging.debug('database {}, return flag {}, execute sql {}\n'.format(self.args.dbname, 1 - fail, sql)) |
| 121 | |
| 122 | cur.close() |
| 123 | self.conn.close() |
| 124 | |
| 125 | print("========== finish time:", time.time()) |
| 126 | |
| 127 | if fail == 1: |
| 128 | # raise RuntimeError("Database query failed") |
| 129 | print("SQL Execution Fatal!!") |
| 130 | |
| 131 | return 0, '' |
| 132 | elif fail == 0: |
| 133 | # print("SQL Execution Succeed!!") |
| 134 | |
| 135 | return 1, res |
| 136 | |
| 137 | def pgsql_results(self, sql): |
| 138 | try: |
no test coverage detected