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();
            }
        }
Exemple #2
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();
            }
        }