use of com.akiban.sql.parser.CursorNode in project com.revolsys.open by revolsys.
the class QueryValue method parseWhere.
static Condition parseWhere(final RecordDefinition recordDefinition, final String whereClause) {
if (Property.hasValue(whereClause)) {
try {
final SQLParser sqlParser = new SQLParser();
String name;
if (recordDefinition == null) {
name = "Unknown";
} else {
name = recordDefinition.getName();
}
final String query = "SELECT * FROM \"" + name + "\" WHERE " + whereClause;
final StatementNode statement = sqlParser.parseStatement(query);
if (statement instanceof CursorNode) {
final CursorNode selectStatement = (CursorNode) statement;
final ResultSetNode resultSetNode = selectStatement.getResultSetNode();
if (resultSetNode instanceof SelectNode) {
final SelectNode selectNode = (SelectNode) resultSetNode;
final ValueNode where = selectNode.getWhereClause();
final Condition condition = toQueryValue(recordDefinition, where);
return condition;
}
}
return null;
} catch (final Throwable e) {
throw new IllegalArgumentException("Invalid where clause: " + whereClause, e);
}
} else {
return null;
}
}
use of com.akiban.sql.parser.CursorNode in project com.revolsys.open by revolsys.
the class QueryWhereConditionField method verifyCondition.
public void verifyCondition() {
this.validating = true;
this.valid = true;
this.statusLabel.setText("");
try {
final String whereClause = this.whereTextField.getText();
if (Property.hasValue(whereClause)) {
final String sql = "SELECT * FROM X WHERE " + "\n" + whereClause;
try {
final StatementNode statement = new SQLParser().parseStatement(sql);
if (statement instanceof CursorNode) {
final CursorNode selectStatement = (CursorNode) statement;
final ResultSetNode resultSetNode = selectStatement.getResultSetNode();
if (resultSetNode instanceof SelectNode) {
final SelectNode selectNode = (SelectNode) resultSetNode;
final ValueNode where = selectNode.getWhereClause();
final QueryValue queryValue = toQueryValue(where);
if (queryValue instanceof Condition) {
final Condition condition = (Condition) queryValue;
if (this.valid) {
setFieldValue(condition);
this.statusLabel.setForeground(WebColors.DarkGreen);
this.statusLabel.setText("Valid");
}
}
}
}
} catch (final SQLParserException e) {
final int offset = e.getErrorPosition();
setInvalidMessage(offset - this.sqlPrefix.length(), "Error parsing SQL: " + e.getMessage());
} catch (final StandardException e) {
Logs.error(this, "Error parsing SQL: " + whereClause, e);
}
} else {
setFieldValue(Condition.ALL);
this.statusLabel.setForeground(WebColors.DarkGreen);
this.statusLabel.setText("Valid");
}
} finally {
if (!this.valid) {
setFieldValue(null);
}
this.validating = false;
}
}
Aggregations