Package sqlline
Class SqlLine
- java.lang.Object
-
- sqlline.SqlLine
-
public class SqlLine extends 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 String
COMMAND_PREFIX
static String
SQLLINE_BASE_DIR
-
Constructor Summary
Constructors Constructor Description SqlLine()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SqlLine.Status
begin(String[] args, 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(String msg)
boolean
error(String msg)
Issue the specified error messageboolean
error(Throwable t)
org.jline.reader.Completer
getCommandCompleter()
Collection<CommandHandler>
getCommandHandlers()
org.jline.reader.LineReader
getConsoleReader(InputStream inputStream, org.jline.reader.History fileHistory)
HighlightStyle
getHighlightStyle()
SqlLineOpts
getOpts()
Map<String,OutputFormat>
getOutputFormats()
sqlline.Reflector
getReflector()
static String
getSeparator()
void
handleException(Throwable e)
void
info(String msg)
void
info(sqlline.ColorBuffer msg)
boolean
isExit()
static void
main(String[] args)
Starts the program.static SqlLine.Status
mainWithInputRedirection(String[] args, InputStream inputStream)
Starts the program with redirected input.void
output(String msg)
Print the specified message to the consolevoid
output(String msg, boolean newline)
Print the specified message to the consolevoid
output(String msg, boolean newline, PrintStream out)
void
output(sqlline.ColorBuffer msg)
void
output(sqlline.ColorBuffer msg, boolean newline)
void
output(sqlline.ColorBuffer msg, boolean newline, PrintStream out)
int
runCommands(List<String> cmds, DispatchCallback callback)
void
setErrorStream(PrintStream errorStream)
void
setExit(boolean exit)
void
setOpts(SqlLineOpts opts)
void
setOutputStream(PrintStream outputStream)
String[]
split(String line, String delim, int limit)
String[][]
splitCompound(String line)
Splits the line into an array of possibly-compound identifiers, observing the database's quoting syntax.static SqlLine.Status
start(String[] args, 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(Collection<CommandHandler> commandHandlers)
void
updateOutputFormats(Map<String,OutputFormat> formats)
-
-
-
Field Detail
-
COMMAND_PREFIX
public static final String COMMAND_PREFIX
- See Also:
- Constant Field Values
-
SQLLINE_BASE_DIR
public static final String SQLLINE_BASE_DIR
- See Also:
- Constant Field Values
-
-
Method Detail
-
main
public static void main(String[] args) throws IOException
Starts the program.- Parameters:
args
- Arguments specified on the command-line- Throws:
IOException
- on error
-
mainWithInputRedirection
public static SqlLine.Status mainWithInputRedirection(String[] args, InputStream inputStream) throws IOException
Starts the program with redirected input.For redirected output, use
setOutputStream(java.io.PrintStream)
andsetErrorStream(java.io.PrintStream)
.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:
IOException
- on error
-
start
public static SqlLine.Status start(String[] args, InputStream inputStream, boolean saveHistory) throws IOException
Backwards 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:
IOException
- if SQLLine cannot obtain history file or start console reader
-
begin
public SqlLine.Status begin(String[] args, InputStream inputStream, boolean saveHistory) throws IOException
Runs 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(PrintStream)
and/orsetErrorStream(PrintStream)
.- Parameters:
args
- Command-line argumentsinputStream
- Input streamsaveHistory
- Whether to save the commands issued to SQLLine's history file- Returns:
- exit status
- Throws:
IOException
- if SQLLine cannot obtain history file or start console reader
-
getConsoleReader
public org.jline.reader.LineReader getConsoleReader(InputStream inputStream, org.jline.reader.History fileHistory) throws IOException
- Throws:
IOException
-
output
public void output(String msg)
Print the specified message to the console- Parameters:
msg
- the message to print
-
info
public void info(String msg)
-
info
public void info(sqlline.ColorBuffer msg)
-
error
public boolean error(String msg)
Issue the specified error message- Parameters:
msg
- the message to issue- Returns:
- false always
-
error
public boolean error(Throwable t)
-
debug
public void debug(String msg)
-
output
public void output(sqlline.ColorBuffer msg)
-
output
public void output(String msg, boolean newline, PrintStream out)
-
output
public void output(sqlline.ColorBuffer msg, boolean newline)
-
output
public void output(sqlline.ColorBuffer msg, boolean newline, PrintStream out)
-
output
public void output(String msg, boolean newline)
Print the specified message to the console- Parameters:
msg
- the message to printnewline
- if false, do not append a newline
-
splitCompound
public String[][] splitCompound(String line)
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 up- Returns:
- an array of compound words
-
handleException
public void handleException(Throwable e)
-
runCommands
public int runCommands(List<String> cmds, DispatchCallback callback)
-
getOpts
public SqlLineOpts getOpts()
-
setOpts
public void setOpts(SqlLineOpts opts)
-
isExit
public boolean isExit()
-
setExit
public void setExit(boolean exit)
-
getSeparator
public static String getSeparator()
-
setOutputStream
public void setOutputStream(PrintStream outputStream)
-
setErrorStream
public void setErrorStream(PrintStream errorStream)
-
getReflector
public sqlline.Reflector getReflector()
-
getCommandCompleter
public org.jline.reader.Completer getCommandCompleter()
-
getHighlightStyle
public HighlightStyle getHighlightStyle()
-
getCommandHandlers
public Collection<CommandHandler> getCommandHandlers()
-
updateCommandHandlers
public void updateCommandHandlers(Collection<CommandHandler> commandHandlers)
-
getOutputFormats
public Map<String,OutputFormat> getOutputFormats()
-
updateOutputFormats
public void updateOutputFormats(Map<String,OutputFormat> formats)
-
-