|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object tribble.parse.sql.QueryParser
Contains methods for parsing query expressions.
This class contains methods for parsing an SQL-like query expression string (i.e., an expression similar to an SQL 'SELECT WHERE' clause) and constructing an expression tree from it. Such a tree can then evaluated against a given set of value objects.
A query (search) criteria string, composed of operators and operands, is used to construct a query control object:
QueryParser parser; // Query expression parser String crit; // Query expression QueryExpr query; // Query control object parser = newQueryParser
(); crit = "date >= '2001-08-01' and rec.name like 'report%.pdf'"; query =parse
(crit);
See also the description of Expression Trees in the QueryExpr
class.
The following expression syntax is recognized:
expr: or_expr or_expr: and_expr and_expr 'OR' or_expr OP_OR and_expr: not_expr not_expr 'AND' and_expr OP_AND not_expr: cmp_expr 'NOT' not_expr OP_NOT cmp_expr: add_expr add_expr 'IS' ['NOT'] 'NULL' OP_IS add_expr ['NOT'] '=' add_expr OP_EQ add_expr ['NOT'] '<>' add_expr OP_NE add_expr ['NOT'] '<' add_expr OP_LT add_expr ['NOT'] '<=' add_expr OP_LE add_expr ['NOT'] '>' add_expr OP_GT add_expr ['NOT'] '>=' add_expr OP_GE add_expr ['NOT'] 'CONTAINS' add_expr OP_CONTAINS add_expr ['NOT'] 'LIKE' add_expr OP_LIKE add_expr ['NOT'] 'LIKEFILE' add_expr OP_LIKEFILE add_expr ['NOT'] 'BETWEEN' add_expr 'AND' add_expr OP_BETWEEN add_expr ['NOT'] 'IN' '(' expr_list ')' OP_IN expr_list: add_expr add_expr [','] expr_list OP_LIST add_expr: mul_expr mul_expr '+' add_expr OP_ADD mul_expr '-' add_expr OP_SUB mul_expr '||' add_expr OP_CONCAT mul_expr: unary_expr unary_expr '*' mul_expr OP_MUL unary_expr '/' mul_expr OP_DIV unary_expr 'MOD' mul_expr OP_MOD unary_expr expo_expr '+' unary_expr OP_POS '-' unary_expr OP_NEG expo_expr: operand operand '**' unary_expr OP_EXPO operand: '(' or_expr ')' name_expr number String 'NULL' String name_expr: name String string String name_expr '.' name OP_MEMBER name_expr '.' string OP_MEMBER name_expr '[' add_expr ']' OP_SUBSCR
Copyright ©2001 by David R. Tribble, all rights reserved.
Permission is granted to any person or entity except those designated by
by the United States Department of State as a terrorist, or terrorist
government or agency, to use and distribute this source code provided
that the original copyright notice remains present and unaltered.
QueryExpr
Field Summary | |
static int |
SERIES
|
Constructor Summary | |
QueryParser()
Default constructor. |
Method Summary | |
static void |
main(java.lang.String[] args)
Test driver. |
QueryExpr |
parse(java.lang.String expr)
Parse a query expression, converting it into an expression tree. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int SERIES
Constructor Detail |
public QueryParser()
Method Detail |
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
public QueryExpr parse(java.lang.String expr) throws java.text.ParseException
expr
- A query expression. This is parsed and converted into an expression tree.
java.text.ParseException
- Thrown if the query expression expr is malformed.
java.text.ParseException
- Thrown if the query expression expr is malformed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |