1 package com.quadcap.sql; 2 3 40 41 import java.io.IOException ; 42 43 import java.sql.SQLException ; 44 45 import com.quadcap.sql.types.Value; 46 import com.quadcap.sql.types.ValueDefault; 47 48 import com.quadcap.util.Debug; 49 50 56 public class UpdateItem { 57 String name; 58 Expression e; 59 Value v; 60 int col = -1; 61 62 public UpdateItem(String name, Expression e) { 63 this.name = name; 64 this.e = e; 65 } 66 67 void evaluate(Session session, Relation r, Cursor cursor) 68 throws SQLException , IOException 69 { 70 if (col < 0) { 71 Column c = cursor.getColumn(name); 72 if (c == null) { 73 throw new SQLException ("Bad column: " + name, "42000"); 74 } 75 col = c.getColumn(); 76 } 77 v = e.getValue(session, cursor); 78 if (v instanceof ValueDefault) { 79 Column c = r.getColumn(col); 80 Expression ex = c.getDefault(); 81 if (ex != null) { 82 v = ex.getValue(session, cursor); 83 } 84 } 85 } 86 87 public void update(Session session, Row row) 88 throws SQLException , IOException 89 { 90 row.set(col, v); 91 } 92 } 93 | Popular Tags |