Exemplo n.º 1
0
    def _parse_sql_statements(cls, migration_sql):
        all_statements = []
        last_statement = ''
        
        for statement in migration_sql.split(';'):
            if len(last_statement) > 0:
                curr_statement = '%s;%s' % (last_statement, statement)
            else:
                curr_statement = statement
            
            normalized_statement = Utils.normalize_sql(curr_statement)
            
            count = Utils.count_occurrences(normalized_statement)
            single_quotes = count.get("'", 0)
            double_quotes = count.get('"', 0)
            left_parenthesis = count.get('(', 0)
            right_parenthesis = count.get(')', 0)

            if single_quotes % 2 == 0 and double_quotes % 2 == 0 and left_parenthesis == right_parenthesis:
                all_statements.append(curr_statement)
                last_statement = ''
            else:
                last_statement = curr_statement

        return [s.strip() for s in all_statements if ((s.strip() != "") and (last_statement == ""))]
Exemplo n.º 2
0
    def _parse_sql_statements(cls, migration_sql):
        all_statements = []
        last_statement = ''

        for statement in migration_sql.split(';'):
            if len(last_statement) > 0:
                curr_statement = '%s;%s' % (last_statement, statement)
            else:
                curr_statement = statement

            count = Utils.count_occurrences(curr_statement)
            single_quotes = count.get("'", 0)
            double_quotes = count.get('"', 0)
            left_parenthesis = count.get('(', 0)
            right_parenthesis = count.get(')', 0)

            if single_quotes % 2 == 0 and double_quotes % 2 == 0 and left_parenthesis == right_parenthesis:
                all_statements.append(curr_statement)
                last_statement = ''
            else:
                last_statement = curr_statement

        return [
            s.strip() for s in all_statements
            if ((s.strip() != "") and (last_statement == ""))
        ]
Exemplo n.º 3
0
    def _parse_sql_statements(cls, migration_sql):
        all_statements = []
        last_statement = ''

        match_stmt = MySQL.__re_objects.match(migration_sql)

        if match_stmt and match_stmt.re.groups > 0:
            if match_stmt.group('pre'):
                all_statements = all_statements + MySQL._parse_sql_statements(match_stmt.group('pre'))
            if match_stmt.group('main'):
                all_statements.append(match_stmt.group('main'))
            if match_stmt.group('pos'):
                all_statements = all_statements + MySQL._parse_sql_statements(match_stmt.group('pos'))

        else:
            for statement in migration_sql.split(';'):
                if len(last_statement) > 0:
                    curr_statement = '%s;%s' % (last_statement, statement)
                else:
                    curr_statement = statement

                count = Utils.count_occurrences(curr_statement)
                single_quotes = count.get("'", 0)
                double_quotes = count.get('"', 0)
                left_parenthesis = count.get('(', 0)
                right_parenthesis = count.get(')', 0)

                if single_quotes % 2 == 0 and double_quotes % 2 == 0 and left_parenthesis == right_parenthesis:
                    all_statements.append(curr_statement)
                    last_statement = ''
                else:
                    last_statement = curr_statement

        return [s.strip() for s in all_statements if ((s.strip() != "") and (last_statement == ""))]
Exemplo n.º 4
0
    def _parse_sql_statements(cls, migration_sql):
        all_statements = []
        last_statement = ''

        match_stmt = MySQL.__re_objects.match(migration_sql)

        if match_stmt and match_stmt.re.groups > 0:
            if match_stmt.group('pre'):
                all_statements = all_statements + MySQL._parse_sql_statements(match_stmt.group('pre'))
            if match_stmt.group('main'):
                all_statements.append(match_stmt.group('main'))
            if match_stmt.group('pos'):
                all_statements = all_statements + MySQL._parse_sql_statements(match_stmt.group('pos'))

        else:
            for statement in migration_sql.split(';'):
                if len(last_statement) > 0:
                    curr_statement = '%s;%s' % (last_statement, statement)
                else:
                    curr_statement = statement

                count = Utils.count_occurrences(curr_statement)
                single_quotes = count.get("'", 0)
                double_quotes = count.get('"', 0)
                left_parenthesis = count.get('(', 0)
                right_parenthesis = count.get(')', 0)

                if single_quotes % 2 == 0 and double_quotes % 2 == 0 and left_parenthesis == right_parenthesis:
                    all_statements.append(curr_statement)
                    last_statement = ''
                else:
                    last_statement = curr_statement

        return [s.strip() for s in all_statements if ((s.strip() != "") and (last_statement == ""))]
Exemplo n.º 5
0
    def _parse_sql_statements(self, migration_sql):
        all_statements = []
        last_statement = ""

        # remove comments
        migration_sql = Oracle.__re_comments_multi_line.sub("\g<pre>", migration_sql)
        migration_sql = Oracle.__re_comments_single_line.sub("\g<pre>", migration_sql)

        match_stmt = Oracle.__re_objects.match(migration_sql)
        if not match_stmt:
            match_stmt = Oracle.__re_anonymous.match(migration_sql)

        if match_stmt and match_stmt.re.groups > 0:
            if match_stmt.group("pre"):
                all_statements = all_statements + Oracle._parse_sql_statements(match_stmt.group("pre"))
            if match_stmt.group("principal"):
                all_statements.append(match_stmt.group("principal"))
            if match_stmt.group("pos"):
                all_statements = all_statements + Oracle._parse_sql_statements(match_stmt.group("pos"))

        else:
            for statement in migration_sql.split(";"):
                if len(last_statement) > 0:
                    curr_statement = "%s;%s" % (last_statement, statement)
                else:
                    curr_statement = statement

                count = Utils.count_occurrences(curr_statement)
                single_quotes = count.get("'", 0)
                double_quotes = count.get('"', 0)
                left_parenthesis = count.get("(", 0)
                right_parenthesis = count.get(")", 0)

                if single_quotes % 2 == 0 and double_quotes % 2 == 0 and left_parenthesis == right_parenthesis:
                    all_statements.append(curr_statement)
                    last_statement = ""
                else:
                    last_statement = curr_statement

        return [s.strip() for s in all_statements if ((s.strip() != "") and (last_statement == ""))]
Exemplo n.º 6
0
    def _parse_sql_statements(self, migration_sql):
        all_statements = []
        last_statement = ''

        #remove comments
        migration_sql = Oracle.__re_comments_multi_line.sub("\g<pre>", migration_sql)
        migration_sql = Oracle.__re_comments_single_line.sub("\g<pre>", migration_sql)

        match_stmt = Oracle.__re_objects.match(migration_sql)
        if not match_stmt:
            match_stmt = Oracle.__re_anonymous.match(migration_sql)

        if match_stmt and match_stmt.re.groups > 0:
            if match_stmt.group('pre'):
                all_statements = all_statements + Oracle._parse_sql_statements(match_stmt.group('pre'))
            if match_stmt.group('principal'):
                all_statements.append(match_stmt.group('principal'))
            if match_stmt.group('pos'):
                all_statements = all_statements + Oracle._parse_sql_statements(match_stmt.group('pos'))

        else:
            for statement in migration_sql.split(';'):
                if len(last_statement) > 0:
                    curr_statement = '%s;%s' % (last_statement, statement)
                else:
                    curr_statement = statement

                count = Utils.count_occurrences(curr_statement)
                single_quotes = count.get("'", 0)
                double_quotes = count.get('"', 0)
                left_parenthesis = count.get('(', 0)
                right_parenthesis = count.get(')', 0)

                if single_quotes % 2 == 0 and double_quotes % 2 == 0 and left_parenthesis == right_parenthesis:
                    all_statements.append(curr_statement)
                    last_statement = ''
                else:
                    last_statement = curr_statement

        return [s.strip() for s in all_statements if ((s.strip() != "") and (last_statement == ""))]
Exemplo n.º 7
0
    def _parse_sql_statements(cls, migration_sql):
        all_statements = []
        last_statement = ""

        for statement in migration_sql.split(";"):
            if len(last_statement) > 0:
                curr_statement = "%s;%s" % (last_statement, statement)
            else:
                curr_statement = statement

            count = Utils.count_occurrences(curr_statement)
            single_quotes = count.get("'", 0)
            double_quotes = count.get('"', 0)
            left_parenthesis = count.get("(", 0)
            right_parenthesis = count.get(")", 0)

            if single_quotes % 2 == 0 and double_quotes % 2 == 0 and left_parenthesis == right_parenthesis:
                all_statements.append(curr_statement)
                last_statement = ""
            else:
                last_statement = curr_statement

        return [s.strip() for s in all_statements if s.strip() != ""]