예제 #1
0
        internal void close()
        {
            // Nothing to do if the session is not open
            if (null == sessionToken)
            {
                return;
            }

            // Send a close session request
            var queryParams = new Dictionary <string, string>();

            queryParams[RestParams.SF_QUERY_SESSION_DELETE] = "true";
            queryParams[RestParams.SF_QUERY_REQUEST_ID]     = Guid.NewGuid().ToString();
            queryParams[RestParams.SF_QUERY_REQUEST_GUID]   = Guid.NewGuid().ToString();

            SFRestRequest closeSessionRequest = new SFRestRequest(InsecureMode)
            {
                Url = BuildUri(RestPath.SF_SESSION_PATH, queryParams),
                authorizationToken = string.Format(SF_AUTHORIZATION_SNOWFLAKE_FMT, sessionToken)
            };

            var response = restRequester.Post <CloseResponse>(closeSessionRequest);

            if (!response.success)
            {
                logger.Debug($"Failed to delete session, error ignored. Code: {response.code} Message: {response.message}");
            }
        }
        internal SFBaseResultSet Execute(int timeout, string sql, Dictionary <string, BindingDTO> bindings, bool describeOnly)
        {
            registerQueryCancellationCallback(timeout, CancellationToken.None);
            var queryRequest = BuildQueryRequest(sql, bindings, describeOnly);

            try
            {
                QueryExecResponse response      = null;
                bool receivedFirstQueryResponse = false;
                while (!receivedFirstQueryResponse)
                {
                    response = _restRequester.Post <QueryExecResponse>(queryRequest);
                    if (SessionExpired(response))
                    {
                        SfSession.renewSession();
                        queryRequest.authorizationToken = string.Format(SF_AUTHORIZATION_SNOWFLAKE_FMT, SfSession.sessionToken);
                    }
                    else
                    {
                        receivedFirstQueryResponse = true;
                    }
                }

                var lastResultUrl = response.data?.getResultUrl;
                while (RequestInProgress(response) || SessionExpired(response))
                {
                    var req = BuildResultRequest(lastResultUrl);
                    response = _restRequester.Get <QueryExecResponse>(req);

                    if (SessionExpired(response))
                    {
                        logger.Info("Ping pong request failed with session expired, trying to renew the session.");
                        SfSession.renewSession();
                    }
                    else
                    {
                        lastResultUrl = response.data?.getResultUrl;
                    }
                }

                return(BuildResultSet(response, CancellationToken.None));
            }
            catch (Exception ex)
            {
                logger.Error("Query execution failed.", ex);
                throw;
            }
            finally
            {
                ClearQueryRequestId();
            }
        }
예제 #3
0
        internal SFBaseResultSet Execute(int timeout, string sql, Dictionary <string, BindingDTO> bindings, bool describeOnly)
        {
            registerQueryCancellationCallback(timeout, CancellationToken.None);
            var queryRequest = BuildQueryRequest(sql, bindings, describeOnly);

            try
            {
                var response = _restRequester.Post <QueryExecResponse>(queryRequest);
                if (SessionExpired(response))
                {
                    SfSession.renewSession();
                    ClearQueryRequestId();
                    return(Execute(timeout, sql, bindings, describeOnly));
                }

                var lastResultUrl = response.data?.getResultUrl;
                while (RequestInProgress(response) || SessionExpired(response))
                {
                    var req = BuildResultRequest(lastResultUrl);
                    response = _restRequester.Get <QueryExecResponse>(req);

                    if (SessionExpired(response))
                    {
                        logger.Info("Ping pong request failed with session expired, trying to renew the session.");
                        SfSession.renewSession();
                    }
                    else
                    {
                        lastResultUrl = response.data?.getResultUrl;
                    }
                }

                return(BuildResultSet(response, CancellationToken.None));
            }
            catch (Exception ex)
            {
                logger.Error("Query execution failed.", ex);
                throw;
            }
            finally
            {
                ClearQueryRequestId();
            }
        }