Search in sources :

Example 21 with Column

use of net.sf.jsqlparser.schema.Column 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);
}
Also used : Replace(net.sf.jsqlparser.statement.replace.Replace) Table(net.sf.jsqlparser.schema.Table) Column(net.sf.jsqlparser.schema.Column) Expression(net.sf.jsqlparser.expression.Expression) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 22 with Column

use of net.sf.jsqlparser.schema.Column in project JSqlParser by JSQLParser.

the class StatementDeParserTest method shouldUseProvidedDeparsersWhenDeParsingInsert.

@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void shouldUseProvidedDeparsersWhenDeParsingInsert() throws JSQLParserException {
    Insert insert = new Insert();
    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);
    insert.setSelect(select);
    insert.setTable(table);
    insert.setUseDuplicate(true);
    insert.setDuplicateUpdateColumns(duplicateUpdateColumns);
    insert.setDuplicateUpdateExpressionList(duplicateUpdateExpressionList);
    duplicateUpdateColumns.add(duplicateUpdateColumn1);
    duplicateUpdateColumns.add(duplicateUpdateColumn2);
    duplicateUpdateExpressionList.add(duplicateUpdateExpression1);
    duplicateUpdateExpressionList.add(duplicateUpdateExpression2);
    insert.setDuplicateUpdateExpressionList(duplicateUpdateExpressionList);
    select.setWithItemsList(withItemsList);
    select.setSelectBody(selectBody);
    withItemsList.add(withItem1);
    withItemsList.add(withItem2);
    withItem1.setSelectBody(withItem1SelectBody);
    withItem2.setSelectBody(withItem2SelectBody);
    statementDeParser.visit(insert);
    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);
}
Also used : Table(net.sf.jsqlparser.schema.Table) Column(net.sf.jsqlparser.schema.Column) Expression(net.sf.jsqlparser.expression.Expression) ArrayList(java.util.ArrayList) Select(net.sf.jsqlparser.statement.select.Select) WithItem(net.sf.jsqlparser.statement.select.WithItem) SelectBody(net.sf.jsqlparser.statement.select.SelectBody) Insert(net.sf.jsqlparser.statement.insert.Insert) Test(org.junit.Test)

Example 23 with Column

use of net.sf.jsqlparser.schema.Column in project JSqlParser by JSQLParser.

the class SelectUtilsTest method testAddExpr.

/**
 * Test of addColumn method, of class SelectUtils.
 */
@Test
public void testAddExpr() throws JSQLParserException {
    Select select = (Select) CCJSqlParserUtil.parse("select a from mytable");
    SelectUtils.addExpression(select, new Column("b"));
    assertEquals("SELECT a, b FROM mytable", select.toString());
    Addition add = new Addition();
    add.setLeftExpression(new LongValue(5));
    add.setRightExpression(new LongValue(6));
    SelectUtils.addExpression(select, add);
    assertEquals("SELECT a, b, 5 + 6 FROM mytable", select.toString());
}
Also used : Addition(net.sf.jsqlparser.expression.operators.arithmetic.Addition) Column(net.sf.jsqlparser.schema.Column) PlainSelect(net.sf.jsqlparser.statement.select.PlainSelect) Select(net.sf.jsqlparser.statement.select.Select) LongValue(net.sf.jsqlparser.expression.LongValue) Test(org.junit.Test)

Example 24 with Column

use of net.sf.jsqlparser.schema.Column in project JSqlParser by JSQLParser.

the class SelectUtilsTest method testTableAliasIssue311_2.

public void testTableAliasIssue311_2() {
    Table table1 = new Table("mytable1");
    table1.setAlias(new Alias("tab1"));
    Column col = new Column(table1, "col1");
    assertEquals("tab1.col1", col.toString());
    assertEquals("mytable.col1", col.getFullyQualifiedName());
}
Also used : Table(net.sf.jsqlparser.schema.Table) Column(net.sf.jsqlparser.schema.Column) Alias(net.sf.jsqlparser.expression.Alias)

Example 25 with Column

use of net.sf.jsqlparser.schema.Column in project JSqlParser by JSQLParser.

the class SelectUtilsTest method testBuildSelectFromTableAndExpressions.

@Test
public void testBuildSelectFromTableAndExpressions() {
    Select select = SelectUtils.buildSelectFromTableAndExpressions(new Table("mytable"), new Column("a"), new Column("b"));
    assertEquals("SELECT a, b FROM mytable", select.toString());
}
Also used : Table(net.sf.jsqlparser.schema.Table) Column(net.sf.jsqlparser.schema.Column) PlainSelect(net.sf.jsqlparser.statement.select.PlainSelect) Select(net.sf.jsqlparser.statement.select.Select) Test(org.junit.Test)

Aggregations

Column (net.sf.jsqlparser.schema.Column)43 Expression (net.sf.jsqlparser.expression.Expression)19 Test (org.junit.Test)19 Table (net.sf.jsqlparser.schema.Table)18 PlainSelect (net.sf.jsqlparser.statement.select.PlainSelect)18 Select (net.sf.jsqlparser.statement.select.Select)18 ArrayList (java.util.ArrayList)9 SelectExpressionItem (net.sf.jsqlparser.statement.select.SelectExpressionItem)8 SelectItem (net.sf.jsqlparser.statement.select.SelectItem)8 OrderByElement (net.sf.jsqlparser.statement.select.OrderByElement)6 LongValue (net.sf.jsqlparser.expression.LongValue)5 AndExpression (net.sf.jsqlparser.expression.operators.conditional.AndExpression)5 Statement (net.sf.jsqlparser.statement.Statement)5 SelectBody (net.sf.jsqlparser.statement.select.SelectBody)5 SimpleNode (net.sf.jsqlparser.parser.SimpleNode)4 SelectVisitorAdapter (net.sf.jsqlparser.statement.select.SelectVisitorAdapter)4 WriteBuilder (com.google.cloud.spanner.Mutation.WriteBuilder)3 ExpressionVisitorAdapter (net.sf.jsqlparser.expression.ExpressionVisitorAdapter)3 CloudSpannerSQLException (nl.topicus.jdbc.exception.CloudSpannerSQLException)3 SQLException (java.sql.SQLException)2