MCPcopy
hub / github.com/spaceandtimefdn/SxT-Python-SDK / sql_exec

Method sql_exec

src/spaceandtime/sxtbaseapi.py:582–610  ·  view source on GitHub ↗

-------------------- Executes a database statement/query of arbitrary type (DML, DDL, DQL), and returns a status or data. Calls and returns data from API: sql, which runs arbitrary SQL and returns records (if any). This api call undergoes one additional SQL parse step to int

(self, sql_text:str, biscuits:list = None, app_name:str = None, validate:bool = False)

Source from the content-addressed store, hash-verified

580
581
582 def sql_exec(self, sql_text:str, biscuits:list = None, app_name:str = None, validate:bool = False):
583 """--------------------
584 Executes a database statement/query of arbitrary type (DML, DDL, DQL), and returns a status or data.
585
586 Calls and returns data from API: sql, which runs arbitrary SQL and returns records (if any).
587 This api call undergoes one additional SQL parse step to interrogate the type and
588 affected tables / views, so is slightly less performant (by 50-100ms) than the type-specific
589 api calls, sql_ddl, sql_dml, sql_dql. Normal human interaction will not be noticed, but
590 if tuning for high-performance applications, consider using the correct typed call.
591
592 Args:
593 sql_text (str): SQL query text to execute. Note, there is NO placeholder replacement.
594 biscuits (list): (optional) List of biscuit tokens for permissioned tables. If only querying public tables, this is not needed.
595 app_name (str): (optional) Name that will appear in querylog, used for bucketing workload.
596 validate (bool): (optional) Perform an additional SQL validation in-parser, before database submission.
597
598 Returns:
599 bool: Success flag (True/False) indicating the api call worked as expected.
600 object: Response information from the Space and Time network, as list or dict(json).
601 """
602 headers = { 'originApp': app_name } if app_name else {}
603 sql_text = self.prep_sql(sql_text=sql_text)
604 biscuit_tokens = self.prep_biscuits(biscuits)
605 if type(biscuit_tokens) != list: raise SxTArgumentError("sql_all requires parameter 'biscuits' to be a list of biscuit_tokens or SXTBiscuit objects.", logger = self.logger)
606 dataparms = {"sqlText": sql_text
607 ,"biscuits": biscuit_tokens
608 ,"validate": str(validate).lower() }
609 success, rtn = self.call_api('sql', True, header_parms=headers, data_parms=dataparms)
610 return success, rtn if success else [rtn]
611
612
613 def sql_ddl(self, sql_text:str, biscuits:list = None, app_name:str = None):

Callers 5

sql_ddlMethod · 0.95
sql_dmlMethod · 0.95
sql_dqlMethod · 0.95
execute_queryMethod · 0.80
execute_queryMethod · 0.80

Calls 4

prep_sqlMethod · 0.95
prep_biscuitsMethod · 0.95
call_apiMethod · 0.95
SxTArgumentErrorClass · 0.90

Tested by

no test coverage detected