| 100 | |
| 101 | |
| 102 | class MySQLClient(BaseJdbcClient): |
| 103 | def get_databases(self): |
| 104 | cursor = self.conn.cursor() |
| 105 | cursor.execute("SHOW DATABASES") |
| 106 | return [db[0] for db in cursor] |
| 107 | |
| 108 | def get_tables(self, database): |
| 109 | cursor = self.conn.cursor() |
| 110 | cursor.execute(f"SHOW TABLES FROM {database}") |
| 111 | return [table[0] for table in cursor] |
| 112 | |
| 113 | def run_query(self, sql): |
| 114 | cursor = self.conn.cursor() |
| 115 | cursor.execute(sql) |
| 116 | column_names = [col[0] for col in cursor.description] |
| 117 | rows = [column_names] # First row is column names |
| 118 | |
| 119 | for row in cursor.fetchall(): |
| 120 | rows.append([str(col) if col is not None else None for col in row]) |
| 121 | |
| 122 | return rows |
| 123 | |
| 124 | def generate_select_all_data_sql(self, database, table_name): |
| 125 | return f"SELECT * FROM {database}.{table_name}" |