use of net.sf.jsqlparser.statement.replace.Replace in project JSqlParser by JSQLParser.
the class TablesNamesFinderTest method testGetTableListFromReplace.
@Test
public void testGetTableListFromReplace() throws Exception {
String sql = "REPLACE INTO MY_TABLE1 (a) VALUES ((SELECT a from MY_TABLE2 WHERE a = 1))";
net.sf.jsqlparser.statement.Statement statement = pm.parse(new StringReader(sql));
Replace replaceStatement = (Replace) statement;
TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();
List<String> tableList = tablesNamesFinder.getTableList(replaceStatement);
assertEquals(2, tableList.size());
assertTrue(tableList.contains("MY_TABLE1"));
assertTrue(tableList.contains("MY_TABLE2"));
}
use of net.sf.jsqlparser.statement.replace.Replace in project JSqlParser by JSQLParser.
the class StatementDeParserTest method shouldUseProvidedDeParsersWhenDeParsingReplaceWithItemsList.
@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void shouldUseProvidedDeParsersWhenDeParsingReplaceWithItemsList() {
Replace replace = new Replace();
Table table = new Table();
ItemsList itemsList = mock(ItemsList.class);
replace.setTable(table);
replace.setItemsList(itemsList);
statementDeParser.visit(replace);
then(itemsList).should().accept(argThat(is(replaceDeParserWithDeParsers(equalTo(expressionDeParser), equalTo(selectDeParser)))));
}
use of net.sf.jsqlparser.statement.replace.Replace in project JSqlParser by JSQLParser.
the class ReplaceTest method testReplaceSyntax1.
@Test
public void testReplaceSyntax1() throws JSQLParserException {
String statement = "REPLACE mytable SET col1='as', col2=?, col3=565";
Replace replace = (Replace) PARSER_MANAGER.parse(new StringReader(statement));
assertEquals("mytable", replace.getTable().getName());
assertEquals(3, replace.getColumns().size());
assertEquals("col1", ((Column) replace.getColumns().get(0)).getColumnName());
assertEquals("col2", ((Column) replace.getColumns().get(1)).getColumnName());
assertEquals("col3", ((Column) replace.getColumns().get(2)).getColumnName());
assertEquals("as", ((StringValue) replace.getExpressions().get(0)).getValue());
assertTrue(replace.getExpressions().get(1) instanceof JdbcParameter);
assertEquals(565, ((LongValue) replace.getExpressions().get(2)).getValue());
assertEquals(statement, "" + replace);
}
use of net.sf.jsqlparser.statement.replace.Replace in project JSqlParser by JSQLParser.
the class ReplaceTest method testReplaceSyntax3.
@Test
public void testReplaceSyntax3() throws JSQLParserException {
String statement = "REPLACE mytable (col1, col2, col3) SELECT * FROM mytable3";
Replace replace = (Replace) PARSER_MANAGER.parse(new StringReader(statement));
assertEquals("mytable", replace.getTable().getName());
assertEquals(3, replace.getColumns().size());
assertEquals("col1", ((Column) replace.getColumns().get(0)).getColumnName());
assertEquals("col2", ((Column) replace.getColumns().get(1)).getColumnName());
assertEquals("col3", ((Column) replace.getColumns().get(2)).getColumnName());
assertTrue(replace.getItemsList() instanceof SubSelect);
}
use of net.sf.jsqlparser.statement.replace.Replace in project JSqlParser by JSQLParser.
the class StatementDeParserTest method shouldUseProvidedDeParsersWhenDeParsingReplaceWithoutItemsList.
@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void shouldUseProvidedDeParsersWhenDeParsingReplaceWithoutItemsList() {
Replace replace = new Replace();
Table table = new Table();
List<Column> columns = new ArrayList<Column>();
List<Expression> expressions = new ArrayList<Expression>();
Column column1 = new Column();
Column column2 = new Column();
Expression expression1 = mock(Expression.class);
Expression expression2 = mock(Expression.class);
replace.setTable(table);
replace.setColumns(columns);
replace.setExpressions(expressions);
columns.add(column1);
columns.add(column2);
expressions.add(expression1);
expressions.add(expression2);
statementDeParser.visit(replace);
then(expression1).should().accept(expressionDeParser);
then(expression2).should().accept(expressionDeParser);
}
Aggregations