Skip to content

Commit ae1eff9

Browse files
feat: syntax sugar
Signed-off-by: Andreas Reichel <andreas@manticore-projects.com>
1 parent 818464c commit ae1eff9

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/main/java/net/sf/jsqlparser/expression/operators/relational/IsNullExpression.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public IsNullExpression(Expression leftExpression) {
2929

3030
public IsNullExpression(String columnName, boolean not) {
3131
this.leftExpression = new Column(columnName);
32-
this.not = useNotNull;
32+
this.not = not;
3333
}
3434

3535
public Expression getLeftExpression() {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package net.sf.jsqlparser.expression;
2+
3+
import net.sf.jsqlparser.JSQLParserException;
4+
import net.sf.jsqlparser.schema.Column;
5+
import net.sf.jsqlparser.statement.select.PlainSelect;
6+
import net.sf.jsqlparser.statement.select.SelectItem;
7+
import net.sf.jsqlparser.test.TestUtils;
8+
import org.junit.jupiter.api.Test;
9+
10+
import static org.junit.jupiter.api.Assertions.*;
11+
12+
class ArrayExpressionTest {
13+
14+
@Test
15+
void testColumnArrayExpression() throws JSQLParserException {
16+
String sqlStr = "SELECT a[2+1] AS a";
17+
PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
18+
SelectItem<?> selectItem = select.getSelectItem(0);
19+
20+
Column column = selectItem.getExpression(Column.class);
21+
assertInstanceOf(ArrayConstructor.class, column.getArrayConstructor());
22+
}
23+
24+
}

src/test/java/net/sf/jsqlparser/expression/operators/relational/IsNullExpressionTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ void testNotNullExpression() throws JSQLParserException {
2020
String sqlStr = "select * from mytable where 1 notnull";
2121
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
2222
}
23+
24+
@Test
25+
void testStringConstructor() {
26+
IsNullExpression isNullExpression= new IsNullExpression("x", true);
27+
TestUtils.assertExpressionCanBeDeparsedAs(isNullExpression, "x IS NOT NULL");
28+
}
2329
}

0 commit comments

Comments
 (0)