use of io.shardingjdbc.core.parsing.parser.token.TableToken in project sharding-jdbc by shardingjdbc.
the class TableReferencesClauseParser method parseSingleTableWithoutAlias.
/**
* Parse single table without alias.
*
* @param sqlStatement SQL statement
*/
public final void parseSingleTableWithoutAlias(final SQLStatement sqlStatement) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
sqlStatement.getSqlTokens().add(new TableToken(beginPosition, lexerEngine.getCurrentToken().getLiterals()));
sqlStatement.getTables().add(new Table(lexerEngine.getCurrentToken().getLiterals(), Optional.<String>absent()));
lexerEngine.nextToken();
}
use of io.shardingjdbc.core.parsing.parser.token.TableToken in project sharding-jdbc by shardingjdbc.
the class UpdateSetItemsClauseParser method parseSetColumn.
private void parseSetColumn(final DMLStatement updateStatement) {
if (lexerEngine.equalAny(Symbol.LEFT_PAREN)) {
lexerEngine.skipParentheses(updateStatement);
return;
}
int beginPosition = lexerEngine.getCurrentToken().getEndPosition();
String literals = lexerEngine.getCurrentToken().getLiterals();
lexerEngine.nextToken();
if (lexerEngine.skipIfEqual(Symbol.DOT)) {
if (updateStatement.getTables().getSingleTableName().equalsIgnoreCase(SQLUtil.getExactlyValue(literals))) {
updateStatement.getSqlTokens().add(new TableToken(beginPosition - literals.length(), literals));
}
lexerEngine.nextToken();
}
}
use of io.shardingjdbc.core.parsing.parser.token.TableToken in project sharding-jdbc by shardingjdbc.
the class SQLRewriteEngineTest method assertRewriteForAutoGeneratedKeyColumn.
@Test
public void assertRewriteForAutoGeneratedKeyColumn() {
selectStatement.getSqlTokens().add(new TableToken(12, "table_x"));
ItemsToken itemsToken1 = new ItemsToken(30);
itemsToken1.getItems().add("id");
ItemsToken itemsToken2 = new ItemsToken(44);
itemsToken2.getItems().add("?");
selectStatement.getSqlTokens().addAll(Arrays.asList(itemsToken1, itemsToken2));
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, "INSERT INTO table_x (name, age) VALUES (?, ?)", DatabaseType.MySQL, selectStatement);
assertThat(rewriteEngine.rewrite(true).toSQL(tableTokens, null), is("INSERT INTO table_1 (name, age, id) VALUES (?, ?, ?)"));
}
use of io.shardingjdbc.core.parsing.parser.token.TableToken in project sharding-jdbc by shardingjdbc.
the class SQLRewriteEngineTest method assertRewriteForTopAndRowNumberForNotRewriteLimit.
@Test
public void assertRewriteForTopAndRowNumberForNotRewriteLimit() {
selectStatement.setLimit(new Limit(DatabaseType.SQLServer));
selectStatement.getLimit().setOffset(new LimitValue(2, -1, true));
selectStatement.getLimit().setRowCount(new LimitValue(4, -1, false));
selectStatement.getSqlTokens().add(new TableToken(85, "table_x"));
selectStatement.getSqlTokens().add(new OffsetToken(123, 2));
selectStatement.getSqlTokens().add(new RowCountToken(26, 4));
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, "SELECT * FROM (SELECT TOP(4) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_x x) AS row_ WHERE row_.rownum_>2", DatabaseType.SQLServer, selectStatement);
assertThat(rewriteEngine.rewrite(false).toSQL(tableTokens, null), is("SELECT * FROM (SELECT TOP(4) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_1 x) AS row_ WHERE row_.rownum_>2"));
}
use of io.shardingjdbc.core.parsing.parser.token.TableToken in project sharding-jdbc by shardingjdbc.
the class SQLRewriteEngineTest method assertRewriteForRowNumForMemoryGroupBy.
@Test
public void assertRewriteForRowNumForMemoryGroupBy() {
selectStatement.setLimit(new Limit(DatabaseType.Oracle));
selectStatement.getLimit().setOffset(new LimitValue(2, -1, true));
selectStatement.getLimit().setRowCount(new LimitValue(4, -1, false));
selectStatement.getSqlTokens().add(new TableToken(68, "table_x"));
selectStatement.getSqlTokens().add(new OffsetToken(119, 2));
selectStatement.getSqlTokens().add(new RowCountToken(98, 4));
selectStatement.getOrderByItems().add(new OrderItem("x", "id", OrderDirection.ASC, OrderDirection.ASC, Optional.<String>absent()));
selectStatement.getGroupByItems().add(new OrderItem("x", "id", OrderDirection.DESC, OrderDirection.ASC, Optional.<String>absent()));
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, "SELECT * FROM (SELECT row_.*, rownum rownum_ FROM (SELECT x.id FROM table_x x) row_ WHERE rownum<=4) t WHERE t.rownum_>2", DatabaseType.Oracle, selectStatement);
assertThat(rewriteEngine.rewrite(true).toSQL(tableTokens, null), is("SELECT * FROM (SELECT row_.*, rownum rownum_ FROM (SELECT x.id FROM table_1 x) row_ WHERE rownum<=2147483647) t WHERE t.rownum_>0"));
}
Aggregations