Python sqlparse.tokens.DDL() Examples

The following are code examples for showing how to use sqlparse.tokens.DDL(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: DbDeo   Author: tushartushar   File: SQLParse.py    MIT License 6 votes vote down vote up
def knowStmtType(self):
        create_seen = False
        for token in self.parsed:
            if token.ttype is DML and token.value.upper() == 'SELECT':
                return SQLStmtType.SELECT
            if token.ttype is DDL and token.value.upper() == 'CREATE':
                create_seen = True
                continue
            if token.ttype is Keyword and token.value.upper() == 'TABLE' and create_seen:
                return SQLStmtType.CREATE
            if token.ttype is Keyword and token.value.upper() == 'INDEX' and create_seen:
                return SQLStmtType.CREATE_INDEX
            if token.ttype is DML and token.value.upper() == 'INSERT':
                return SQLStmtType.INSERT
            if token.ttype is DML and token.value.upper() == 'UPDATE':
                return SQLStmtType.UPDATE
        return SQLStmtType.DEFAULT 
Example 2
Project: xuemc   Author: skycucumber   File: grouping.py    GNU General Public License v2.0 5 votes vote down vote up
def group_as(tlist):

    def _right_valid(token):
        # Currently limited to DML/DDL. Maybe additional more non SQL reserved
        # keywords should appear here (see issue8).
        return not token.ttype in (T.DML, T.DDL)

    def _left_valid(token):
        if token.ttype is T.Keyword and token.value in ('NULL',):
            return True
        return token.ttype is not T.Keyword

    _group_left_right(tlist, T.Keyword, 'AS', sql.Identifier,
                      check_right=_right_valid,
                      check_left=_left_valid) 
Example 3
Project: Sublime-uroboroSQL-formatter   Author: future-architect   File: grouping.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def group_as(tlist):

    def _right_valid(token):
        # Currently limited to DML/DDL. Maybe additional more non SQL reserved
        # keywords should appear here (see issue8).
        return not token.ttype in (T.DML, T.DDL)

    def _left_valid(token):
        if token.ttype is T.Keyword and token.value in ('NULL',):
            return True
        return token.ttype is not T.Keyword

    _group_left_right(tlist, T.Keyword, 'AS', sql.Identifier,
                      check_right=_right_valid,
                      check_left=_left_valid) 
Example 4
Project: codenn   Author: sriniiyer   File: grouping.py    MIT License 5 votes vote down vote up
def group_as(tlist):

    def _right_valid(token):
        # Currently limited to DML/DDL. Maybe additional more non SQL reserved
        # keywords should appear here (see issue8).
        return not token.ttype in (T.DML, T.DDL)

    def _left_valid(token):
        if token.ttype is T.Keyword and token.value in ('NULL',):
            return True
        return token.ttype is not T.Keyword

    _group_left_right(tlist, T.Keyword, 'AS', sql.Identifier,
                      check_right=_right_valid,
                      check_left=_left_valid) 
Example 5
Project: uroboroSQL-formatter   Author: future-architect   File: grouping.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def group_as(tlist):

    def _right_valid(token):
        # Currently limited to DML/DDL. Maybe additional more non SQL reserved
        # keywords should appear here (see issue8).
        return not token.ttype in (T.DML, T.DDL)

    def _left_valid(token):
        if token.ttype is T.Keyword and token.value in ('NULL',):
            return True
        return token.ttype is not T.Keyword

    _group_left_right(tlist, T.Keyword, 'AS', sql.Identifier,
                      check_right=_right_valid,
                      check_left=_left_valid)