| java.lang.Object henplus.SQLStatementSeparator
SQLStatementSeparator | public class SQLStatementSeparator (Code) | | Simple parser that separates SQLStatements.
Example.
-----------------------
statementSeparator.append("select * from foo; echo $foobar \n");
while (statementSeparator.hasNext()) {
String stmt = statementSeparator.next();
if (stmt.startsWith("echo")) {
// is ok, this command works always without ';'
statementSeparator.consumed();
System.err.println(stmt.substring("echo ".length());
}
else { // SQL-command. we require a semicolon at the end.
if (!stmt.charAt(stmt.length()-1) == ';') {
statementSeparator.cont(); // continue.
}
else {
statementSeparator.consumed();
SQLExecute(stmt);
}
}
}
-----------------------
FIXME: this is a bit rough and accummulated some ideas. Should be
cleaned up.
author: Henner Zeller |
Method Summary | |
public void | append(String s) add a new line including the '\n' to the input buffer. | public void | consumed() after having called next() and you were pleased with the result
call this method to state, that you consumed it. | public void | cont() after having called next(), call cont(), if you are not yet
pleased with the result; the parser should read to the next
possible end. | public void | discard() discard any input. | public PropertyHolder | getRemoveCommentsProperty() returns a property holder for the remove comments property. | public boolean | hasNext() | public String | next() returns the next command; requires to call hasNext() before. | public void | pop() | public void | push() push the current state and start with a clean one. | public void | removeComments(boolean b) set, whether comments should be removed. |
SQLStatementSeparator | public SQLStatementSeparator()(Code) | | |
append | public void append(String s)(Code) | | add a new line including the '\n' to the input buffer.
|
consumed | public void consumed()(Code) | | after having called next() and you were pleased with the result
call this method to state, that you consumed it.
|
cont | public void cont()(Code) | | after having called next(), call cont(), if you are not yet
pleased with the result; the parser should read to the next
possible end.
|
discard | public void discard()(Code) | | discard any input.
|
getRemoveCommentsProperty | public PropertyHolder getRemoveCommentsProperty()(Code) | | returns a property holder for the remove comments property.
|
hasNext | public boolean hasNext() throws IllegalStateException(Code) | | returns true, if the parser can find a complete command that either
ends with newline or with ';'
|
push | public void push()(Code) | | push the current state and start with a clean one. Use to parse
other files (like includes), and continue then with the old
state.
like
load foobar.sql ; select * from foobar
|
removeComments | public void removeComments(boolean b)(Code) | | set, whether comments should be removed.
|
|
|