Use explicit sessions when a transaction needs to span multiple requests or when using volatile tables. These sessions are only reused if you reference the sessions in a query request. The request is queued if a request references an explicit session already in use.
-
Create a session Send a POST request to the
/system/<SYSTEM_NAME>/sessionsendpoint. The request creates a new database session and returns the session details as the response.In the following example, the request includes
'auto_commit': True- the request to commit the query upon completion.Request
# first create a session url = 'https://<QS_HOSTNAME>:1443/systems/<SYSTEM_NAME>/sessions' payload = { 'auto_commit': True } payload_json = json.dumps(payload) response = requests.request('POST', url, headers=headers, data=payload_json, verify=False) print(response.text)Response
{ 'sessionId': 1366010, 'system': 'testsystem', 'user': 'dbc', 'tdSessionNo': 1626922, 'createMode': 'EXPLICIT', 'state': 'LOGGINGON', 'autoCommit': true } -
Use the session created in Step 1 to submit queries
Send a POST request to the
/system/<SYSTEM_NAME>/queriesendpoint.The request submits queries to the target system and returns the release and version number of the target system.
In the following example, the request includes: *
SELECT * FROM DBC.DBCInfo: The query to the system with the alias<SYSTEM_NAME>. *'format': 'OBJECT': The format for response. *'Session' : <Session ID>: The session ID returned in Step 1 to create an explicit session.Request
# use this session to submit queries afterwards url = 'https://<QS_HOSTNAME>:1443/systems/<SYSTEM_NAME>/queries' payload = { 'query': 'SELECT * FROM DBC.DBCInfo;', 'format': 'OBJECT', 'session': 1366010 # <-- sessionId } payload_json = json.dumps(payload) response = requests.request('POST', url, headers=headers, data=payload_json, verify=False) print(response.text)Response
{ "queueDuration":6, "queryDuration":41, "results":[ { "resultSet":true, "data":[ { "InfoKey":"LANGUAGE SUPPORT MODE", "InfoData":"Standard" }, { "InfoKey":"RELEASE", "InfoData":"15.10.07.02" }, { "InfoKey":"VERSION", "InfoData":"15.10.07.02" } ], "rowCount":3, "rowLimitExceeded":false } ] }