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 classSqlLine.StatusExit status returned to the operating system. -
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCOMMAND_PREFIXstatic java.lang.StringSQLLINE_BASE_DIR -
Constructor Summary
Constructors Constructor Description SqlLine() -
Method Summary
Modifier and Type Method Description SqlLine.Statusbegin(java.lang.String[] args, java.io.InputStream inputStream, boolean saveHistory)Runs SQLLine, accepting input from the given input stream, dispatching it to the appropriateCommandHandleruntil the global variableexitis true.voiddebug(java.lang.String msg)booleanerror(java.lang.String msg)Issue the specified error messagebooleanerror(java.lang.Throwable t)org.jline.reader.CompletergetCommandCompleter()java.util.Collection<CommandHandler>getCommandHandlers()ConnectionMetadatagetConnectionMetadata()org.jline.reader.LineReadergetConsoleReader(java.io.InputStream inputStream, org.jline.reader.History fileHistory)HighlightStylegetHighlightStyle()SqlLineOptsgetOpts()java.util.Map<java.lang.String,OutputFormat>getOutputFormats()PromptHandlergetPromptHandler()sqlline.ReflectorgetReflector()static java.lang.StringgetSeparator()voidhandleException(java.lang.Throwable e)voidinfo(java.lang.String msg)voidinfo(org.jline.utils.AttributedString msg)booleanisExit()static voidmain(java.lang.String[] args)Starts the program.static SqlLine.StatusmainWithInputRedirection(java.lang.String[] args, java.io.InputStream inputStream)Starts the program with redirected input.voidoutput(java.lang.String msg)Print the specified message to the consolevoidoutput(java.lang.String msg, boolean newline, java.io.PrintStream out)voidoutput(org.jline.utils.AttributedString msg)voidoutput(org.jline.utils.AttributedString msg, boolean newline)voidoutput(org.jline.utils.AttributedString msg, boolean newline, java.io.PrintStream out)intrunCommands(java.util.List<java.lang.String> cmds, DispatchCallback callback)voidsetErrorStream(java.io.OutputStream errorStream)voidsetExit(boolean exit)voidsetOpts(SqlLineOpts opts)voidsetOutputStream(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.Statusstart(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.voidupdateCommandHandlers(java.util.Collection<CommandHandler> commandHandlers)voidupdateOutputFormats(java.util.Map<java.lang.String,OutputFormat> formats)voidupdatePromptHandler(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 appropriateCommandHandleruntil the global variableexitis 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
-