📄 sqlfile.java
字号:
processSQL();
} catch (BadSpecial bs) {
// BadSpecials ALWAYS have non-null getMessage().
errprintln(rb.getString(SqltoolRB.ERRORAT,
new String[] {
((file == null) ? "stdin" : file.toString()),
Integer.toString(curLinenum),
inputLine,
bs.getMessage(),
}
));
Throwable cause = bs.getCause();
if (cause != null) {
errprintln(rb.getString(SqltoolRB.CAUSEREPORT,
cause.toString()));
}
if (!continueOnError) {
throw new SqlToolError(bs);
}
} catch (SQLException se) {
errprintln("SQL " + rb.getString(SqltoolRB.ERRORAT,
new String[] {
((file == null) ? "stdin" : file.toString()),
Integer.toString(curLinenum),
lastSqlStatement,
se.getMessage(),
}));
// It's possible that we could have
// SQLException.getMessage() == null, but if so, I think
// it reasonsable to show "null". That's a DB inadequacy.
if (!continueOnError) {
throw se;
}
} catch (BreakException be) {
String msg = be.getMessage();
if (recursed) {
rollbackUncoms = false;
// Recursion level will exit by rethrowing the BE.
// We set rollbackUncoms to false because only the
// top level should detect break errors and
// possibly roll back.
} else if (msg == null || msg.equals("file")) {
break;
} else {
errprintln(rb.getString(SqltoolRB.BREAK_UNSATISFIED,
msg));
}
if (recursed ||!continueOnError) {
throw be;
}
} catch (ContinueException ce) {
String msg = ce.getMessage();
if (recursed) {
rollbackUncoms = false;
} else {
errprintln(rb.getString(SqltoolRB.CONTINUE_UNSATISFIED,
msg));
}
if (recursed ||!continueOnError) {
throw ce;
}
} catch (QuitNow qn) {
throw qn;
} catch (SqlToolError ste) {
errprint(rb.getString(SqltoolRB.ERRORAT,
new String[] {
((file == null) ? "stdin" : file.toString()),
Integer.toString(curLinenum),
inputLine,
((ste.getMessage() == null)
? "" : ste.getMessage())
}
));
if (ste.getMessage() != null) errprintln("");
Throwable cause = ste.getCause();
if (cause != null) {
errprintln(rb.getString(SqltoolRB.CAUSEREPORT,
cause.toString()));
}
if (!continueOnError) {
throw ste;
}
}
immCmdSB.setLength(0);
}
if (inComment || immCmdSB.length() != 0) {
errprintln(rb.getString(SqltoolRB.INPUT_UNTERMINATED,
immCmdSB.toString()));
throw new SqlToolError(rb.getString(
SqltoolRB.INPUT_UNTERMINATED, immCmdSB.toString()));
}
rollbackUncoms = false;
// Exiting gracefully, so don't roll back.
} catch (IOException ioe) {
throw new SqlToolError(rb.getString(
SqltoolRB.PRIMARYINPUT_ACCESSFAIL), ioe);
} catch (QuitNow qn) {
if (recursed) {
throw qn;
// Will rollback if conditions otherwise require.
// Otherwise top level will decide based upon qn.getMessage().
}
rollbackUncoms = (qn.getMessage() != null);
if (rollbackUncoms) {
errprintln(rb.getString(SqltoolRB.ABORTING, qn.getMessage()));
throw new SqlToolError(qn.getMessage());
}
return;
} finally {
closeQueryOutputStream();
if (fetchingVar != null) {
errprintln(rb.getString(SqltoolRB.PLVAR_SET_INCOMPLETE,
fetchingVar));
rollbackUncoms = true;
}
if (br != null) try {
br.close();
} catch (IOException ioe) {
throw new SqlToolError(rb.getString(
SqltoolRB.INPUTREADER_CLOSEFAIL), ioe);
}
if (rollbackUncoms && possiblyUncommitteds.get()) {
errprintln(rb.getString(SqltoolRB.ROLLINGBACK));
curConn.rollback();
possiblyUncommitteds.set(false);
}
}
}
/**
* Returns a copy of given string without a terminating semicolon.
* If there is no terminating semicolon, null is returned.
*
* @param inString Base String, which will not be modified (because
* a "copy" will be returned).
* @returns Null if inString contains no terminating semi-colon.
*/
private static String deTerminated(String inString) {
int index = inString.lastIndexOf(';');
if (index < 0) {
return null;
}
for (int i = index + 1; i < inString.length(); i++) {
if (!Character.isWhitespace(inString.charAt(i))) {
return null;
}
}
return inString.substring(0, index);
}
/**
* Utility nested Exception class for internal use only.
*
* Do not instantiate with null message.
*/
static private class BadSpecial extends AppendableException {
static final long serialVersionUID = 7162440064026570590L;
BadSpecial(String s) {
super(s);
if (s == null)
throw new RuntimeException(
"Must construct BadSpecials with non-null message");
}
BadSpecial(String s, Throwable t) {
super(s, t);
if (s == null)
throw new RuntimeException(
"Must construct BadSpecials with non-null message");
}
}
/**
* Utility nested Exception class for internal use.
* This must extend SqlToolError because it has to percolate up from
* recursions of SqlTool.execute(), yet SqlTool.execute() is public.
* Therefore, external users have no reason to specifically handle
* QuitNow.
*/
private class QuitNow extends SqlToolError {
static final long serialVersionUID = 1811094258670900488L;
public QuitNow(String s) {
super(s);
}
public QuitNow() {
super();
}
}
/**
* Utility nested Exception class for internal use.
* This must extend SqlToolError because it has to percolate up from
* recursions of SqlTool.execute(), yet SqlTool.execute() is public.
* Therefore, external users have no reason to specifically handle
* BreakException.
*/
private class BreakException extends SqlToolError {
static final long serialVersionUID = 351150072817675994L;
public BreakException() {
super();
}
public BreakException(String s) {
super(s);
}
}
/**
* Utility nested Exception class for internal use.
* This must extend SqlToolError because it has to percolate up from
* recursions of SqlTool.execute(), yet SqlTool.execute() is public.
* Therefore, external users have no reason to specifically handle
* ContinueException.
*/
private class ContinueException extends SqlToolError {
static final long serialVersionUID = 5064604160827106014L;
public ContinueException() {
super();
}
public ContinueException(String s) {
super(s);
}
}
/**
* Utility nested Exception class for internal use only.
*/
private class BadSubst extends Exception {
static final long serialVersionUID = 7325933736897253269L;
BadSubst(String s) {
super(s);
}
}
/**
* Utility nested Exception class for internal use only.
*/
private class RowError extends AppendableException {
static final long serialVersionUID = 754346434606022750L;
RowError(String s) {
super(s);
}
RowError(Throwable t) {
this(null, t);
}
RowError(String s, Throwable t) {
super(s, t);
}
}
/**
* Execute processSql/processPL/processSpecial from buffer.
*/
public void processFromBuffer()
throws BadSpecial, SQLException, SqlToolError {
historize();
if (buffer.charAt(0) == '*' && (buffer.length() < 2
|| buffer.charAt(1) != '{')) {
// Test above just means commands starting with *, EXCEPT
// for commands beginning with *{.
processPL(buffer);
return;
}
if (buffer.charAt(0) == '\\') {
processSpecial(buffer);
return;
}
processSQL();
}
/**
* Process a Buffer/History Command.
*
* Due to the nature of the goal here, we don't trim() "other" like
* we do for other kinds of commands.
*
* @param inString Complete command, less the leading ':' character.
* @throws SQLException thrown by JDBC driver.
* @throws BadSpecial special-command-specific errors.
* @throws SqlToolError all other errors.
*/
private void processBuffHist(String inString)
throws BadSpecial, SQLException, SqlToolError {
if (inString.length() < 1) {
throw new BadSpecial(rb.getString(SqltoolRB.BUFHIST_UNSPECIFIED));
}
// First handle the simple cases where user may not specify a
// command number.
char commandChar = inString.charAt(0);
String other = inString.substring(1);
if (other.trim().length() == 0) {
other = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -