(self)
| 190 | @expose('/querySql/id', methods=("GET",)) |
| 191 | @safe |
| 192 | def query_sql_by_id(self) -> FlaskResponse: |
| 193 | data_source_id = request.args.get('dataSourceId', type=int) |
| 194 | sql = request.args.get('sql') |
| 195 | # Call the service method to execute the SQL query by ID. You need to implement this logic |
| 196 | |
| 197 | # Call the service method to get table data. You need to implement this logic |
| 198 | data_source = DataSourceDAO.get_data_source_id(data_source_id) |
| 199 | if data_source is None: |
| 200 | return self.handle_error(SolidUIErrorType.QUERY_DATASOURCE_ERROR) |
| 201 | |
| 202 | data_source_type = DataSourceTypeDAO.get_id(data_source.datasource_type_id) |
| 203 | if data_source_type is None: |
| 204 | return self.handle_error(SolidUIErrorType.QUERY_DATASOURCE_TYPE_ERROR) |
| 205 | |
| 206 | # Parse the JSON parameters |
| 207 | params = json.loads(data_source.parameter) |
| 208 | |
| 209 | # Create a JDBC client |
| 210 | jdbc_client = JdbcClientFactory.create_client( |
| 211 | db_type=data_source_type.name, # Assuming MySQL for example |
| 212 | host=params.get("host"), |
| 213 | port=params.get("port"), |
| 214 | username=params.get("username"), |
| 215 | password=params.get("password"), |
| 216 | database=params.get("database"), |
| 217 | extra_params=params.get("params", {}) |
| 218 | ) |
| 219 | |
| 220 | try: |
| 221 | |
| 222 | data_list = JdbcClientFactory.run_query(jdbc_client, sql) |
| 223 | return self.response_format(data=data_list) |
| 224 | |
| 225 | except DAONotFound as ex: |
| 226 | logger.exception(ex) |
| 227 | return self.handle_error(SolidUIErrorType.QUERY_METADATA_SQL_ERROR) |
nothing calls this directly
no test coverage detected