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);
}
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));
}
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"));
}
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;
}
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;
}
Aggregations