Skip to content

Commit

Permalink
[SQLLINE-39] '!help set' shouldn't break long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
julianhyde committed Jan 18, 2016
1 parent 6049893 commit dcda196
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 66 deletions.
11 changes: 11 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

For a full list of releases, see <a href="https://github.com/julianhyde/sqlline/releases">github</a>.

## <a href="https://github.com/julianhyde/sqlline/releases/tag/sqlline-1.1.10">1.1.10</a> (under development)

Bugs and functional changes:

* [<a href="https://github.com/julianhyde/sqlline/issues/39">SQLLINE-39</a>]
`!help set` shouldn't break long lines
* Add `WrappedSqlException` to allow `IncrementalRows` to throw a `SQLException`
(Parth Chandra)
* Switch to "scott-data-hsqldb" as test data set; it is smaller than
"foodmart-data-hsqldb"

## <a href="https://github.com/julianhyde/sqlline/releases/tag/sqlline-1.1.9">1.1.9</a> (2015-03-06)

No bug fixes or other functional changes
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/sqlline/SqlLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1432,16 +1432,19 @@ String wrap(String toWrap, int len, int start) {
char[] head = new char[start];
Arrays.fill(head, ' ');

for (
StringTokenizer tok = new StringTokenizer(toWrap, " ");
for (StringTokenizer tok = new StringTokenizer(toWrap, " ");
tok.hasMoreTokens();) {
String next = tok.nextToken();
if (line.length() + next.length() > len) {
final int x = line.length();
line.append(line.length() == 0 ? "" : " ").append(next);
if (line.length() > len) {
// The line is now too long. Backtrack: remove the last word, start a
// new line containing just that word.
line.setLength(x);
buff.append(line).append(SEPARATOR).append(head);
line.setLength(0);
line.append(next);
}

line.append(line.length() == 0 ? "" : " ").append(next);
}

buff.append(line);
Expand Down
116 changes: 58 additions & 58 deletions src/main/resources/sqlline/SqlLine.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,65 +49,65 @@ help-commit: Commit the current transaction (if autocommit is off)
help-rollback: Roll back the current transaction (if autocommit is off)
help-batch: Start or execute a batch of statements
help-help: Print a summary of command usage
help-set: Set a sqlline variable\n\
help-set: Set a sqlline variable\
\n\
Variable Value Description\n\
=============== ========== ================================\n\
autoCommit true/false Enable/disable automatic\n\
transaction commit\n\
autoSave true/false Automatically save preferences\n\
color true/false Control whether color is used\n\
for display\n\
fastConnect true/false Skip building table/column list\n\
for tab-completion\n\
force true/false Continue running script even\n\
after errors\n\
headerInterval integer The interval between which\n\
headers are displayed\n\
historyFile path File in which to save command\n\
history. Default is\n\
$HOME/.sqlline/history (UNIX,\n\
Linux, Mac OS),\n\
$HOME/sqlline/history (Windows)\n\
incremental true/false Do not receive all rows from\n\
server before printing the first\n\
row. Uses fewer resources,\n\
especially for long-running\n\
queries, but column widths may\n\
be incorrect.\n\
isolation LEVEL Set transaction isolation level\n\
maxColumnWidth integer The maximum width to use when\n\
displaying columns\n\
maxHeight integer The maximum height of the\n\
terminal\n\
maxWidth integer The maximum width of the\n\
terminal\n\
numberFormat pattern Format numbers using\n\
DecimalFormat pattern\n\
outputFormat table/vertical/csv/tsv Format mode for\n\
result display\n\
propertiesFile path File from which SqlLine reads\n\
properties on startup; default is\n\
$HOME/.sqlline/sqlline.properties\n\
(UNIX, Linux, Mac OS),\n\
$HOME/sqlline/sqlline.properties\n\
(Windows)\n\
rowLimit integer Maximum number of rows returned\n\
from a query; zero means no\n\
limit\n\
showElapsedTime true/false Display execution time when\n\
verbose\n\
showHeader true/false Show column names in query\n\
results\n\
showNestedErrs true/false Display nested errors\n\
showWarnings true/false Display connection warnings\n\
silent true/false Be more silent\n\
timeout integer Query timeout in seconds; less\n\
than zero means no timeout\n\
trimScripts true/false Remove trailing spaces from\n\
lines read from script files\n\
verbose true/false Show verbose error messages and\n\
debug info
\nVariable Value Description\
\n=============== ========== ================================\
\nautoCommit true/false Enable/disable automatic\
\n transaction commit\
\nautoSave true/false Automatically save preferences\
\ncolor true/false Control whether color is used\
\n for display\
\nfastConnect true/false Skip building table/column list\
\n for tab-completion\
\nforce true/false Continue running script even\
\n after errors\
\nheaderInterval integer The interval between which\
\n headers are displayed\
\nhistoryFile path File in which to save command\
\n history. Default is\
\n $HOME/.sqlline/history (UNIX,\
\n Linux, Mac OS),\
\n $HOME/sqlline/history (Windows)\
\nincremental true/false Do not receive all rows from\
\n server before printing the first\
\n row. Uses fewer resources,\
\n especially for long-running\
\n queries, but column widths may\
\n be incorrect.\
\nisolation LEVEL Set transaction isolation level\
\nmaxColumnWidth integer The maximum width to use when\
\n displaying columns\
\nmaxHeight integer The maximum height of the\
\n terminal\
\nmaxWidth integer The maximum width of the\
\n terminal\
\nnumberFormat pattern Format numbers using\
\n DecimalFormat pattern\
\noutputFormat table/vertical/csv/tsv Format mode for\
\n result display\
\npropertiesFile path File from which SqlLine reads\
\n properties on startup; default is\
\n $HOME/.sqlline/sqlline.properties\
\n (UNIX, Linux, Mac OS),\
\n $HOME/sqlline/sqlline.properties\
\n (Windows)\
\nrowLimit integer Maximum number of rows returned\
\n from a query; zero means no\
\n limit\
\nshowElapsedTime true/false Display execution time when\
\n verbose\
\nshowHeader true/false Show column names in query\
\n results\
\nshowNestedErrs true/false Display nested errors\
\nshowWarnings true/false Display connection warnings\
\nsilent true/false Be more silent\
\ntimeout integer Query timeout in seconds; less\
\n than zero means no timeout\
\ntrimScripts true/false Remove trailing spaces from\
\n lines read from script files\
\nverbose true/false Show verbose error messages and\
\n debug info
help-save: Save the current variabes and aliases
help-native: Show the database''s native SQL for a command
help-alias: Create a new command alias
Expand Down
29 changes: 26 additions & 3 deletions src/test/java/sqlline/SqlLineArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,16 @@ public void testClose() throws Throwable {
*/
@Test
public void testHelpSet() throws Throwable {
final String expected = "1/1 !help set\n"
+ "!set Set a sqlline variable\n"
+ "\n"
+ "Variable Value Description\n"
+ "=============== ========== ================================\n"
+ "autoCommit true/false Enable/disable automatic\n"
+ " transaction commit\n"
+ "autoSave true/false Automatically save preferences\n";
checkScriptFile("!help set\n", false, equalTo(SqlLine.Status.OK),
containsString(
"1/1 !help set\n"
+ "!set Set a sqlline variable\n"));
containsString(expected));

// Make sure that each variable (autoCommit, autoSave, color, etc.) has a
// line in the output of '!help set'
Expand Down Expand Up @@ -206,6 +212,23 @@ public void testHelpSet() throws Throwable {
}
}

/**
* Test case for [SQLLINE-39], "'help set' shouldn't break long lines".
*
* <p>But it should break 'help all', which consists of a single long line.
*/
@Test
public void testHelpAll() throws Throwable {
// Note that "connections" has been broken onto a new line.
final String expected = "1/1 !help all\n"
+ "!all Execute the specified SQL against all the current\n"
+ " connections\n"
+ "Closing: org.hsqldb.jdbc.JDBCConnection\n"
+ "sqlline version ???\n";
checkScriptFile("!help all\n", false, equalTo(SqlLine.Status.OK),
is(expected));
}

/**
* Test case for [SQLLINE-26], "Flush output for each command when using
* !record command."
Expand Down

0 comments on commit dcda196

Please sign in to comment.