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