1 package com.quadcap.sql; 2 3 40 41 import java.io.Externalizable ; 42 import java.io.IOException ; 43 import java.io.ObjectInput ; 44 import java.io.ObjectOutput ; 45 46 import java.util.ArrayList ; 47 import java.util.Vector ; 48 49 import java.sql.SQLException ; 50 51 import com.quadcap.sql.types.Op; 52 import com.quadcap.sql.types.Type; 53 import com.quadcap.sql.types.Value; 54 55 import com.quadcap.util.Debug; 56 import com.quadcap.util.Util; 57 58 63 public class NameExpression extends Expression implements Externalizable { 64 String name; 65 boolean not = false; 66 67 70 public NameExpression() {} 71 72 public NameExpression(String name) { 73 this.name = name; 74 } 75 76 79 public int rank() { return 0; } 80 81 public Type getType(Session session, Cursor cursor) throws SQLException { 82 String rname = session.getConnection().resolveColname(name, cursor); 83 Column c = cursor.getColumn(rname); 84 return c.getType(); 85 } 86 87 public Value getValue(Session session, Cursor cursor) throws SQLException { 88 Cursor effectiveCursor = cursor; 89 if (cursor == null) { 90 throw new SQLException ("No cursor for name expression: " + name, "42000"); 91 } 92 String rname = session.getConnection().resolveColname(name, cursor); 93 Column c = cursor.getColumn(rname); 94 if (c == null) { 95 throw new SQLException ("Bad column: " + name, "Q000S"); 96 } 97 Tuple tc = c.getRelation(); 98 if (tc instanceof Cursor && !(cursor instanceof StaticCursor)) { 99 effectiveCursor = (Cursor)tc; 100 } 101 102 int col = c.getColumn(); 103 Row row = effectiveCursor.getRow(); 104 if (row == null) { 105 throw new SQLException ("no cursor", "Q000T"); 106 } 107 Value v = row.item(col); 108 if (not) v = v.unop(Op.NOT); 109 return v; 110 } 111 112 public Row getValues(Session session, Cursor cursor) throws SQLException { 113 ArrayList v = new ArrayList (); 114 v.add(getValue(session, cursor)); 115 return new Row(v); 116 } 117 118 public String getName() { return name; } 119 120 public void invert() { 121 not = !not; 122 } 123 124 public void visitSubExpressions(ExpressionVisitor ev) { 125 } 126 127 public void readExternal(ObjectInput in) 128 throws IOException , ClassNotFoundException 129 { 130 name = (String )in.readObject(); 131 } 132 133 public void writeExternal(ObjectOutput out) throws IOException { 134 out.writeObject(name); 135 } 136 137 public String toString() { 138 return name; 139 } 140 } 141 | Popular Tags |