Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SQLLINE-440] Support legacy date/time format #442

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/apidocs/index-all.html
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,8 @@ <h2 class="title">K</h2>
</a>
<h2 class="title">L</h2>
<dl>
<dt><span class="memberNameLink"><a href="sqlline/BuiltInProperty.html#LEGACY_DATE_AND_TIME_FOMRAT">LEGACY_DATE_AND_TIME_FOMRAT</a></span> - sqlline.<a href="sqlline/BuiltInProperty.html" title="enum in sqlline">BuiltInProperty</a></dt>
<dd>&nbsp;</dd>
<dt><span class="memberNameLink"><a href="sqlline/SqlLineParser.SqlParserState.html#LINE_CONTINUES">LINE_CONTINUES</a></span> - sqlline.<a href="sqlline/SqlLineParser.SqlParserState.html" title="enum in sqlline">SqlLineParser.SqlParserState</a></dt>
<dd>&nbsp;</dd>
<dt><span class="memberNameLink"><a href="sqlline/Commands.html#list(java.lang.String,sqlline.DispatchCallback)">list(String, DispatchCallback)</a></span> - Method in class sqlline.<a href="sqlline/Commands.html" title="class in sqlline">Commands</a></dt>
Expand Down
2 changes: 1 addition & 1 deletion docs/apidocs/member-search-index.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions docs/apidocs/sqlline/BuiltInProperty.html
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ <h2>Enum Constant Summary</h2>
<td class="colLast">&nbsp;</td>
</tr>
<tr class="rowColor">
<th class="colFirst" scope="row"><code><span class="memberNameLink"><a href="#LEGACY_DATE_AND_TIME_FOMRAT">LEGACY_DATE_AND_TIME_FOMRAT</a></span></code></th>
<td class="colLast">&nbsp;</td>
</tr>
</tr>
<tr class="rowColor">
<th class="colFirst" scope="row"><code><span class="memberNameLink"><a href="#LIVE_TEMPLATES">LIVE_TEMPLATES</a></span></code></th>
<td class="colLast">&nbsp;</td>
</tr>
Expand Down Expand Up @@ -628,6 +633,13 @@ <h3><a id="ISOLATION">ISOLATION</a></h3>
<h3><a id="KEEP_SEMICOLON">KEEP_SEMICOLON</a></h3>
<div class="memberSignature"><span class="modifiers">public static final</span>&nbsp;<span class="returnType"><a href="BuiltInProperty.html" title="enum in sqlline">BuiltInProperty</a></span>&nbsp;<span class="memberName">KEEP_SEMICOLON</span></div>
</section>
</li>
</li>
<li class="blockList">
<section class="detail">
<h3><a id="LEGACY_DATE_AND_TIME_FOMRAT">LEGACY_DATE_AND_TIME_FOMRAT</a></h3>
<div class="memberSignature"><span class="modifiers">public static final</span>&nbsp;<span class="returnType"><a href="BuiltInProperty.html" title="enum in sqlline">BuiltInProperty</a></span>&nbsp;<span class="memberName">LEGACY_DATE_AND_TIME_FOMRAT</span></div>
</section>
</li>
<li class="blockList">
<section class="detail">
Expand Down
1 change: 1 addition & 0 deletions src/main/java/sqlline/BuiltInProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public enum BuiltInProperty implements SqlLineProperty {
ISOLATION("isolation", Type.STRING, "TRANSACTION_REPEATABLE_READ",
true, false, new HashSet<>(new Application().getIsolationLevels())),
KEEP_SEMICOLON("keepSemicolon", Type.BOOLEAN, false),
LEGACY_DATE_AND_TIME_FOMRAT("legacyDateAndTimeFormat", Type.BOOLEAN, false),
LIVE_TEMPLATES("liveTemplates", Type.FILE_PATH, ""),
MAX_COLUMN_WIDTH("maxColumnWidth", Type.INTEGER, -1),
// don't save maxheight, maxwidth: it is automatically set based on
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/sqlline/Rows.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,25 @@ class Row {
setFormat(rs.getObject(i + 1), null, i);
break;
case Types.TIME:
setFormat(rs.getObject(i + 1), timeFormat, i);
if (!sqlLine.getOpts().getlegacyDateAndTimeFormat()) {
setFormat(rs.getObject(i + 1), timeFormat, i);
} else {
values[i] = rs.getString(i + 1);
}
break;
case Types.DATE:
setFormat(rs.getObject(i + 1), dateFormat, i);
if (!sqlLine.getOpts().getlegacyDateAndTimeFormat()) {
setFormat(rs.getObject(i + 1), dateFormat, i);
} else {
values[i] = rs.getString(i + 1);
}
break;
case Types.TIMESTAMP:
setFormat(rs.getObject(i + 1), timestampFormat, i);
if (!sqlLine.getOpts().getlegacyDateAndTimeFormat()) {
setFormat(rs.getObject(i + 1), timestampFormat, i);
} else {
values[i] = rs.getString(i + 1);
}
break;
default:
values[i] = rs.getString(i + 1);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/sqlline/SqlLineOpts.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import static sqlline.BuiltInProperty.INCREMENTAL_BUFFER_ROWS;
import static sqlline.BuiltInProperty.ISOLATION;
import static sqlline.BuiltInProperty.KEEP_SEMICOLON;
import static sqlline.BuiltInProperty.LEGACY_DATE_AND_TIME_FOMRAT;
import static sqlline.BuiltInProperty.LIVE_TEMPLATES;
import static sqlline.BuiltInProperty.MAX_COLUMN_WIDTH;
import static sqlline.BuiltInProperty.MAX_HEIGHT;
Expand Down Expand Up @@ -965,6 +966,10 @@ public void setMode(String mode) {
}
}

public boolean getlegacyDateAndTimeFormat() {
return getBoolean(LEGACY_DATE_AND_TIME_FOMRAT);
}

public void setOutputFormat(String outputFormat) {
if (DEFAULT.equalsIgnoreCase(outputFormat)) {
set(OUTPUT_FORMAT, OUTPUT_FORMAT.defaultValue());
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/sqlline/SqlLine.properties
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ variables:\
\nmode emacs/vi The editing mode\
\nnullValue String Use String in place of NULL values\
\nnumberFormat pattern Format numbers using DecimalFormat pattern\
\nlegacyDateAndTimeFormat true/false Enables legacy output format for DATE,\
\n TIME and TIMESTAMP data types\
\noutputFormat table/vertical/csv/tsv/xmlattrs/xmlelements/json/ansiconsole\
\n Format mode for result display\
\nprompt pattern Format prompt\
Expand Down Expand Up @@ -367,6 +369,8 @@ cmd-usage: Usage: java sqlline.SqlLine \n \
\ --mode=[emacs/vi] the editing mode\n \
\ --silent=[true/false] be more silent\n \
\ --autosave=[true/false] automatically save preferences\n \
\ --legacyDateAndTimeFormat=[true/false] Enables legacy output format for DATE,\n \
\ TIME and TIMESTAMP data types\n \
\ --outputformat=[table/vertical/csv/tsv/xmlattrs/xmlelements/json/ansiconsole]\n \
\ format mode for result display\n \
\ --isolation=LEVEL set the transaction isolation level\n \
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/sqlline/manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2271,6 +2271,7 @@ maxwidth
mode
nullValue
numberformat
legacyDateAndTimeFormat
outputformat
prompt
rightprompt
Expand Down Expand Up @@ -2392,6 +2393,10 @@ numberformat

The format for how numeric values are displayed. Setting to default causes numeric values to be fetched and rendered via ResultSet.getString. Any other setting results in fetch via ResultSet.getObject and rendering via java.text.DecimalFormat. For example, the setting "0.###E0" yields scientific notation with up to three fractional digits, values like "6.022E23".

legacyDateAndTimeFormat

Enables legacy output format for DATE, TIME and TIMESTAMP data types

outputformat

The format for how results are displayed. For details, see the information on the outputformat command.
Expand Down