Search in sources :

Example 11 with SQLParsingEngine

use of io.shardingjdbc.core.parsing.SQLParsingEngine 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);
}
Also used : ShardingRule(io.shardingjdbc.core.rule.ShardingRule) SQLParsingEngine(io.shardingjdbc.core.parsing.SQLParsingEngine) InsertStatement(io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement) Test(org.junit.Test)

Example 12 with SQLParsingEngine

use of io.shardingjdbc.core.parsing.SQLParsingEngine 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);
}
Also used : ShardingRule(io.shardingjdbc.core.rule.ShardingRule) SQLParsingEngine(io.shardingjdbc.core.parsing.SQLParsingEngine) InsertStatement(io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement) Test(org.junit.Test)

Example 13 with SQLParsingEngine

use of io.shardingjdbc.core.parsing.SQLParsingEngine 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);
}
Also used : ShardingRule(io.shardingjdbc.core.rule.ShardingRule) SQLParsingEngine(io.shardingjdbc.core.parsing.SQLParsingEngine) InsertStatement(io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement) Test(org.junit.Test)

Example 14 with SQLParsingEngine

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

the class UpdateStatementParserTest method parseWithoutParameter.

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

use of io.shardingjdbc.core.parsing.SQLParsingEngine 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)

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