use of io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement in project sharding-jdbc by shardingjdbc.
the class ParsingSQLRouter method parse.
@Override
public SQLStatement parse(final String logicSQL) {
SQLParsingEngine parsingEngine = new SQLParsingEngine(databaseType, logicSQL, shardingRule);
SQLStatement result = parsingEngine.parse();
if (result instanceof InsertStatement) {
((InsertStatement) result).appendGenerateKeyToken(shardingRule);
}
return result;
}
use of io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement in project sharding-jdbc by shardingjdbc.
the class InsertStatementParserTest method parseWithSpecialSyntax.
@SuppressWarnings("unchecked")
private void parseWithSpecialSyntax(final DatabaseType dbType, final String actualSQL) {
ShardingRule shardingRule = createShardingRule();
InsertStatement insertStatement = (InsertStatement) new SQLParsingEngine(dbType, actualSQL, shardingRule).parse();
assertThat(insertStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX"));
assertFalse(insertStatement.getTables().find("TABLE_XXX").get().getAlias().isPresent());
Condition condition = insertStatement.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.insert.InsertStatement in project sharding-jdbc by shardingjdbc.
the class InsertStatementParserTest method assertParseWithoutParameter.
@Test
public void assertParseWithoutParameter() {
ShardingRule shardingRule = createShardingRule();
SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "INSERT INTO `TABLE_XXX` (`field1`, `field2`) VALUES (10, 1)", shardingRule);
InsertStatement insertStatement = (InsertStatement) statementParser.parse();
assertInsertStatementWithoutParameter(insertStatement);
}
use of io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement in project sharding-jdbc by shardingjdbc.
the class InsertStatementParserTest method assertParseWithParameter.
@Test
public void assertParseWithParameter() {
ShardingRule shardingRule = createShardingRule();
SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "INSERT INTO TABLE_XXX (field1, field2) VALUES (?, ?)", shardingRule);
InsertStatement insertStatement = (InsertStatement) statementParser.parse();
assertInsertStatementWithParameter(insertStatement);
}
use of io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement in project sharding-jdbc by shardingjdbc.
the class InsertStatementParserTest method assertParseWithGenerateKeyColumnsWithParameter.
@Test
public void assertParseWithGenerateKeyColumnsWithParameter() {
ShardingRule shardingRule = createShardingRuleWithGenerateKeyColumns();
SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "INSERT INTO `TABLE_XXX` (`field1`) VALUES (?)", shardingRule);
InsertStatement insertStatement = (InsertStatement) statementParser.parse();
assertInsertStatementWithParameter(insertStatement);
}
Aggregations