Search in sources :

Example 6 with DMLStatement

use of io.shardingjdbc.core.parsing.parser.sql.dml.DMLStatement in project sharding-jdbc by shardingjdbc.

the class UpdateStatementParserTest method parseWithParameter.

@Test
public void parseWithParameter() {
    String sql = "UPDATE TABLE_XXX AS xxx SET field1=field1+? WHERE field4<? AND xxx.field1=? AND field5>? AND xxx.field2 IN (?, ?) AND field6<=? AND xxx.field3 BETWEEN ? AND ? AND field7>=?";
    ShardingRule shardingRule = createShardingRule();
    SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, sql, shardingRule);
    DMLStatement updateStatement = (DMLStatement) statementParser.parse();
    assertUpdateStatementWitParameter(updateStatement);
}
Also used : ShardingRule(io.shardingjdbc.core.rule.ShardingRule) SQLParsingEngine(io.shardingjdbc.core.parsing.SQLParsingEngine) DMLStatement(io.shardingjdbc.core.parsing.parser.sql.dml.DMLStatement) Test(org.junit.Test)

Example 7 with DMLStatement

use of io.shardingjdbc.core.parsing.parser.sql.dml.DMLStatement in project sharding-jdbc by shardingjdbc.

the class DeleteStatementParserTest method parseWithSpecialSyntax.

private void parseWithSpecialSyntax(final DatabaseType dbType, final String actualSQL) {
    ShardingRule shardingRule = createShardingRule();
    DMLStatement deleteStatement = (DMLStatement) new SQLParsingEngine(dbType, actualSQL, shardingRule).parse();
    assertThat(deleteStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX"));
    assertFalse(deleteStatement.getTables().find("TABLE_XXX").get().getAlias().isPresent());
    Condition condition = deleteStatement.getConditions().find(new Column("field1", "TABLE_XXX")).get();
    assertThat(condition.getOperator(), is(ShardingOperator.EQUAL));
    assertThat(((ListShardingValue<? extends Comparable>) condition.getShardingValue(Collections.emptyList())).getValues().iterator().next(), is((Comparable) 1));
}
Also used : Condition(io.shardingjdbc.core.parsing.parser.context.condition.Condition) Column(io.shardingjdbc.core.parsing.parser.context.condition.Column) ShardingRule(io.shardingjdbc.core.rule.ShardingRule) DMLStatement(io.shardingjdbc.core.parsing.parser.sql.dml.DMLStatement) SQLParsingEngine(io.shardingjdbc.core.parsing.SQLParsingEngine)

Example 8 with DMLStatement

use of io.shardingjdbc.core.parsing.parser.sql.dml.DMLStatement in project sharding-jdbc by shardingjdbc.

the class UpdateStatementParserTest method parseWithoutCondition.

@Test
public void parseWithoutCondition() {
    ShardingRule shardingRule = createShardingRule();
    SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "UPDATE TABLE_XXX SET field1=field1+1", shardingRule);
    DMLStatement updateStatement = (DMLStatement) statementParser.parse();
    assertThat(updateStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX"));
}
Also used : ShardingRule(io.shardingjdbc.core.rule.ShardingRule) SQLParsingEngine(io.shardingjdbc.core.parsing.SQLParsingEngine) DMLStatement(io.shardingjdbc.core.parsing.parser.sql.dml.DMLStatement) Test(org.junit.Test)

Example 9 with DMLStatement

use of io.shardingjdbc.core.parsing.parser.sql.dml.DMLStatement in project sharding-jdbc by shardingjdbc.

the class AbstractUpdateParser method parse.

@Override
public DMLStatement parse() {
    lexerEngine.nextToken();
    lexerEngine.skipAll(getSkippedKeywordsBetweenUpdateAndTable());
    lexerEngine.unsupportedIfEqual(getUnsupportedKeywordsBetweenUpdateAndTable());
    DMLStatement result = new DMLStatement();
    updateClauseParserFacade.getTableReferencesClauseParser().parse(result, true);
    updateClauseParserFacade.getUpdateSetItemsClauseParser().parse(result);
    lexerEngine.skipUntil(DefaultKeyword.WHERE);
    updateClauseParserFacade.getWhereClauseParser().parse(shardingRule, result, Collections.<SelectItem>emptyList());
    return result;
}
Also used : DMLStatement(io.shardingjdbc.core.parsing.parser.sql.dml.DMLStatement)

Example 10 with DMLStatement

use of io.shardingjdbc.core.parsing.parser.sql.dml.DMLStatement in project sharding-jdbc by shardingjdbc.

the class AbstractDeleteParser method parse.

@Override
public DMLStatement parse() {
    lexerEngine.nextToken();
    lexerEngine.skipAll(getSkippedKeywordsBetweenDeleteAndTable());
    lexerEngine.unsupportedIfEqual(getUnsupportedKeywordsBetweenDeleteAndTable());
    DMLStatement result = new DMLStatement();
    deleteClauseParserFacade.getTableReferencesClauseParser().parse(result, true);
    lexerEngine.skipUntil(DefaultKeyword.WHERE);
    deleteClauseParserFacade.getWhereClauseParser().parse(shardingRule, result, Collections.<SelectItem>emptyList());
    return result;
}
Also used : DMLStatement(io.shardingjdbc.core.parsing.parser.sql.dml.DMLStatement)

Aggregations

DMLStatement (io.shardingjdbc.core.parsing.parser.sql.dml.DMLStatement)10 SQLParsingEngine (io.shardingjdbc.core.parsing.SQLParsingEngine)8 ShardingRule (io.shardingjdbc.core.rule.ShardingRule)8 Test (org.junit.Test)6 Column (io.shardingjdbc.core.parsing.parser.context.condition.Column)2 Condition (io.shardingjdbc.core.parsing.parser.context.condition.Condition)2