Skip to content

Commit

Permalink
[SQLLINE-288] Output null value as "null"
Browse files Browse the repository at this point in the history
  • Loading branch information
arina-ielchiieva authored and julianhyde committed May 23, 2019
1 parent 525dd0e commit a689205
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/main/java/sqlline/SqlLineOpts.java
Expand Up @@ -400,18 +400,21 @@ public boolean getBoolean(SqlLineProperty key) {
}
}

/** Returns whether the property is its default value.
/**
* Returns whether the property is its default value.
*
* <p>This true if it has not been assigned a value,
* or if has been assigned a value equal to its default value.
*
* @param property Property
* @return whether property has its default value */
* @return whether property has its default value
*/
public boolean isDefault(SqlLineProperty property) {
final String defaultValue = String.valueOf(property.defaultValue());
final String currentValue = get(property);
return String.valueOf((Object) null).equals(currentValue)
|| Objects.equals(currentValue, defaultValue);
final Object currentValue =
propertiesMap.getOrDefault(property, property.defaultValue());
return currentValue == null
|| Objects.equals(String.valueOf(currentValue), defaultValue);
}

public String get(String key) {
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/sqlline/SqlLineArgsTest.java
Expand Up @@ -1243,12 +1243,16 @@ public void testNullValue() {
+ "!set outputformat csv\n"
+ "values (NULL, -1.5, null, date '1969-07-20', null, 'null');\n"
+ "!set nullValue \"'\"\n"
+ "values (NULL, -1.5, null, date '1969-07-20', null, 'null');\n"
+ "!set nullValue null\n"
+ "values (NULL, -1.5, null, date '1969-07-20', null, 'null');\n";
checkScriptFile(script, true, equalTo(SqlLine.Status.OK),
CoreMatchers.allOf(containsString("'C1','C2','C3','C4','C5','C6'"),
containsString("'%%%','-1.5','%%%','1969-07-20','%%%','null'"),
containsString("'C1','C2','C3','C4','C5','C6'"),
containsString("'''','-1.5','''','1969-07-20','''','null'")));
containsString("'''','-1.5','''','1969-07-20','''','null'"),
containsString("'C1','C2','C3','C4','C5','C6'"),
containsString("'null','-1.5','null','1969-07-20','null','null'")));
}

@Test
Expand Down

0 comments on commit a689205

Please sign in to comment.