public void run ( String line , DispatchCallback callback ) { String filename ; if ( line . length ( ) == "run" . length ( ) || ( filename = sqlLine . dequote ( line . substring ( "run" . length ( ) + 1 ) ) ) == null ) { sqlLine . error ( "Usage: run <file name>" ) ; callback . setToFailure ( ) ; return ; } List < String > cmds = new LinkedList <> ( ) ; try { final Parser parser = sqlLine . getLineReader ( ) . getParser ( ) ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( new FileInputStream ( expand ( filename ) ) , StandardCharsets . UTF_8 ) ) ) { // ### NOTE: fix for sf.net bug 879427 final StringBuilder cmd = new StringBuilder ( ) ; boolean needsContinuation ; for ( ; ; ) { final String scriptLine = reader . readLine ( ) ; if ( scriptLine == null ) { break ; } // we're continuing an existing command cmd . append ( " \n" ) ; cmd . append ( scriptLine ) ; try { needsContinuation = false ; parser . parse ( cmd . toString ( ) , cmd . length ( ) , Parser . ParseContext . ACCEPT_LINE ) ; } catch ( EOFError e ) { needsContinuation = true ; } if ( ! needsContinuation && ! cmd . toString ( ) . trim ( ) . isEmpty ( ) ) { cmds . add ( maybeTrim ( cmd . toString ( ) ) ) ; cmd . setLength ( 0 ) ; } } if ( SqlLineParser . isSql ( sqlLine , cmd . toString ( ) , Parser . ParseContext . ACCEPT_LINE ) ) { // ### REVIEW: oops, somebody left the last command // unterminated; should we fix it for them or complain? // For now be nice and fix it. cmd . append ( ";" ) ; cmds . add ( cmd . toString ( ) ) ; } } // success only if all the commands were successful if ( sqlLine . runCommands ( cmds , callback ) == cmds . size ( ) ) { callback . setToSuccess ( ) ; } else { callback . setToFailure ( ) ; } } catch ( Exception e ) { callback . setToFailure ( ) ; sqlLine . error ( e ) ; } }
Runs a script from the specified file .