Search in sources :

Example 1 with StandardException

use of com.akiban.sql.StandardException 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;
    }
}
Also used : Condition(com.revolsys.record.query.Condition) StandardException(com.akiban.sql.StandardException) SQLParser(com.akiban.sql.parser.SQLParser) SelectNode(com.akiban.sql.parser.SelectNode) ValueNode(com.akiban.sql.parser.ValueNode) SQLParserException(com.akiban.sql.parser.SQLParserException) StatementNode(com.akiban.sql.parser.StatementNode) QueryValue(com.revolsys.record.query.QueryValue) CursorNode(com.akiban.sql.parser.CursorNode) ResultSetNode(com.akiban.sql.parser.ResultSetNode)

Aggregations

StandardException (com.akiban.sql.StandardException)1 CursorNode (com.akiban.sql.parser.CursorNode)1 ResultSetNode (com.akiban.sql.parser.ResultSetNode)1 SQLParser (com.akiban.sql.parser.SQLParser)1 SQLParserException (com.akiban.sql.parser.SQLParserException)1 SelectNode (com.akiban.sql.parser.SelectNode)1 StatementNode (com.akiban.sql.parser.StatementNode)1 ValueNode (com.akiban.sql.parser.ValueNode)1 Condition (com.revolsys.record.query.Condition)1 QueryValue (com.revolsys.record.query.QueryValue)1