use of net.sf.jsqlparser.schema.Table in project JSqlParser by JSQLParser.
the class SelectUtilsTest method testBuildSelectFromTableAndParsedExpression.
@Test
public void testBuildSelectFromTableAndParsedExpression() throws JSQLParserException {
Select select = SelectUtils.buildSelectFromTableAndExpressions(new Table("mytable"), "a+b", "test");
assertEquals("SELECT a + b, test FROM mytable", select.toString());
assertTrue(((SelectExpressionItem) ((PlainSelect) select.getSelectBody()).getSelectItems().get(0)).getExpression() instanceof Addition);
}
use of net.sf.jsqlparser.schema.Table 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.schema.Table in project JSqlParser by JSQLParser.
the class StatementDeParserTest method shouldUseProvidedDeparsersWhenDeParsingUpsertWithExpressionList.
@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void shouldUseProvidedDeparsersWhenDeParsingUpsertWithExpressionList() throws JSQLParserException {
Upsert upsert = new Upsert();
Table table = new Table();
List<Column> duplicateUpdateColumns = new ArrayList<Column>();
List<Expression> duplicateUpdateExpressionList = new ArrayList<Expression>();
Column duplicateUpdateColumn1 = new Column();
Column duplicateUpdateColumn2 = new Column();
Expression duplicateUpdateExpression1 = mock(Expression.class);
Expression duplicateUpdateExpression2 = mock(Expression.class);
Select select = new Select();
List<WithItem> withItemsList = new ArrayList<WithItem>();
WithItem withItem1 = spy(new WithItem());
WithItem withItem2 = spy(new WithItem());
SelectBody withItem1SelectBody = mock(SelectBody.class);
SelectBody withItem2SelectBody = mock(SelectBody.class);
SelectBody selectBody = mock(SelectBody.class);
upsert.setSelect(select);
upsert.setTable(table);
upsert.setUseDuplicate(true);
upsert.setDuplicateUpdateColumns(duplicateUpdateColumns);
upsert.setDuplicateUpdateExpressionList(duplicateUpdateExpressionList);
duplicateUpdateColumns.add(duplicateUpdateColumn1);
duplicateUpdateColumns.add(duplicateUpdateColumn2);
duplicateUpdateExpressionList.add(duplicateUpdateExpression1);
duplicateUpdateExpressionList.add(duplicateUpdateExpression2);
upsert.setDuplicateUpdateExpressionList(duplicateUpdateExpressionList);
select.setWithItemsList(withItemsList);
select.setSelectBody(selectBody);
withItemsList.add(withItem1);
withItemsList.add(withItem2);
withItem1.setSelectBody(withItem1SelectBody);
withItem2.setSelectBody(withItem2SelectBody);
statementDeParser.visit(upsert);
then(withItem1).should().accept(selectDeParser);
then(withItem2).should().accept(selectDeParser);
then(selectBody).should().accept(selectDeParser);
then(duplicateUpdateExpression1).should().accept(expressionDeParser);
then(duplicateUpdateExpression1).should().accept(expressionDeParser);
}
use of net.sf.jsqlparser.schema.Table in project JSqlParser by JSQLParser.
the class DeleteDeParser method deParse.
public void deParse(Delete delete) {
buffer.append("DELETE");
if (delete.getTables() != null && delete.getTables().size() > 0) {
for (Table table : delete.getTables()) {
buffer.append(" ").append(table.getFullyQualifiedName());
}
}
buffer.append(" FROM ").append(delete.getTable().toString());
if (delete.getJoins() != null) {
for (Join join : delete.getJoins()) {
if (join.isSimple()) {
buffer.append(", ").append(join);
} else {
buffer.append(" ").append(join);
}
}
}
if (delete.getWhere() != null) {
buffer.append(" WHERE ");
delete.getWhere().accept(expressionVisitor);
}
if (delete.getOrderByElements() != null) {
new OrderByDeParser(expressionVisitor, buffer).deParse(delete.getOrderByElements());
}
if (delete.getLimit() != null) {
new LimitDeparser(buffer).deParse(delete.getLimit());
}
}
use of net.sf.jsqlparser.schema.Table in project JSqlParser by JSQLParser.
the class Delete method toString.
@Override
public String toString() {
StringBuilder b = new StringBuilder("DELETE");
if (tables != null && tables.size() > 0) {
b.append(" ");
for (Table t : tables) {
b.append(t.toString());
}
}
b.append(" FROM ");
b.append(table);
if (joins != null) {
for (Join join : joins) {
if (join.isSimple()) {
b.append(", ").append(join);
} else {
b.append(" ").append(join);
}
}
}
if (where != null) {
b.append(" WHERE ").append(where);
}
if (orderByElements != null) {
b.append(PlainSelect.orderByToString(orderByElements));
}
if (limit != null) {
b.append(limit);
}
return b.toString();
}
Aggregations