Giter Site home page Giter Site logo

Comments (4)

windiana42 avatar windiana42 commented on September 25, 2024

I already located the problem near tsql.py:115:

        if isinstance(node, tsqlParser.Declare_statementContext):
            self.dynamics.extend(result)

from pytsql.

windiana42 avatar windiana42 commented on September 25, 2024

Here is a failing testcase: 58a61a7

from pytsql.

windiana42 avatar windiana42 commented on September 25, 2024

I am trying to reliably detect whether DECLARE is a top level statement. My current hypothesis is: a DECLARE statement is top level if the chain of parentCtx to the root (BatchContext) only includes Sql_clauseContext or Sql_clausesContext objects.

    @staticmethod
    def is_top_level_statement(node: ParserRuleContext):
        """Check wether node is a top level SQL statement."""
        cur = node.parentCtx
        while isinstance(cur, tsqlParser.Sql_clauseContext) or isinstance(cur, tsqlParser.Sql_clausesContext):
            cur = cur.parentCtx
        return isinstance(cur, tsqlParser.BatchContext)

from pytsql.

windiana42 avatar windiana42 commented on September 25, 2024

Why is the expectation that this SQL code should result in @declare statement to be unconditionally copied?

def test_declaration_in_control_flow():
        seed = """
        IF 1 = 1
            DECLARE @A INT = 5
        SELECT * FROM x

If it is, we might have to parse the IF statement outcome:

        IF 1 = 0
            DECLARE @A INT = 5
        GO
        SELECT @A

The second with GO actually does not work in TSQL either. But this does:

DECLARE @A INT = 5
GO
SELECT @A

from pytsql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.