001: package com.quadcap.sql;
002:
003: /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.io.IOException;
042:
043: import java.util.Enumeration;
044: import java.util.Vector;
045:
046: import java.sql.SQLException;
047:
048: import com.quadcap.sql.types.Op;
049: import com.quadcap.sql.types.Type;
050: import com.quadcap.sql.types.Value;
051:
052: import com.quadcap.util.Debug;
053:
054: /**
055: * Base class for all expression types.
056: *
057: * @author Stan Bailes
058: */
059:
060: public abstract class Expression {
061: /**
062: * Returns zero if this is a scalar expression, one if it's a vector
063: * type and 2 if it's a table/cursor type.
064: */
065: public abstract int rank();
066:
067: /**
068: * Return the expression's type if known
069: */
070: public abstract Type getType(Session session, Cursor cursor)
071: throws SQLException;
072:
073: /**
074: * If this is a scalar, return its value
075: */
076: public Value getValue(Session session, Cursor cursor)
077: throws SQLException {
078: return null;
079: }
080:
081: /**
082: * If this is a vector, return the value
083: */
084: public Row getValues(Session session, Cursor cursor)
085: throws SQLException {
086: if (rank() == 0) {
087: Value v = getValue(session, cursor);
088: Row row = new Row(1);
089: row.set(1, v);
090: return row;
091: } else {
092: throw new SQLException("getValues, rank = " + rank(),
093: "Q0000");
094: }
095: }
096:
097: /**
098: * If this is a cursor, return the value
099: */
100: public Cursor getCursor(Session session, Cursor cursor)
101: throws SQLException {
102: return null;
103: }
104:
105: /**
106: * Negate the logical value of the expression
107: */
108: public void invert() throws antlr.RecognitionException {
109: throw new antlr.RecognitionException(
110: "Error, not a boolean expression");
111: }
112:
113: /**
114: * Give a visitor access to the parse tree.
115: */
116: public void visitSubExpressions(ExpressionVisitor v) {
117: }
118:
119: public String getName() {
120: return null;
121: }
122:
123: abstract public String toString();
124:
125: }
|