00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00025 #include "SingleValue.h"
00026 #include "Parameter.h"
00027 #include "Config.h"
00028 #include "Sequence.h"
00029 #include <rcudb/Server.h>
00030 #include <rcudb/Sql.h>
00031 #include <rcudb/Row.h>
00032 #include <rcudb/Result.h>
00033 #include <iostream>
00034
00035 const std::string RcuConf::SingleValue::fgName("SingleValue");
00036
00037
00038 RcuConf::SingleValue::SingleValue(RcuDb::Row& row)
00039 : Value(row)
00040 {
00041 row.Field(5, fValue);
00042 }
00043
00044
00045 void
00046 RcuConf::SingleValue::Print() const
00047 {
00048 Value::Print();
00049 std::cout << "\tvalue=" << fValue << std::endl;
00050 }
00051
00052
00053 bool
00054 RcuConf::SingleValue::Insert(RcuDb::Server& server)
00055 {
00056
00057 List vers;
00058 if (!Select(vers, server, fConfigId, fParamId,
00059 (fAddressId <= 0 ? -1 : fAddressId))) return false;
00060
00061 fVersion = 0;
00062 if (vers.size() > 0) {
00063 SingleValue* v = *(vers.begin());
00064 fVersion = v->fVersion + 1;
00065 }
00066
00067
00068 if (!MakeId(server)) return false;
00069
00070
00071 RcuDb::Sql sql2;
00072 sql2 << "INSERT INTO " << fgName << " VALUES(";
00073 ValueInsert(sql2);
00074 sql2 << fValue << ")";
00075 if (fAddressId > 0)
00076 std::cout << "Insert with " << sql2.Text() << std::endl;
00077 return server.Exec(sql2);
00078 }
00079
00080
00081
00082 bool
00083 RcuConf::SingleValue::Create(RcuDb::Server& server)
00084 {
00085 RcuDb::Sql sql;
00086 sql << "CREATE TABLE " << fgName << " (";
00087 Value::ValueCreate(sql);
00088 sql << " value INT, "
00089 << " INDEX(configid),"
00090 << " INDEX(paramid), "
00091 << " INDEX(version))";
00092 return server.Exec(sql);
00093 }
00094
00095
00096 bool
00097 RcuConf::SingleValue::Drop(RcuDb::Server& server)
00098 {
00099 return Table::Drop(server, fgName);
00100 }
00101
00102
00103 bool
00104 RcuConf::SingleValue::Select(List& l, RcuDb::Server& server, const RcuDb::Sql& cond)
00105 {
00106
00107 RcuDb::Result* res = 0;
00108 if (!Value::Select(res, server, fgName, cond)) return false;
00109
00110
00111 if (!res) return true;
00112 RcuDb::Row* row = 0;
00113 while ((row = res->Next())) l.push_back(new SingleValue(*row));
00114
00115
00116 delete res;
00117 return true;
00118 }
00119
00120
00121 bool
00122 RcuConf::SingleValue::Select(List& l, RcuDb::Server& server,
00123 const Config& c, const Parameter& p, int addr)
00124 {
00125
00126 if (p.IsBlob()) return false;
00127 return Select(l, server, c.Id(), p.Id(), addr);
00128 }
00129
00130
00131 bool
00132 RcuConf::SingleValue::Select(List& l, RcuDb::Server& server,
00133 int config, int param, int addr)
00134 {
00135 RcuDb::Result* res = 0;
00136 if (!Value::Select(res, server, fgName, config, param, addr)) return false;
00137
00138
00139 if (!res) return true;
00140 RcuDb::Row* row = 0;
00141 while ((row = res->Next())) l.push_back(new SingleValue(*row));
00142
00143
00144 delete res;
00145 return true;
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156