ModSQL
Class Expression

java.lang.Object
  |
  +--ModSQL.Expression

abstract class Expression
extends Object

Abstract class with static methods for parsing SQL expressions.

Author:
chris.studholme@utoronto.ca

Field Summary
static int PRIORITY_ADD
          Arbitrarily scaled priority number (for addition).
static int PRIORITY_AND
          Arbitrarily scaled priority number (for AND).
static int PRIORITY_COMPARE
          Arbitrarily scaled priority number (for comparisions).
static int PRIORITY_MULTIPLY
          Arbitrarily scaled priority number (for multiplication).
static int PRIORITY_NOT
          Arbitrarily scaled priority number (for NOT).
static int PRIORITY_OR
          Arbitrarily scaled priority number (for OR).
protected static String[] sqlkeywords
          List of SQL keywords.
 
Constructor Summary
(package private) Expression()
           
 
Method Summary
static Function getBuiltinFunction(String name)
          Get a new object representing a built-in SQL function.
static boolean isKeyword(String word)
          Static support method.
static Function parseExpression(StreamTokenizer tokenizer, DatabaseManager manager)
          Parse an arbitrary SQL expression and return the root Function of the graph of Function's that results.
static Function parseExpression(StreamTokenizer tokenizer, DatabaseManager manager, int priority_min)
          Generalized version of above method.
static Table parseTableExpression(StreamTokenizer tokenizer, DatabaseManager manager)
          Parse an arbitrary table expression.
static Function parseValue(StreamTokenizer tokenizer, DatabaseManager manager)
          Parse an arbitrary SQL value and return the root Function of the graph of Function's that results.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

PRIORITY_MULTIPLY

public static final int PRIORITY_MULTIPLY
Arbitrarily scaled priority number (for multiplication).

PRIORITY_ADD

public static final int PRIORITY_ADD
Arbitrarily scaled priority number (for addition).

PRIORITY_COMPARE

public static final int PRIORITY_COMPARE
Arbitrarily scaled priority number (for comparisions).

PRIORITY_NOT

public static final int PRIORITY_NOT
Arbitrarily scaled priority number (for NOT).

PRIORITY_AND

public static final int PRIORITY_AND
Arbitrarily scaled priority number (for AND).

PRIORITY_OR

public static final int PRIORITY_OR
Arbitrarily scaled priority number (for OR).

sqlkeywords

protected static final String[] sqlkeywords
List of SQL keywords. This list is no where near complete.
Constructor Detail

Expression

Expression()
Method Detail

isKeyword

public static boolean isKeyword(String word)
Static support method. Determine if the parameter represents a SQL keyword. The parameter must be all lowercase.
Parameters:
word - word to check
Returns:
true if word is a SQL keyword, false otherwise

getBuiltinFunction

public static Function getBuiltinFunction(String name)
                                   throws SQLException
Get a new object representing a built-in SQL function.
Parameters:
name - name of function to lookup (all lowercase)
Returns:
function object (or null if function not known)
Throws:
SQLException - if an error occurs

parseExpression

public static Function parseExpression(StreamTokenizer tokenizer,
                                       DatabaseManager manager)
                                throws SQLException,
                                       IOException

Parse an arbitrary SQL expression and return the root Function of the graph of Function's that results.

The first thing parseExpression() does is call parseValue(). The expression may consist of nothing more than a value parsable by parseValue().

Parameters:
tokenizer - StreamTokenizer that SQL tokens should be read from
manager - DatabaseManager currently in use (used for subqueries)
Returns:
the root Function representing the expression
Throws:
SQLException - if a database-access error occurs
IOException - if there is a problem with the StreamTokenizer

parseExpression

public static Function parseExpression(StreamTokenizer tokenizer,
                                       DatabaseManager manager,
                                       int priority_min)
                                throws SQLException,
                                       IOException
Generalized version of above method. When parsing, if an operator with a priority less than or equal to priority_min if found, parsing will cease at that point.
Parameters:
tokenizer - StreamTokenizer that SQL tokens should be read from
manager - DatabaseManager currently in use (used for subqueries)
priority_min - stop if an operator with a low priority is found
Returns:
the root Function representing the expression
Throws:
SQLException - if a database-access error occurs
IOException - if there is a problem with the StreamTokenizer

parseValue

public static Function parseValue(StreamTokenizer tokenizer,
                                  DatabaseManager manager)
                           throws SQLException,
                                  IOException

Parse an arbitrary SQL value and return the root Function of the graph of Function's that results. This method is useful for parsing literals '-5.43', single parameter operators 'NOT a=b', and subexpressions including row-constructors '(SELECT ...)'. Use parseExpression() for parsing general expressions.

Parameters:
tokenizer - StreamTokenizer that SQL tokens should be read from
manager - DatabaseManager currently in use (used for subqueries)
Returns:
the root Function's representing the value
Throws:
SQLException - if a database-access error occurs
IOException - if there is a problem with the StreamTokenizer

parseTableExpression

public static Table parseTableExpression(StreamTokenizer tokenizer,
                                         DatabaseManager manager)
                                  throws SQLException,
                                         IOException
Parse an arbitrary table expression. These are of the form: where row-constructor is of the form (column-value [, ...]) or SELECT ....
Parameters:
tokenizer - StreamTokenizer that SQL tokens should be read from
manager - DatabaseManager currently in use (used for subqueries)
Returns:
the root Function's representing the value
Throws:
SQLException - if a database-access error occurs
IOException - if there is a problem with the StreamTokenizer