Sequence.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 "Sequence.h"
00026 #include <rcudb/Server.h>
00027 #include <rcudb/Sql.h>
00028 #include <rcudb/Row.h>
00029 #include <rcudb/Result.h>
00030 
00031 //_____________________________________________________________________
00032 int
00033 RcuConf::Sequence::Increment(RcuDb::Server& server) 
00034 {
00035   int ret = -1;
00036 
00037   // Get the rows in the sequence table 
00038   RcuDb::Sql sql1;
00039   sql1 << "SELECT * FROM Sequence";
00040   RcuDb::Result* res = server.Query(sql1);
00041   if (!res) return ret;
00042 
00043   // Loop through rows (there should be only one!)
00044   RcuDb::Row*    row = 0;
00045   while ((row = res->Next())) row->Field(0, ret);
00046   if (ret < 0) return ret;
00047   
00048   
00049   // Update the sequence table 
00050   RcuDb::Sql sql2;
00051   sql2 << "UPDATE Sequence SET id=" << ret + 1;
00052   if (!server.Exec(sql2)) return -1;
00053 
00054   // Increment and return 
00055   ret++;
00056   return ret;
00057 }
00058 
00059 
00060 //_____________________________________________________________________
00061 bool
00062 RcuConf::Sequence::Create(RcuDb::Server& server) 
00063 {
00064   RcuDb::Sql sql;
00065   sql << "CREATE TABLE Sequence ("
00066       << "id INT KEY)";
00067   bool ret = server.Exec(sql);
00068   if (!ret) return ret;
00069   
00070   RcuDb::Sql sql2;
00071   sql2 << "INSERT INTO Sequence SET id=0";
00072   ret = server.Exec(sql2);
00073   return ret;
00074 }
00075 
00076 //_____________________________________________________________________
00077 bool
00078 RcuConf::Sequence::Drop(RcuDb::Server& server) 
00079 {
00080   RcuDb::Sql sql = "DROP TABLE Sequence";
00081   return server.Exec(sql);
00082 }
00083 
00084 //_____________________________________________________________________
00085 //
00086 // EOF
00087 //
Top of page Last update Fri Apr 27 01:54:16 2007
Copyright © 2004 Christian Holm Created by DoxyGen 1.3.5