Beispiel #1
0
        // Internal for testing purposes
        internal string GetSqlText(ExecuteRequestParamsBase request)
        {
            // If it is a document selection, we'll retrieve the text from the document
            ExecuteDocumentSelectionParams docRequest = request as ExecuteDocumentSelectionParams;

            if (docRequest != null)
            {
                return(GetSqlTextFromSelectionData(docRequest.OwnerUri, docRequest.QuerySelection));
            }

            // If it is a document statement, we'll retrieve the text from the document
            ExecuteDocumentStatementParams stmtRequest = request as ExecuteDocumentStatementParams;

            if (stmtRequest != null)
            {
                return(GetSqlStatementAtPosition(stmtRequest.OwnerUri, stmtRequest.Line, stmtRequest.Column));
            }

            // If it is an ExecuteStringParams, return the text as is
            ExecuteStringParams stringRequest = request as ExecuteStringParams;

            if (stringRequest != null)
            {
                return(stringRequest.Query);
            }

            // Note, this shouldn't be possible due to inheritance rules
            throw new InvalidCastException("Invalid request type");
        }
        public void ExecuteDocumentStatementTest()
        {
            string query            = string.Format("{0}{1}GO{1}{0}", Constants.StandardQuery, Environment.NewLine);
            var    workspaceService = GetDefaultWorkspaceService(query);
            var    queryService     = new QueryExecutionService(null, workspaceService);

            var queryParams = new ExecuteDocumentStatementParams {
                OwnerUri = Constants.OwnerUri, Line = 0, Column = 0
            };
            var queryText = queryService.GetSqlText(queryParams);

            // The text should match the standard query
            Assert.Equal(queryText, Constants.StandardQuery);
        }
        private void ExecuteDocumentStatementSameLineHelper(string statement1, string statement2, int cursorColumn, string expectedQueryText)
        {
            string query            = string.Format("{0};{1}", statement1, statement2);
            var    workspaceService = GetDefaultWorkspaceService(query);
            var    queryService     = new QueryExecutionService(null, workspaceService);

            // If a line has multiple statements and the cursor is somewhere in the line
            var queryParams = new ExecuteDocumentStatementParams {
                OwnerUri = Constants.OwnerUri, Line = 0, Column = cursorColumn
            };
            var queryText = queryService.GetSqlText(queryParams);

            // The query text should match the expected statement at the cursor
            Assert.Equal(expectedQueryText, queryText);
        }