Search in sources :

Example 76 with SQLIdentifierExpr

use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.

the class OracleSelectJoin method setLeft.

public void setLeft(String tableName) {
    SQLExprTableSource tableSource;
    if (tableName == null || tableName.length() == 0) {
        tableSource = null;
    } else {
        tableSource = new OracleSelectTableReference(new SQLIdentifierExpr(tableName));
    }
    this.setLeft(tableSource);
}
Also used : SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource)

Example 77 with SQLIdentifierExpr

use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.

the class Schema method findTable.

public SchemaObject findTable(SQLTableSource tableSource, String alias) {
    if (tableSource instanceof SQLExprTableSource) {
        if (StringUtils.equalsIgnoreCase(alias, tableSource.computeAlias())) {
            SQLExprTableSource exprTableSource = (SQLExprTableSource) tableSource;
            SchemaObject tableObject = exprTableSource.getSchemaObject();
            if (tableObject != null) {
                return tableObject;
            }
            SQLExpr expr = exprTableSource.getExpr();
            if (expr instanceof SQLIdentifierExpr) {
                long tableNameHashCode64 = ((SQLIdentifierExpr) expr).nameHashCode64();
                tableObject = findTable(tableNameHashCode64);
                if (tableObject != null) {
                    exprTableSource.setSchemaObject(tableObject);
                }
                return tableObject;
            }
            if (expr instanceof SQLPropertyExpr) {
                long tableNameHashCode64 = ((SQLPropertyExpr) expr).nameHashCode64();
                tableObject = findTable(tableNameHashCode64);
                if (tableObject != null) {
                    exprTableSource.setSchemaObject(tableObject);
                }
                return tableObject;
            }
        }
        return null;
    }
    if (tableSource instanceof SQLJoinTableSource) {
        SQLJoinTableSource join = (SQLJoinTableSource) tableSource;
        SQLTableSource left = join.getLeft();
        SchemaObject tableObject = findTable(left, alias);
        if (tableObject != null) {
            return tableObject;
        }
        SQLTableSource right = join.getRight();
        tableObject = findTable(right, alias);
        return tableObject;
    }
    return null;
}
Also used : SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 78 with SQLIdentifierExpr

use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.

the class Schema method findTable.

public SchemaObject findTable(SQLTableSource tableSource, SQLExpr expr) {
    if (expr instanceof SQLAggregateExpr) {
        SQLAggregateExpr aggregateExpr = (SQLAggregateExpr) expr;
        String function = aggregateExpr.getMethodName();
        if ("min".equalsIgnoreCase(function) || "max".equalsIgnoreCase(function)) {
            SQLExpr arg = aggregateExpr.getArguments().get(0);
            return findTable(tableSource, arg);
        }
    }
    if (expr instanceof SQLPropertyExpr) {
        String ownerName = ((SQLPropertyExpr) expr).getOwnernName();
        return findTable(tableSource, ownerName);
    }
    if (expr instanceof SQLAllColumnExpr || expr instanceof SQLIdentifierExpr) {
        if (tableSource instanceof SQLExprTableSource) {
            return findTable(tableSource, tableSource.computeAlias());
        }
        if (tableSource instanceof SQLJoinTableSource) {
            SQLJoinTableSource join = (SQLJoinTableSource) tableSource;
            SchemaObject table = findTable(join.getLeft(), expr);
            if (table == null) {
                table = findTable(join.getRight(), expr);
            }
            return table;
        }
        return null;
    }
    return null;
}
Also used : SQLAllColumnExpr(com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLAggregateExpr(com.alibaba.druid.sql.ast.expr.SQLAggregateExpr) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 79 with SQLIdentifierExpr

use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.

the class SQLRefactorVisitor method visit.

public boolean visit(SQLExprTableSource x) {
    TableMapping mapping = findMapping(x);
    if (mapping == null) {
        return true;
    }
    String destTable = mapping.getDestTable();
    x.setExpr(new SQLIdentifierExpr(quote(destTable)));
    return false;
}
Also used : SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)

Example 80 with SQLIdentifierExpr

use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.

the class MySqlAlterTableTest_40_change method isRenameColumn.

public boolean isRenameColumn(SQLAlterTableStatement stmt) {
    for (SQLAlterTableItem item : stmt.getItems()) {
        if (item instanceof MySqlAlterTableChangeColumn) {
            MySqlAlterTableChangeColumn changeColumn = (MySqlAlterTableChangeColumn) item;
            SQLIdentifierExpr columnName = (SQLIdentifierExpr) changeColumn.getColumnName();
            String newColumnName = changeColumn.getNewColumnDefinition().getColumnName();
            if (!columnName.nameEquals(newColumnName)) {
                return true;
            }
        }
        if (item instanceof SQLAlterTableRenameColumn) {
            return true;
        }
    }
    return false;
}
Also used : SQLAlterTableItem(com.alibaba.druid.sql.ast.statement.SQLAlterTableItem) SQLAlterTableRenameColumn(com.alibaba.druid.sql.ast.statement.SQLAlterTableRenameColumn) MySqlAlterTableChangeColumn(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableChangeColumn) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)

Aggregations

SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)152 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)68 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)45 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)19 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)18 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)17 SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)16 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)16 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)15 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)15 SQLAggregateExpr (com.alibaba.druid.sql.ast.expr.SQLAggregateExpr)14 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)13 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)11 SQLAssignItem (com.alibaba.druid.sql.ast.statement.SQLAssignItem)11 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)10 SQLColumnDefinition (com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)10 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)10 SQLAllColumnExpr (com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr)9 ArrayList (java.util.ArrayList)9 SQLName (com.alibaba.druid.sql.ast.SQLName)8