Search in sources :

Example 6 with SQLParsingException

use of io.seata.sqlparser.SQLParsingException in project seata by seata.

the class MySQLUpdateRecognizer method getUpdateColumns.

@Override
public List<String> getUpdateColumns() {
    List<SQLUpdateSetItem> updateSetItems = ast.getItems();
    List<String> list = new ArrayList<>(updateSetItems.size());
    for (SQLUpdateSetItem updateSetItem : updateSetItems) {
        SQLExpr expr = updateSetItem.getColumn();
        if (expr instanceof SQLIdentifierExpr) {
            list.add(((SQLIdentifierExpr) expr).getName());
        } else if (expr instanceof SQLPropertyExpr) {
            // This is alias case, like UPDATE xxx_tbl a SET a.name = ? WHERE a.id = ?
            SQLExpr owner = ((SQLPropertyExpr) expr).getOwner();
            if (owner instanceof SQLIdentifierExpr) {
                list.add(((SQLIdentifierExpr) owner).getName() + "." + ((SQLPropertyExpr) expr).getName());
            // This is table Field Full path, like update xxx_database.xxx_tbl set xxx_database.xxx_tbl.xxx_field...
            } else if (((SQLPropertyExpr) expr).getOwnernName().split("\\.").length > 1) {
                list.add(((SQLPropertyExpr) expr).getOwnernName() + "." + ((SQLPropertyExpr) expr).getName());
            }
        } else {
            throw new SQLParsingException("Unknown SQLExpr: " + expr.getClass() + " " + expr);
        }
    }
    return list;
}
Also used : SQLUpdateSetItem(com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem) SQLParsingException(io.seata.sqlparser.SQLParsingException) ArrayList(java.util.ArrayList) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 7 with SQLParsingException

use of io.seata.sqlparser.SQLParsingException in project seata by seata.

the class OracleUpdateRecognizer method getUpdateColumns.

@Override
public List<String> getUpdateColumns() {
    List<SQLUpdateSetItem> updateSetItems = ast.getItems();
    List<String> list = new ArrayList<>(updateSetItems.size());
    for (SQLUpdateSetItem updateSetItem : updateSetItems) {
        SQLExpr expr = updateSetItem.getColumn();
        if (expr instanceof SQLIdentifierExpr) {
            list.add(((SQLIdentifierExpr) expr).getName());
        } else if (expr instanceof SQLPropertyExpr) {
            // This is alias case, like UPDATE xxx_tbl a SET a.name = ? WHERE a.id = ?
            SQLExpr owner = ((SQLPropertyExpr) expr).getOwner();
            if (owner instanceof SQLIdentifierExpr) {
                list.add(((SQLIdentifierExpr) owner).getName() + "." + ((SQLPropertyExpr) expr).getName());
            // This is table Field Full path, like update xxx_database.xxx_tbl set xxx_database.xxx_tbl.xxx_field...
            } else if (((SQLPropertyExpr) expr).getOwnernName().split("\\.").length > 1) {
                list.add(((SQLPropertyExpr) expr).getOwnernName() + "." + ((SQLPropertyExpr) expr).getName());
            }
        } else {
            throw new SQLParsingException("Unknown SQLExpr: " + expr.getClass() + " " + expr);
        }
    }
    return list;
}
Also used : SQLUpdateSetItem(com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem) SQLParsingException(io.seata.sqlparser.SQLParsingException) ArrayList(java.util.ArrayList) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 8 with SQLParsingException

use of io.seata.sqlparser.SQLParsingException in project seata by seata.

the class OracleUpdateRecognizer method getUpdateValues.

@Override
public List<Object> getUpdateValues() {
    List<SQLUpdateSetItem> updateSetItems = ast.getItems();
    List<Object> list = new ArrayList<>(updateSetItems.size());
    for (SQLUpdateSetItem updateSetItem : updateSetItems) {
        SQLExpr expr = updateSetItem.getValue();
        if (expr instanceof SQLValuableExpr) {
            list.add(((SQLValuableExpr) expr).getValue());
        } else if (expr instanceof SQLVariantRefExpr) {
            list.add(new VMarker());
        } else {
            throw new SQLParsingException("Unknown SQLExpr: " + expr.getClass() + " " + expr);
        }
    }
    return list;
}
Also used : SQLUpdateSetItem(com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem) SQLParsingException(io.seata.sqlparser.SQLParsingException) ArrayList(java.util.ArrayList) SQLVariantRefExpr(com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) SQLValuableExpr(com.alibaba.druid.sql.ast.expr.SQLValuableExpr)

Example 9 with SQLParsingException

use of io.seata.sqlparser.SQLParsingException in project seata by seata.

the class PostgresqlUpdateRecognizer method getUpdateColumns.

@Override
public List<String> getUpdateColumns() {
    List<SQLUpdateSetItem> updateSetItems = ast.getItems();
    List<String> list = new ArrayList<>(updateSetItems.size());
    for (SQLUpdateSetItem updateSetItem : updateSetItems) {
        SQLExpr expr = updateSetItem.getColumn();
        if (expr instanceof SQLIdentifierExpr) {
            list.add(((SQLIdentifierExpr) expr).getName());
        } else if (expr instanceof SQLPropertyExpr) {
            // This is alias case, like UPDATE xxx_tbl a SET a.name = ? WHERE a.id = ?
            SQLExpr owner = ((SQLPropertyExpr) expr).getOwner();
            if (owner instanceof SQLIdentifierExpr) {
                list.add(((SQLIdentifierExpr) owner).getName() + "." + ((SQLPropertyExpr) expr).getName());
            // This is table Field Full path, like update xxx_database.xxx_tbl set xxx_database.xxx_tbl.xxx_field...
            } else if (((SQLPropertyExpr) expr).getOwnernName().split("\\.").length > 1) {
                list.add(((SQLPropertyExpr) expr).getOwnernName() + "." + ((SQLPropertyExpr) expr).getName());
            }
        } else {
            throw new SQLParsingException("Unknown SQLExpr: " + expr.getClass() + " " + expr);
        }
    }
    return list;
}
Also used : SQLUpdateSetItem(com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem) SQLParsingException(io.seata.sqlparser.SQLParsingException) ArrayList(java.util.ArrayList) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 10 with SQLParsingException

use of io.seata.sqlparser.SQLParsingException in project seata by seata.

the class MySQLInsertRecognizer method getInsertColumns.

@Override
public List<String> getInsertColumns() {
    List<SQLExpr> columnSQLExprs = ast.getColumns();
    if (columnSQLExprs.isEmpty()) {
        // INSERT INTO ta VALUES (...), without fields clarified
        return null;
    }
    List<String> list = new ArrayList<>(columnSQLExprs.size());
    for (SQLExpr expr : columnSQLExprs) {
        if (expr instanceof SQLIdentifierExpr) {
            list.add(((SQLIdentifierExpr) expr).getName());
        } else {
            throw new SQLParsingException("Unknown SQLExpr: " + expr.getClass() + " " + expr);
        }
    }
    return list;
}
Also used : SQLParsingException(io.seata.sqlparser.SQLParsingException) ArrayList(java.util.ArrayList) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Aggregations

SQLParsingException (io.seata.sqlparser.SQLParsingException)17 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)12 ArrayList (java.util.ArrayList)12 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)6 SQLValuableExpr (com.alibaba.druid.sql.ast.expr.SQLValuableExpr)6 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)6 SQLUpdateSetItem (com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem)6 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)3 SQLNullExpr (com.alibaba.druid.sql.ast.expr.SQLNullExpr)3 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)3 SQLInsertStatement (com.alibaba.druid.sql.ast.statement.SQLInsertStatement)3 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)3 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)3 List (java.util.List)3 SQLSequenceExpr (com.alibaba.druid.sql.ast.expr.SQLSequenceExpr)2 SqlSequenceExpr (io.seata.sqlparser.struct.SqlSequenceExpr)2 SQLDefaultExpr (com.alibaba.druid.sql.ast.expr.SQLDefaultExpr)1