BlobValue.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 "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   // Get previous versions. 
00057   List vers;
00058   if (!Select(vers, server, fConfigId, fParamId,
00059               (fAddressId <= 0 ? -1 : fAddressId))) return false;
00060   // We can have only one instance of an blobvalue
00061   fVersion = 0;
00062   if (vers.size() > 0) {
00063     BlobValue* v = *(vers.begin());
00064     fVersion     = v->fVersion +  1;
00065   }
00066 
00067   // Get a unique ID from the sequence table 
00068   if (!MakeId(server)) return false;
00069 
00070   // And then do the insert. 
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   // Make the query 
00103   RcuDb::Result* res = 0;
00104   if (!Value::Select(res, server, fgName, cond)) return false;
00105 
00106   // Make the result table if any 
00107   if (!res) return true;
00108   RcuDb::Row* row = 0;
00109   while ((row = res->Next())) l.push_back(new BlobValue(*row));
00110 
00111   // delete result, and return OK.
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   // If parameter object p does not describe a blob, then fail. 
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   // Make the result table if any 
00135   if (!res) return true;
00136   RcuDb::Row* row = 0;
00137   while ((row = res->Next())) l.push_back(new BlobValue(*row));
00138 
00139   // delete result, and return OK.
00140   delete res;
00141   return true;  
00142 }
00143 
00144 //_____________________________________________________________________
00145 //
00146 // EOF
00147 //
00148 
00149 
00150   
00151 
00152   
Top of page Last update Fri Apr 27 01:54:15 2007
Copyright © 2004 Christian Holm Created by DoxyGen 1.3.5