1 28 29 package com.caucho.db.sql; 30 31 import com.caucho.log.Log; 32 33 import java.sql.SQLException ; 34 import java.util.ArrayList ; 35 import java.util.logging.Logger ; 36 37 class DoubleCmpExpr extends Expr { 38 private static final Logger log = Log.open(DoubleCmpExpr.class); 39 40 private Expr _left; 41 private Expr _right; 42 private int _op; 43 44 DoubleCmpExpr(int op, Expr left, Expr right) 45 { 46 _left = left; 47 _right = right; 48 _op = op; 49 } 50 51 protected Expr bind(Query query) 52 throws SQLException 53 { 54 Expr newLeft = _left.bind(query); 55 Expr newRight = _right.bind(query); 56 57 if (_left == newLeft && _right == newRight) 58 return this; 59 else 60 return new CmpExpr(newLeft, newRight, _op); 61 } 62 63 66 public Class getType() 67 { 68 return boolean.class; 69 } 70 71 74 public long subCost(ArrayList <FromItem> fromList) 75 { 76 return _left.subCost(fromList) + _right.subCost(fromList); 77 } 78 79 82 public int evalBoolean(QueryContext context) 83 throws SQLException 84 { 85 if (_left.isNull(context) || _right.isNull(context)) 86 return UNKNOWN; 87 88 switch (_op) { 89 case Parser.LT: 90 if (_left.evalDouble(context) < _right.evalDouble(context)) 91 return TRUE; 92 else 93 return FALSE; 94 95 case Parser.LE: 96 if (_left.evalDouble(context) <= _right.evalDouble(context)) 97 return TRUE; 98 else 99 return FALSE; 100 101 case Parser.GT: 102 if (_left.evalDouble(context) > _right.evalDouble(context)) 103 return TRUE; 104 else 105 return FALSE; 106 107 case Parser.GE: 108 if (_left.evalDouble(context) >= _right.evalDouble(context)) 109 return TRUE; 110 else 111 return FALSE; 112 113 case Parser.NE: 114 if (_left.evalDouble(context) != _right.evalDouble(context)) 115 return TRUE; 116 else 117 return FALSE; 118 119 case Parser.EQ: 120 if (_left.evalDouble(context) == _right.evalDouble(context)) 121 return TRUE; 122 else 123 return FALSE; 124 125 default: 126 throw new SQLException ("can't compare"); 127 } 128 } 129 130 public String evalString(QueryContext context) 131 throws SQLException 132 { 133 throw new SQLException ("can't convert string to boolean"); 134 } 135 136 141 public void evalGroup(QueryContext context) 142 throws SQLException 143 { 144 _left.evalGroup(context); 145 _right.evalGroup(context); 146 } 147 148 public String toString() 149 { 150 return "(" + _left + " = " + _right + ")"; 151 } 152 } 153 | Popular Tags |