Package sqlline

Class 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
    • Constructor Detail

      • SqlLine

        public SqlLine()
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
                         throws java.io.IOException
        Starts 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.IOException
        Starts the program with redirected input.

        For redirected output, use setOutputStream(java.io.PrintStream) and setErrorStream(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:
        java.io.IOException - on error
      • start

        public static SqlLine.Status start​(java.lang.String[] args,
                                           java.io.InputStream inputStream,
                                           boolean saveHistory)
                                    throws java.io.IOException
        Backwards compatibility method to allow mainWithInputRedirection(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 from main(String[])
        inputStream - Stream to read sql commands from (stdin or a file) or null for an interactive shell
        saveHistory - 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.IOException
        Runs SQLLine, accepting input from the given input stream, dispatching it to the appropriate CommandHandler until the global variable exit is true.

        Before you invoke this method, you can redirect output by calling setOutputStream(PrintStream) and/or setErrorStream(PrintStream).

        Parameters:
        args - Command-line arguments
        inputStream - Input stream
        saveHistory - 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)
        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
        keepSqlIdentifierQuotes - keep SQL identifiers
        Returns:
        an array of compound words
      • splitCompound

        public java.lang.String[][] splitCompound​(java.lang.String line)
      • 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

        public int runCommands​(java.util.List<java.lang.String> cmds,
                               DispatchCallback callback)
      • isExit

        public boolean isExit()
      • setExit

        public void setExit​(boolean exit)
      • getSeparator

        public static java.lang.String getSeparator()
      • setOutputStream

        public void setOutputStream​(java.io.PrintStream outputStream)
      • setErrorStream

        public void setErrorStream​(java.io.PrintStream errorStream)
      • getReflector

        public sqlline.Reflector getReflector()
      • getCommandCompleter

        public org.jline.reader.Completer getCommandCompleter()
      • getCommandHandlers

        public java.util.Collection<CommandHandler> getCommandHandlers()
      • updateCommandHandlers

        public void updateCommandHandlers​(java.util.Collection<CommandHandler> commandHandlers)
      • getOutputFormats

        public java.util.Map<java.lang.String,​OutputFormat> getOutputFormats()
      • updateOutputFormats

        public void updateOutputFormats​(java.util.Map<java.lang.String,​OutputFormat> formats)
      • updatePromptHandler

        public void updatePromptHandler​(PromptHandler promptHandler)