Permalink
Browse files

- The "showbinary" setting has been renamed to "maxbinary".

- Added a "maxcompletions" setting, controlling how many possible completions
  are shown when tab-completion results in multiple choices.
  • Loading branch information...
1 parent ca8b19e commit 5c7d1f5b7d39004a1eae88439d15a2a26b296cbf @bmc committed Mar 9, 2010
View
@@ -1,10 +1,14 @@
Version 0.5 (...)
- Fixed a command completion error in the ".show" command.
+- Completions are now displayed in a columnar fashion.
- SQLShell now supports --sqlshell-block-begin and --sqlshell-block-end
structured comments, used to delineate multi-statement SQL that must be
run all at once, such as stored procedure definitions. See the User's
Guide for details.
+- The "showbinary" setting has been renamed to "maxbinary".
+- Added a "maxcompletions" setting, controlling how many possible completions
+ are shown when tab-completion results in multiple choices.
- SQLShell now permits setting the primary prompt, via ".set prompt".
The prompt string can contain escapes, such as "%db%" (which substitutes
the current database name) and "%user%" (which substitutes the name of
View
Binary file not shown.
View
@@ -3,6 +3,9 @@
structured comments, used to delineate multi-statement SQL that must be
run all at once, such as stored procedure definitions. See the User's
Guide for complete details.
+* The `showbinary` setting has been renamed to `maxbinary`.
+* Added a `maxcompletions` setting, controlling how many possible completions
+ are shown when tab-completion results in multiple choices.
* SQLShell now permits setting the primary prompt, via ".set prompt".
The prompt string can contain escapes, such as `"%db%"` (which substitutes
the current database name) and `"%user%"` (which substitutes the name of
View
@@ -176,7 +176,7 @@ The following file specifies the same databases as in the examples, above:
# sqlshell initialization file
[settings]
- showbinary: 20
+ maxbinary: 20
[db.testdb]
aliases: sqlite, test
@@ -345,7 +345,7 @@ settings that are understood by the `.set` command. See the description of
[settings]
# Show up to 20 characters of CLOB and BLOB data
- showbinary: 20
+ maxbinary: 20
#### The [drivers] section
@@ -529,10 +529,10 @@ transcript, to whet your appetite:
catalog:
echo: false
logging: info
+ maxbinary: 20
maxhistory: 2147483647
prompt: sqlshell>
schema: public
- showbinary: 20
showresults: true
showrowcount: true
showtimings: true
@@ -887,10 +887,10 @@ See **Command History** for a complete explanation of SQLShell's
catalog:
echo: false
logging: info
+ maxbinary: 20
maxhistory: 2147483647
prompt: sqlshell>
schema:
- showbinary: 20
showrowcount: true
showtimings: true
sortcolnames: false
@@ -935,6 +935,19 @@ See **Command History** for a complete explanation of SQLShell's
> to the screen. Legal values are, in order of verbosity: `error`, `info`,
> `verbose`, `warning`, `debug`. **Default:** `info`
>
+> * `maxbinary`: How many bytes or characters to display from binary (BLOB,
+> CLOB, LONGVARCHAR, etc.) columns. For non-character columns like BLOBs,
+> the bytes are displayed as two-character hexadecimal strings. If this
+> setting is 0, then SQLShell will not retrieve binary values and will display
+> placeholder strings like `<binary>` and `<clob>`, instead. **Default:** 0
+>
+> * `maxcompletions`: The maximum number of possible completions to show.
+> This setting comes into play when you press the TAB key to complete a
+> string, and there are multiple possible completions for the string.
+> SQLShell will display up to `maxcompletions` of those possible completions,
+> in a columnar form, on the screen. If this setting is 0, then SQLShell
+> will display all of the possible completions. **Default:** 30
+>
> * `maxhistory`: Sets the maximum number of entries in the command history.
> **Default:** A really large number (the largest possible signed 32-bit
> integer, 2147483647).
@@ -958,12 +971,6 @@ See **Command History** for a complete explanation of SQLShell's
> value may also be initialized in the configuration section for the database.
> **Default:** none
>
-> * `showbinary`: How many bytes or characters to display from binary (BLOB,
-> CLOB, LONGVARCHAR, etc.) columns. For non-character columns like BLOBs,
-> the bytes are displayed as two-character hexadecimal strings. If this
-> setting is 0, then SQLShell will not retrieve binary values and will display
-> placeholder strings like `<binary>` and `<clob>`, instead. **Default:** 0
->
> * `showrowcount`: Whether or not to display the number of rows retrieved or
> affected by a SQL statement. **Default:** on
>
@@ -106,6 +106,15 @@ class MaxHistorySetting(readline: Readline)
readline.history.max = newValue.asInstanceOf[Int]
}
+class MaxCompletionsSetting(readline: Readline)
+ extends Setting with IntValueConverter
+{
+ override def get = readline.maxShownCompletions
+
+ override def set(newValue: Any) =
+ readline.maxShownCompletions = newValue.asInstanceOf[Int]
+}
+
/**
* Handles enabling/disabling verbose messages.
*/
@@ -163,19 +172,20 @@ class SQLShell(val config: Configuration,
AnsiSetting.set(useAnsiColors)
val settings = new Settings(
- ("ansi", AnsiSetting),
- ("catalog", new StringSetting("")),
- ("echo", new BooleanSetting(false)),
- ("logging", LogLevelSetting),
- ("maxhistory", new MaxHistorySetting(readline)),
- ("prompt", new StringSetting(Constants.DefaultPrimaryPrompt)),
- ("schema", new StringSetting("")),
- ("showbinary", new IntSetting(0)),
- ("showresults", new BooleanSetting(true)),
- ("showrowcount", new BooleanSetting(true)),
- ("showtimings", new BooleanSetting(true)),
- ("sortcolnames", new BooleanSetting(false)),
- ("stacktrace", new BooleanSetting(showStackTraces))
+ ("ansi", AnsiSetting),
+ ("catalog", new StringSetting("")),
+ ("echo", new BooleanSetting(false)),
+ ("logging", LogLevelSetting),
+ ("maxbinary", new IntSetting(0)),
+ ("maxcompletions", new MaxCompletionsSetting(readline)),
+ ("maxhistory", new MaxHistorySetting(readline)),
+ ("prompt", new StringSetting(Constants.DefaultPrimaryPrompt)),
+ ("schema", new StringSetting("")),
+ ("showresults", new BooleanSetting(true)),
+ ("showrowcount", new BooleanSetting(true)),
+ ("showtimings", new BooleanSetting(true)),
+ ("sortcolnames", new BooleanSetting(false)),
+ ("stacktrace", new BooleanSetting(showStackTraces))
)
// List of command handlers.
@@ -1018,7 +1028,7 @@ trait ResultSetHandler
def closeResultSetHandler: Unit = return
}
-abstract class ResultSetStringifier(showBinary: Int)
+abstract class ResultSetStringifier(maxBinary: Int)
{
private val DateFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.S")
@@ -1052,7 +1062,7 @@ abstract class ResultSetStringifier(showBinary: Int)
def clobString(i: Int): String =
{
- if (showBinary == 0)
+ if (maxBinary == 0)
"<clob>"
else
@@ -1068,13 +1078,13 @@ abstract class ResultSetStringifier(showBinary: Int)
// Read one more than the binary length. If we get
// that many, then display an ellipsis.
- val buf = r.readSome(showBinary + 1)
+ val buf = r.readSome(maxBinary + 1)
buf.length match
{
- case 0 => ""
- case n if (n > showBinary) => buf.mkString("") +
- "..."
- case n => buf.mkString("")
+ case 0 => ""
+ case n if (n > maxBinary) => buf.mkString("") +
+ "..."
+ case n => buf.mkString("")
}
}
}
@@ -1083,7 +1093,7 @@ abstract class ResultSetStringifier(showBinary: Int)
def binaryString(i: Int): String =
{
- if (showBinary == 0)
+ if (maxBinary == 0)
"<blob>"
else
@@ -1099,8 +1109,8 @@ abstract class ResultSetStringifier(showBinary: Int)
// Read one more than the binary length. If we get
// that many, then display an ellipsis.
- val buf = is.readSome(showBinary + 1)
- val ellipsis = buf.length > showBinary
+ val buf = is.readSome(maxBinary + 1)
+ val ellipsis = buf.length > maxBinary
val hexList =
{
for (b <- buf)
@@ -1291,8 +1301,8 @@ private[sqlshell] trait SelectResultSetHandler extends ResultSetHandler
* Used by the select handler to process and cache a result set.
*/
private[sqlshell] class ResultSetCacheHandler(tempFile: File,
- val showBinary: Int)
- extends ResultSetStringifier(showBinary) with SelectResultSetHandler
+ val maxBinary: Int)
+ extends ResultSetStringifier(maxBinary) with SelectResultSetHandler
{
import java.io.{FileOutputStream, ObjectOutputStream}
@@ -1479,8 +1489,8 @@ class SelectHandler(shell: SQLShell, connection: Connection)
logger.verbose("Processing results...")
val metadata = rs.getMetaData
- val showBinary = shell.settings.intSetting("showbinary")
- val cacheHandler = new ResultSetCacheHandler(tempFile, showBinary)
+ val maxBinary = shell.settings.intSetting("maxbinary")
+ val cacheHandler = new ResultSetCacheHandler(tempFile, maxBinary)
val noCacheHandler = new ResultSetNoCacheHandler
val resultHandler =
if (shell.settings.booleanSettingIsTrue("showresults"))
@@ -1655,10 +1665,10 @@ class CaptureHandler(shell: SQLShell, selectHandler: SelectHandler)
|headers, until it sees ".capture off".""".stripMargin
private val HandlerKey = this.getClass.getName
- private val showBinary = shell.settings.intSetting("showbinary")
+ private val maxBinary = shell.settings.intSetting("maxbinary")
private class SaveToCSVHandler(path: File)
- extends ResultSetStringifier(showBinary) with ResultSetHandler
+ extends ResultSetStringifier(maxBinary) with ResultSetHandler
{
import java.io.{FileOutputStream, OutputStreamWriter}
@@ -2537,6 +2547,8 @@ class DescribeHandler(val shell: SQLShell,
class ShowHandler(val shell: SQLShell, val connection: Connection)
extends SQLShellCommandHandler with Wrapper with Sorter
{
+ import grizzled.collection.GrizzledLinearSeq.Implicits._
+
val CommandName = ".show"
val Help =
"""|Show various useful things.
@@ -2655,7 +2667,7 @@ class ShowHandler(val shell: SQLShell, val connection: Connection)
val tables: List[TableSpec] = shell.getTables(schemaOption, nameFilter)
val tableNames = tables.filter(_.name != None).map(_.name.get)
val sorted = sortByName(tableNames)
- print(shell.columnarize(sorted, shell.OutputWidth))
+ print(sorted.columnarize(shell.OutputWidth))
KeepGoing
}
@@ -2664,6 +2676,6 @@ class ShowHandler(val shell: SQLShell, val connection: Connection)
{
val schemas = shell.getSchemas
val sorted = sortByName(schemas)
- print(shell.columnarize(sorted, shell.OutputWidth))
+ print(sorted.columnarize(shell.OutputWidth))
}
}
@@ -119,7 +119,7 @@ object Tool
{
import java.util.Arrays.asList
import java.util.{List => JList}
- import grizzled.collection.implicits._
+ import scala.collection.JavaConversions._
val parser = new OptionParser
@@ -177,7 +177,10 @@ object Tool
val showAnsi = ! options.has("n")
val positionalParams =
- (for (s <- options.nonOptionArguments) yield s).toList
+ {
+ for (s <- JListWrapper(options.nonOptionArguments))
+ yield s
+ }.toList
if (positionalParams.length == 0)
throw new CommandLineException("Missing parameter(s).")
@@ -210,9 +213,11 @@ object Tool
val readlineLibNames =
if (options.has("r"))
- {for (v <- options.valuesOf("r")
- .asInstanceOf[JList[String]])
- yield(v)}.toList
+ {
+ val names: scala.collection.mutable.Buffer[String] =
+ options.valuesOf("r").asInstanceOf[JList[String]]
+ names.toList
+ }
else
Nil

0 comments on commit 5c7d1f5

Please sign in to comment.