Package sqlline

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

      • SqlLine

        public SqlLine()
    • 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
      • start

        public static SqlLine.Status start​(String[] args,
                                           InputStream inputStream,
                                           boolean saveHistory)
                                    throws 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:
        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 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:
        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​(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 print
        newline - 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)
      • 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()