2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
23 * Services manipulation methods
26 * $Date: 2009/05/13 13:19:33 $
30 #include "firebird_store.h"
33 #include "stg/service_conf.h"
34 #include "stg/common.h"
36 //-----------------------------------------------------------------------------
37 int FIREBIRD_STORE::GetServicesList(std::vector<std::string> * servicesList) const
39 STG_LOCKER lock(&mutex);
41 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
42 IBPP::Statement st = IBPP::StatementFactory(db, tr);
47 st->Execute("select name from tb_services");
52 servicesList->push_back(name);
57 catch (IBPP::Exception & ex)
60 strError = "IBPP exception";
61 printfd(__FILE__, ex.what());
67 //-----------------------------------------------------------------------------
68 int FIREBIRD_STORE::SaveService(const STG::ServiceConf & sc) const
70 STG_LOCKER lock(&mutex);
72 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
73 IBPP::Statement st = IBPP::StatementFactory(db, tr);
78 st->Prepare("update tb_services set \
83 st->Set(1, sc.comment);
85 st->Set(3, static_cast<int16_t>(sc.payDay));
91 catch (IBPP::Exception & ex)
94 strError = "IBPP exception";
95 printfd(__FILE__, ex.what());
101 //-----------------------------------------------------------------------------
102 int FIREBIRD_STORE::RestoreService(STG::ServiceConf * sc,
103 const std::string & name) const
105 STG_LOCKER lock(&mutex);
107 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
108 IBPP::Statement st = IBPP::StatementFactory(db, tr);
113 st->Prepare("select * from tb_services where name = ?");
118 st->Get(3, sc->comment);
119 st->Get(4, sc->cost);
122 sc->payDay = static_cast<uint8_t>(pd);
126 strError = "Service \"" + name + "\" not found in database";
127 printfd(__FILE__, "Service '%s' not found in database\n", name.c_str());
134 catch (IBPP::Exception & ex)
137 strError = "IBPP exception";
138 printfd(__FILE__, ex.what());
144 //-----------------------------------------------------------------------------
145 int FIREBIRD_STORE::AddService(const std::string & name) const
147 STG_LOCKER lock(&mutex);
149 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
150 IBPP::Statement st = IBPP::StatementFactory(db, tr);
155 st->Prepare("insert into tb_services (name, comment, cost, pay_day) \
156 values (?, '', 0, 0)");
162 catch (IBPP::Exception & ex)
165 strError = "IBPP exception";
166 printfd(__FILE__, ex.what());
172 //-----------------------------------------------------------------------------
173 int FIREBIRD_STORE::DelService(const std::string & name) const
175 STG_LOCKER lock(&mutex);
177 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
178 IBPP::Statement st = IBPP::StatementFactory(db, tr);
183 st->Prepare("execute procedure sp_delete_service(?)");
189 catch (IBPP::Exception & ex)
192 strError = "IBPP exception";
193 printfd(__FILE__, ex.what());
199 //-----------------------------------------------------------------------------