00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00025 #include "Priority.h"
00026 #include "Config.h"
00027 #include "Sequence.h"
00028 #include <rcudb/Server.h>
00029 #include <rcudb/Result.h>
00030 #include <rcudb/Sql.h>
00031 #include <rcudb/Row.h>
00032 #include <iostream>
00033
00034 const std::string RcuConf::Priority::fgName("Priority");
00035
00036
00037 RcuConf::Priority::Priority(RcuDb::Row& row)
00038 : Table(row)
00039 {
00040 row.Field(1, fDescription);
00041 row.Field(2, fParams);
00042 }
00043
00044
00045 void
00046 RcuConf::Priority::Print() const
00047 {
00048 std::cout << "Priority: id=" << fId
00049 << "\tdescription=" << fDescription
00050 << "\tparams=" << fParams << std::endl;
00051 }
00052
00053
00054 bool
00055 RcuConf::Priority::Insert(RcuDb::Server& server)
00056 {
00057
00058 if (!MakeId(server)) return false;
00059
00060
00061 RcuDb::Sql sql2;
00062 sql2 << "INSERT INTO " << fgName << " VALUES("
00063 << fId << ",'"
00064 << fDescription << "','"
00065 << fParams << "')";
00066 return server.Exec(sql2);
00067 }
00068
00069
00070
00071 bool
00072 RcuConf::Priority::Create(RcuDb::Server& server)
00073 {
00074 RcuDb::Sql sql;
00075 sql << "CREATE TABLE " << fgName << " ("
00076 << " id INT KEY, "
00077 << " description VARCHAR(64) NOT NULL, "
00078 << " params BLOB, "
00079 << " INDEX(description))";
00080 return server.Exec(sql);
00081 }
00082
00083
00084 bool
00085 RcuConf::Priority::Drop(RcuDb::Server& server)
00086 {
00087 return Table::Drop(server, fgName);
00088 }
00089
00090
00091 bool
00092 RcuConf::Priority::Select(List& l, RcuDb::Server& server, const RcuDb::Sql& cond)
00093 {
00094
00095 RcuDb::Sql sql;
00096 sql << "SELECT * FROM " << fgName
00097 << (cond.Text().empty() ? "" : " WHERE ")
00098 << (cond.Text().empty() ? "" : cond);
00099
00100
00101 RcuDb::Result* res = server.Query(sql);
00102 if (server.IsError()) return false;
00103
00104
00105 if (!res) return true;
00106
00107
00108 RcuDb::Row* row = 0;
00109 while ((row = res->Next())) l.push_back(new Priority(*row));
00110
00111
00112 delete res;
00113 return true;
00114 }
00115
00116
00117 bool
00118 RcuConf::Priority::Select(List& l, RcuDb::Server& server, const Config& c)
00119 {
00120 RcuDb::Sql sql;
00121 sql << "id=" << c.PriorityId();
00122 return Select(l, server, sql);
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133