|
1 | 1 | package net.sf.jsqlparser.util;
|
2 | 2 |
|
| 3 | +import java.util.Arrays; |
| 4 | +import java.util.List; |
3 | 5 | import net.sf.jsqlparser.JSQLParserException;
|
| 6 | +import net.sf.jsqlparser.expression.Alias; |
4 | 7 | import net.sf.jsqlparser.expression.Expression;
|
5 | 8 | import net.sf.jsqlparser.expression.LongValue;
|
6 | 9 | import net.sf.jsqlparser.expression.operators.arithmetic.Addition;
|
@@ -99,4 +102,24 @@ public void testBuildSelectFromTableWithGroupBy() {
|
99 | 102 | assertEquals("SELECT * FROM mytable GROUP BY b", select.toString());
|
100 | 103 | }
|
101 | 104 |
|
| 105 | + @Test |
| 106 | + public void testTableAliasIssue311() { |
| 107 | + Table table1 = new Table("mytable1"); |
| 108 | + table1.setAlias(new Alias("tab1")); |
| 109 | + Table table2 = new Table("mytable2"); |
| 110 | + table2.setAlias(new Alias("tab2")); |
| 111 | + |
| 112 | + List<? extends Expression> colunas = Arrays.asList(new Column(table1, "col1"), new Column(table1, "col2"), new Column(table1, "col3"), new Column(table2, "b1"), new Column(table2, "b2")); |
| 113 | + |
| 114 | + Select select = SelectUtils.buildSelectFromTableAndExpressions(table1, colunas.toArray(new Expression[colunas.size()])); |
| 115 | + |
| 116 | + final EqualsTo equalsTo = new EqualsTo(); |
| 117 | + equalsTo.setLeftExpression(new Column(table1, "col1")); |
| 118 | + equalsTo.setRightExpression(new Column(table2, "b1")); |
| 119 | + Join addJoin = SelectUtils.addJoin(select, table2, equalsTo); |
| 120 | + addJoin.setLeft(true); |
| 121 | + |
| 122 | + assertEquals("SELECT tab1.col1, tab1.col2, tab1.col3, tab2.b1, tab2.b2 FROM mytable1 AS tab1 LEFT JOIN mytable2 AS tab2 ON tab1.col1 = tab2.b1", |
| 123 | + select.toString()); |
| 124 | + } |
102 | 125 | }
|
0 commit comments