(self, sql)
| 170 | return result |
| 171 | |
| 172 | def operate_SQL(self, sql): |
| 173 | # SQL包含表名以及数据库名称 |
| 174 | match = re.search(r'FROM\s+(\S+)\.(\S+)', sql) |
| 175 | database_name = None |
| 176 | table_name = None |
| 177 | if match: |
| 178 | database_name = match.group(0) |
| 179 | table_name = match.group(1) |
| 180 | # SQL不包含数据库名,只包含表名 |
| 181 | match = re.search(r'FROM\s+(\S+)', sql) |
| 182 | if match: |
| 183 | table_name = match.group(1) |
| 184 | else: |
| 185 | logging.error("Table Name is not found, please check SQL") |
| 186 | if database_name is None: |
| 187 | for jdbc in self.jdbcList: |
| 188 | tables = self.tableList.get(jdbc) |
| 189 | if tables.__contains__(table_name): |
| 190 | database_name = str(jdbc).split('/')[-1] |
| 191 | break |
| 192 | if database_name is None: |
| 193 | if table_name is None: |
| 194 | logging.error("Cannot find the database and table") |
| 195 | else: |
| 196 | logging.error("Cannot find the database contain table: " + table_name) |
| 197 | # 执行结果 |
| 198 | if database_name is not None or table_name is not None: |
| 199 | for jdbc in self.jdbcList: |
| 200 | if str(jdbc).split('/')[-1] == database_name: |
| 201 | engine = self.connMap.get(jdbc) |
| 202 | with engine.connect() as conn: |
| 203 | start_time = time.time() |
| 204 | result = conn.execute(text(sql)) |
| 205 | end_time = time.time() |
| 206 | logging.info("sql: " + sql + " cost time " + str(end_time - start_time)) |
| 207 | result = self.process_result(sql, result) |
| 208 | return result |
| 209 | |
| 210 | def get_db_structure_and_index(self, sql): |
| 211 | """ |
nothing calls this directly
no test coverage detected