(self)
| 152 | @expose('/querySql', methods=("GET",)) |
| 153 | @safe |
| 154 | def query_sql(self) -> FlaskResponse: |
| 155 | data_source_name = request.args.get('dataSourceName') |
| 156 | sql = request.args.get('sql') |
| 157 | |
| 158 | # Call the service method to get table data. You need to implement this logic |
| 159 | data_source = DataSourceDAO.get_data_source_name(data_source_name) |
| 160 | if data_source is None: |
| 161 | return self.handle_error(SolidUIErrorType.QUERY_DATASOURCE_ERROR) |
| 162 | |
| 163 | data_source_type = DataSourceTypeDAO.get_id(data_source.datasource_type_id) |
| 164 | if data_source_type is None: |
| 165 | return self.handle_error(SolidUIErrorType.QUERY_DATASOURCE_TYPE_ERROR) |
| 166 | |
| 167 | # Parse the JSON parameters |
| 168 | params = json.loads(data_source.parameter) |
| 169 | |
| 170 | # Create a JDBC client |
| 171 | jdbc_client = JdbcClientFactory.create_client( |
| 172 | db_type=data_source_type.name, # Assuming MySQL for example |
| 173 | host=params.get("host"), |
| 174 | port=params.get("port"), |
| 175 | username=params.get("username"), |
| 176 | password=params.get("password"), |
| 177 | database=params.get("database"), |
| 178 | extra_params=params.get("params", {}) |
| 179 | ) |
| 180 | |
| 181 | try: |
| 182 | |
| 183 | data_list = JdbcClientFactory.run_query(jdbc_client, sql) |
| 184 | return self.response_format(data=data_list) |
| 185 | |
| 186 | except DAONotFound as ex: |
| 187 | logger.exception(ex) |
| 188 | return self.handle_error(SolidUIErrorType.QUERY_METADATA_SQL_ERROR) |
| 189 | |
| 190 | @expose('/querySql/id', methods=("GET",)) |
| 191 | @safe |
nothing calls this directly
no test coverage detected