Package sqlline
Class SqlLine
java.lang.Object
sqlline.SqlLine
public class SqlLine
extends java.lang.Object
A console SQL shell with command completion.
TODO:
- Page results
- Handle binary data (blob fields)
- Implement command aliases
- Stored procedure execution
- Binding parameters to prepared statements
- Scripting language
- XA transactions
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SqlLine.Status
Exit status returned to the operating system. -
Field Summary
Fields Modifier and Type Field Description static java.lang.String
COMMAND_PREFIX
static java.lang.String
SQLLINE_BASE_DIR
-
Constructor Summary
Constructors Constructor Description SqlLine()
-
Method Summary
Modifier and Type Method Description SqlLine.Status
begin(java.lang.String[] args, java.io.InputStream inputStream, boolean saveHistory)
Runs SQLLine, accepting input from the given input stream, dispatching it to the appropriateCommandHandler
until the global variableexit
is true.void
debug(java.lang.String msg)
boolean
error(java.lang.String msg)
Issue the specified error messageboolean
error(java.lang.Throwable t)
org.jline.reader.Completer
getCommandCompleter()
java.util.Collection<CommandHandler>
getCommandHandlers()
ConnectionMetadata
getConnectionMetadata()
org.jline.reader.LineReader
getConsoleReader(java.io.InputStream inputStream, org.jline.reader.History fileHistory)
HighlightStyle
getHighlightStyle()
SqlLineOpts
getOpts()
java.util.Map<java.lang.String,OutputFormat>
getOutputFormats()
PromptHandler
getPromptHandler()
sqlline.Reflector
getReflector()
static java.lang.String
getSeparator()
void
handleException(java.lang.Throwable e)
void
info(java.lang.String msg)
void
info(org.jline.utils.AttributedString msg)
boolean
isExit()
static void
main(java.lang.String[] args)
Starts the program.static SqlLine.Status
mainWithInputRedirection(java.lang.String[] args, java.io.InputStream inputStream)
Starts the program with redirected input.void
output(java.lang.String msg)
Print the specified message to the consolevoid
output(java.lang.String msg, boolean newline, java.io.PrintStream out)
void
output(org.jline.utils.AttributedString msg)
void
output(org.jline.utils.AttributedString msg, boolean newline)
void
output(org.jline.utils.AttributedString msg, boolean newline, java.io.PrintStream out)
int
runCommands(java.util.List<java.lang.String> cmds, DispatchCallback callback)
void
setErrorStream(java.io.OutputStream errorStream)
void
setExit(boolean exit)
void
setOpts(SqlLineOpts opts)
void
setOutputStream(java.io.OutputStream outputStream)
java.lang.String[]
split(java.lang.String line, java.lang.String delim, int limit)
java.lang.String[][]
splitCompound(java.lang.String line)
java.lang.String[][]
splitCompound(java.lang.String line, boolean keepSqlIdentifierQuotes)
java.lang.String[][]
splitCompound(java.lang.String line, boolean keepSqlIdentifierQuotes, boolean keepCase)
Splits the line into an array of possibly-compound identifiers, observing the database's quoting syntax.static SqlLine.Status
start(java.lang.String[] args, java.io.InputStream inputStream, boolean saveHistory)
Backwards compatibility method to allowmainWithInputRedirection(String[], java.io.InputStream)
proxied calls to keep method signature but add in new behavior of not saving queries.void
updateCommandHandlers(java.util.Collection<CommandHandler> commandHandlers)
void
updateOutputFormats(java.util.Map<java.lang.String,OutputFormat> formats)
void
updatePromptHandler(PromptHandler promptHandler)
-
Field Details
-
COMMAND_PREFIX
public static final java.lang.String COMMAND_PREFIX- See Also:
- Constant Field Values
-
SQLLINE_BASE_DIR
public static final java.lang.String SQLLINE_BASE_DIR- See Also:
- Constant Field Values
-
-
Constructor Details
-
SqlLine
public SqlLine()
-
-
Method Details
-
main
public static void main(java.lang.String[] args) throws java.io.IOExceptionStarts the program.- Parameters:
args
- Arguments specified on the command-line- Throws:
java.io.IOException
- on error
-
mainWithInputRedirection
public static SqlLine.Status mainWithInputRedirection(java.lang.String[] args, java.io.InputStream inputStream) throws java.io.IOExceptionStarts the program with redirected input.For redirected output, use
setOutputStream(java.io.OutputStream)
andsetErrorStream(java.io.OutputStream)
.Exits with 0 on success, 1 on invalid arguments, and 2 on any other error.
- Parameters:
args
- same as main()inputStream
- redirected input, or null to use standard input- Returns:
- Status code to be returned to the operating system
- Throws:
java.io.IOException
- on error
-
start
public static SqlLine.Status start(java.lang.String[] args, java.io.InputStream inputStream, boolean saveHistory) throws java.io.IOExceptionBackwards compatibility method to allowmainWithInputRedirection(String[], java.io.InputStream)
proxied calls to keep method signature but add in new behavior of not saving queries.- Parameters:
args
- args[] passed in directly frommain(String[])
inputStream
- Stream to read sql commands from (stdin or a file) or null for an interactive shellsaveHistory
- Whether to save the commands issued to SQLLine's history file- Returns:
- Whether successful
- Throws:
java.io.IOException
- if SQLLine cannot obtain history file or start console reader
-
begin
public SqlLine.Status begin(java.lang.String[] args, java.io.InputStream inputStream, boolean saveHistory) throws java.io.IOExceptionRuns SQLLine, accepting input from the given input stream, dispatching it to the appropriateCommandHandler
until the global variableexit
is true.Before you invoke this method, you can redirect output by calling
setOutputStream(OutputStream)
and/orsetErrorStream(OutputStream)
.- Parameters:
args
- Command-line argumentsinputStream
- Input streamsaveHistory
- Whether to save the commands issued to SQLLine's history file- Returns:
- exit status
- Throws:
java.io.IOException
- if SQLLine cannot obtain history file or start console reader
-
getConsoleReader
public org.jline.reader.LineReader getConsoleReader(java.io.InputStream inputStream, org.jline.reader.History fileHistory) throws java.io.IOException- Throws:
java.io.IOException
-
output
public void output(java.lang.String msg)Print the specified message to the console- Parameters:
msg
- the message to print
-
info
public void info(java.lang.String msg) -
info
public void info(org.jline.utils.AttributedString msg) -
error
public boolean error(java.lang.String msg)Issue the specified error message- Parameters:
msg
- the message to issue- Returns:
- false always
-
error
public boolean error(java.lang.Throwable t) -
debug
public void debug(java.lang.String msg) -
output
public void output(org.jline.utils.AttributedString msg) -
output
public void output(org.jline.utils.AttributedString msg, boolean newline) -
output
public void output(java.lang.String msg, boolean newline, java.io.PrintStream out) -
output
public void output(org.jline.utils.AttributedString msg, boolean newline, java.io.PrintStream out) -
splitCompound
public java.lang.String[][] splitCompound(java.lang.String line, boolean keepSqlIdentifierQuotes, boolean keepCase)Splits the line into an array of possibly-compound identifiers, observing the database's quoting syntax.For example, on Oracle, which uses double-quote (") as quote character,
!tables "My Schema"."My Table"
returns
{ {"!tables"}, {"My Schema", "My Table"} }
- Parameters:
line
- the line to break upkeepSqlIdentifierQuotes
- keep SQL identifierskeepCase
- keep case- Returns:
- an array of compound words
-
splitCompound
public java.lang.String[][] splitCompound(java.lang.String line) -
splitCompound
public java.lang.String[][] splitCompound(java.lang.String line, boolean keepSqlIdentifierQuotes) -
split
public java.lang.String[] split(java.lang.String line, java.lang.String delim, int limit) -
handleException
public void handleException(java.lang.Throwable e) -
runCommands
-
getOpts
-
setOpts
-
isExit
public boolean isExit() -
setExit
public void setExit(boolean exit) -
getSeparator
public static java.lang.String getSeparator() -
setOutputStream
public void setOutputStream(java.io.OutputStream outputStream) -
setErrorStream
public void setErrorStream(java.io.OutputStream errorStream) -
getReflector
public sqlline.Reflector getReflector() -
getCommandCompleter
public org.jline.reader.Completer getCommandCompleter() -
getHighlightStyle
-
getCommandHandlers
-
updateCommandHandlers
-
getOutputFormats
-
updateOutputFormats
-
getPromptHandler
-
updatePromptHandler
-
getConnectionMetadata
-