Priority.cxx

Go to the documentation of this file.
00001 // -*- mode: C++ -*- 
00002 //
00003 // Copyright (C) 2006 Christian Holm Christensen <cholm@nbi.dk>
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public License
00007 // as published by the Free Software Foundation; either version 2.1
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free
00017 // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018 // 02111-1307 USA
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   // Get a unique ID from the sequence table 
00058   if (!MakeId(server)) return false;
00059 
00060   // And then do the insert. 
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   // Make the query 
00095   RcuDb::Sql     sql;
00096   sql << "SELECT * FROM " << fgName 
00097       << (cond.Text().empty() ? "" : " WHERE ") 
00098       << (cond.Text().empty() ? "" : cond);
00099   // std::cout << "Doing query: " << sql.Text() << std::endl;
00100   // Execute query, and check error status
00101   RcuDb::Result* res = server.Query(sql);
00102   if (server.IsError()) return false;
00103 
00104   // Make the result table if any 
00105   if (!res) return true;
00106   // res->Print();
00107   
00108   RcuDb::Row* row = 0;
00109   while ((row = res->Next())) l.push_back(new Priority(*row));
00110 
00111   // delete result, and return OK.
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 // EOF
00128 //
00129 
00130 
00131   
00132 
00133   
Top of page Last update Fri Apr 27 01:54:15 2007
Copyright © 2004 Christian Holm Created by DoxyGen 1.3.5