Search in sources :

Example 6 with SQLParsingEngine

use of io.shardingjdbc.core.parsing.SQLParsingEngine in project sharding-jdbc by shardingjdbc.

the class DeleteStatementParserTest method parseWithoutCondition.

@Test
public void parseWithoutCondition() {
    ShardingRule shardingRule = createShardingRule();
    SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "DELETE FROM TABLE_XXX", shardingRule);
    DMLStatement deleteStatement = (DMLStatement) statementParser.parse();
    assertThat(deleteStatement.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 7 with SQLParsingEngine

use of io.shardingjdbc.core.parsing.SQLParsingEngine in project sharding-jdbc by shardingjdbc.

the class DeleteStatementParserTest method parseStatementWithDeleteMultipleTable.

@Test(expected = UnsupportedOperationException.class)
public void parseStatementWithDeleteMultipleTable() {
    ShardingRule shardingRule = createShardingRule();
    new SQLParsingEngine(DatabaseType.MySQL, "DELETE TABLE_XXX1, TABLE_xxx2 FROM TABLE_XXX1 JOIN TABLE_XXX2", shardingRule).parse();
}
Also used : ShardingRule(io.shardingjdbc.core.rule.ShardingRule) SQLParsingEngine(io.shardingjdbc.core.parsing.SQLParsingEngine) Test(org.junit.Test)

Example 8 with SQLParsingEngine

use of io.shardingjdbc.core.parsing.SQLParsingEngine in project sharding-jdbc by shardingjdbc.

the class DeleteStatementParserTest method parseWithParameter.

@Test
public void parseWithParameter() {
    ShardingRule shardingRule = createShardingRule();
    SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "DELETE FROM TABLE_XXX xxx WHERE field4<? AND field1=? AND field5>? AND field2 IN (?,?) AND field6<=? AND field3 BETWEEN ? AND ? AND field7>=?", shardingRule);
    DMLStatement deleteStatement = (DMLStatement) statementParser.parse();
    assertDeleteStatementWithParameter(deleteStatement);
}
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 SQLParsingEngine

use of io.shardingjdbc.core.parsing.SQLParsingEngine in project sharding-jdbc by shardingjdbc.

the class DeleteStatementParserTest method parseWithoutParameter.

@Test
public void parseWithoutParameter() {
    ShardingRule shardingRule = createShardingRule();
    SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "DELETE FROM TABLE_XXX xxx WHERE field4<10 AND TABLE_XXX.field1=1 AND field5>10 AND xxx.field2 IN (1,3) AND field6<=10 AND field3 BETWEEN 5 AND 20 AND field7>=10", shardingRule);
    DMLStatement deleteStatement = (DMLStatement) statementParser.parse();
    assertDeleteStatementWithoutParameter(deleteStatement);
}
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 10 with SQLParsingEngine

use of io.shardingjdbc.core.parsing.SQLParsingEngine 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));
}
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) SQLParsingEngine(io.shardingjdbc.core.parsing.SQLParsingEngine) InsertStatement(io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement)

Aggregations

SQLParsingEngine (io.shardingjdbc.core.parsing.SQLParsingEngine)23 ShardingRule (io.shardingjdbc.core.rule.ShardingRule)19 Test (org.junit.Test)17 DMLStatement (io.shardingjdbc.core.parsing.parser.sql.dml.DMLStatement)8 InsertStatement (io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement)6 Column (io.shardingjdbc.core.parsing.parser.context.condition.Column)3 Condition (io.shardingjdbc.core.parsing.parser.context.condition.Condition)3 SQLStatement (io.shardingjdbc.core.parsing.parser.sql.SQLStatement)2 LinkedList (java.util.LinkedList)2 QueryResult (io.shardingjdbc.core.merger.QueryResult)1 MemoryQueryResultRow (io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow)1 SQLStatementAssert (io.shardingjdbc.core.parsing.integrate.asserts.SQLStatementAssert)1 TableRule (io.shardingjdbc.core.rule.TableRule)1 DatabaseProtocolPacket (io.shardingjdbc.proxy.transport.common.packet.DatabaseProtocolPacket)1 ColumnDefinition41Packet (io.shardingjdbc.proxy.transport.mysql.packet.command.text.query.ColumnDefinition41Packet)1 EofPacket (io.shardingjdbc.proxy.transport.mysql.packet.generic.EofPacket)1