Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

SQLUpdate.h

Go to the documentation of this file.
00001 #ifndef SQL_UPDATE_H 00002 #define SQL_UPDATE_H 00003 00004 #include "Expression.h" 00005 #include "TupleDescription.h" 00006 #include "SQLUtil.h" 00007 00008 BOREALIS_NAMESPACE_BEGIN 00009 00010 class SQLUpdate { 00011 public: 00012 class SetExpr { 00013 public: 00014 SetExpr(string field_name, ptr<Expression> expr, 00015 string table_name, const ExprContext& ctxt); 00016 ~SetExpr() {} 00017 00018 // Evaluate into the tuple, given the context. 00019 void evalInto(char *tuple, const EvalContext& ctxt) { 00020 _expr->evalInto(tuple+_offset, ctxt); 00021 } 00022 00023 string as_string() const { 00024 return ("SetExpr(offset(" + to_string(_offset) + 00025 "=" + _expr + ")"); 00026 } 00027 private: 00028 unsigned int _offset; 00029 ptr<Expression> _expr; 00030 }; 00031 public: 00032 SQLUpdate(string table, 00033 const vector<ptr<SetExpr> >& set_list, 00034 ptr<SQLWhereClause> where_clause, 00035 const ExprContext &ctxt) : 00036 _table_name(table), 00037 _set_list(set_list), 00038 _where_clause(where_clause) { 00039 // TODO: Use named context or something. 00040 TupleDescription td; 00041 ctxt.getNamedTupleInfo(_table_name, td, _table_tuple_num); 00042 _row_size = td.getSizeInBytes(); 00043 } 00044 ~SQLUpdate() {} 00045 00046 string getTableName() const { return _table_name; } 00047 00049 ptr<SQLWhereClause> getWhereClause() { return _where_clause; } 00050 00053 void evalNewRow(char *new_row, const EvalContext& ctxt) 00054 throw (EvalException) { 00055 // Copy existing row 00056 memcpy(new_row, ctxt.getTuple(_table_tuple_num), _row_size); 00057 // Run set expressions. 00058 vector<ptr<SetExpr> >::const_iterator i; 00059 for (i = _set_list.begin(); i != _set_list.end(); ++i) { 00060 SetExpr &se = **i; 00061 se.evalInto(new_row, ctxt); 00062 } 00063 } 00064 00065 const string as_string() const { 00066 return ("SQLUpdate(table=" + _table_name + " setlist=" + 00067 _set_list + " where=" + _where_clause + ")"); 00068 } 00069 00070 public: 00071 static ptr<SQLUpdate> parse(string expr, const ExprContext& ctxt, 00072 string table_name) 00073 throw (ExprException); 00074 00075 private: 00076 string _table_name; 00077 unsigned int _table_tuple_num; // The number of the table row in eval contexts. 00078 size_t _row_size; 00079 vector<ptr<SetExpr> > _set_list; 00080 ptr<SQLWhereClause> _where_clause; 00081 }; 00082 00083 BOREALIS_NAMESPACE_END 00084 00085 #endif // SQL_UPDATE_H

Generated on Fri Nov 12 15:15:22 2004 for Borealis by doxygen 1.3.8