-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Issue #2109 true and false value parsed as column instead of Boo…
…leanValue (#2110) Co-authored-by: Luca Rota <[email protected]>
- Loading branch information
Showing
11 changed files
with
191 additions
and
3 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/main/java/net/sf/jsqlparser/expression/BooleanValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/*- | ||
* #%L | ||
* JSQLParser library | ||
* %% | ||
* Copyright (C) 2004 - 2024 JSQLParser | ||
* %% | ||
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0 | ||
* #L% | ||
*/ | ||
package net.sf.jsqlparser.expression; | ||
|
||
import net.sf.jsqlparser.parser.ASTNodeAccessImpl; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* A boolean value true/false | ||
*/ | ||
public final class BooleanValue extends ASTNodeAccessImpl implements Expression { | ||
|
||
private boolean value = false; | ||
|
||
public BooleanValue() { | ||
// empty constructor | ||
} | ||
|
||
public BooleanValue(String value) { | ||
this(Boolean.parseBoolean(value)); | ||
} | ||
|
||
public BooleanValue(boolean bool) { | ||
value = bool; | ||
} | ||
|
||
public boolean getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(boolean bool) { | ||
value = bool; | ||
} | ||
|
||
@Override | ||
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) { | ||
return expressionVisitor.visit(this, context); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Boolean.toString(value); | ||
} | ||
|
||
public BooleanValue withValue(boolean bool) { | ||
this.setValue(bool); | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
BooleanValue that = (BooleanValue) o; | ||
return Objects.equals(value, that.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/java/net/sf/jsqlparser/expression/BooleanValueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*- | ||
* #%L | ||
* JSQLParser library | ||
* %% | ||
* Copyright (C) 2004 - 2024 JSQLParser | ||
* %% | ||
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0 | ||
* #L% | ||
*/ | ||
package net.sf.jsqlparser.expression; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* | ||
* @author tw | ||
*/ | ||
public class BooleanValueTest { | ||
|
||
@Test | ||
public void testTrueValue() { | ||
BooleanValue value = new BooleanValue("true"); | ||
|
||
assertTrue(value.getValue()); | ||
} | ||
|
||
@Test | ||
public void testFalseValue() { | ||
BooleanValue value = new BooleanValue("false"); | ||
|
||
assertFalse(value.getValue()); | ||
} | ||
|
||
@Test | ||
public void testWrongValueAsFalseLargeNumber() { | ||
BooleanValue value = new BooleanValue("test"); | ||
|
||
assertFalse(value.getValue()); | ||
} | ||
|
||
@Test | ||
public void testNullStringValue() { | ||
BooleanValue value = new BooleanValue(null); | ||
|
||
assertFalse(value.getValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters