Search in sources :

Example 11 with SQLParsingException

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

the class MySQLUpdateRecognizer 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 12 with SQLParsingException

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

the class PostgresqlUpdateRecognizer 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 13 with SQLParsingException

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

the class OracleInsertRecognizer method getInsertRows.

@Override
public List<List<Object>> getInsertRows(Collection<Integer> primaryKeyIndex) {
    List<SQLInsertStatement.ValuesClause> valuesClauses = ast.getValuesList();
    List<List<Object>> rows = new ArrayList<>(valuesClauses.size());
    for (SQLInsertStatement.ValuesClause valuesClause : valuesClauses) {
        List<SQLExpr> exprs = valuesClause.getValues();
        List<Object> row = new ArrayList<>(exprs.size());
        rows.add(row);
        for (int i = 0, len = exprs.size(); i < len; i++) {
            SQLExpr expr = exprs.get(i);
            if (expr instanceof SQLNullExpr) {
                row.add(Null.get());
            } else if (expr instanceof SQLValuableExpr) {
                row.add(((SQLValuableExpr) expr).getValue());
            } else if (expr instanceof SQLVariantRefExpr) {
                row.add(((SQLVariantRefExpr) expr).getName());
            } else if (expr instanceof SQLMethodInvokeExpr) {
                row.add(SqlMethodExpr.get());
            } else if (expr instanceof SQLSequenceExpr) {
                SQLSequenceExpr sequenceExpr = (SQLSequenceExpr) expr;
                String sequence = sequenceExpr.getSequence().getSimpleName();
                String function = sequenceExpr.getFunction().name;
                row.add(new SqlSequenceExpr(sequence, function));
            } else {
                if (primaryKeyIndex.contains(i)) {
                    throw new SQLParsingException("Unknown SQLExpr: " + expr.getClass() + " " + expr);
                }
                row.add(NotPlaceholderExpr.get());
            }
        }
    }
    return rows;
}
Also used : SQLMethodInvokeExpr(com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr) ArrayList(java.util.ArrayList) SQLNullExpr(com.alibaba.druid.sql.ast.expr.SQLNullExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) SQLValuableExpr(com.alibaba.druid.sql.ast.expr.SQLValuableExpr) SQLParsingException(io.seata.sqlparser.SQLParsingException) SQLInsertStatement(com.alibaba.druid.sql.ast.statement.SQLInsertStatement) SQLVariantRefExpr(com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr) ArrayList(java.util.ArrayList) List(java.util.List) SQLSequenceExpr(com.alibaba.druid.sql.ast.expr.SQLSequenceExpr) SqlSequenceExpr(io.seata.sqlparser.struct.SqlSequenceExpr)

Example 14 with SQLParsingException

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

the class OracleSelectForUpdateRecognizer method getSelect.

private SQLSelectQueryBlock getSelect() {
    SQLSelect select = ast.getSelect();
    if (select == null) {
        throw new SQLParsingException("should never happen!");
    }
    SQLSelectQueryBlock selectQueryBlock = select.getQueryBlock();
    if (selectQueryBlock == null) {
        throw new SQLParsingException("should never happen!");
    }
    return selectQueryBlock;
}
Also used : SQLParsingException(io.seata.sqlparser.SQLParsingException) SQLSelect(com.alibaba.druid.sql.ast.statement.SQLSelect) SQLSelectQueryBlock(com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)

Example 15 with SQLParsingException

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

the class PostgresqlInsertRecognizer method getInsertColumns.

@Override
public List<String> getInsertColumns() {
    List<SQLExpr> columnSQLExprs = ast.getColumns();
    if (columnSQLExprs.size() == 0) {
        // 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