MCPcopy Create free account
hub / github.com/CloudOrc/SolidUI / query_sql_by_id

Method query_sql_by_id

solidui/views/metadata/api.py:192–227  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 8

get_data_source_idMethod · 0.80
handle_errorMethod · 0.80
get_idMethod · 0.80
create_clientMethod · 0.80
exceptionMethod · 0.80
getMethod · 0.45
run_queryMethod · 0.45
response_formatMethod · 0.45

Tested by

no test coverage detected