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