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);
49 st->Execute("select name from tb_services");
53 servicesList->push_back(name);
58 catch (IBPP::Exception & ex)
61 strError = "IBPP exception";
62 printfd(__FILE__, ex.what());
68 //-----------------------------------------------------------------------------
69 int FIREBIRD_STORE::SaveService(const STG::ServiceConf & sc) const
71 STG_LOCKER lock(&mutex);
73 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
74 IBPP::Statement st = IBPP::StatementFactory(db, tr);
79 st->Prepare("update tb_services set \
84 st->Set(1, sc.comment);
86 st->Set(3, static_cast<int16_t>(sc.payDay));
92 catch (IBPP::Exception & ex)
95 strError = "IBPP exception";
96 printfd(__FILE__, ex.what());
102 //-----------------------------------------------------------------------------
103 int FIREBIRD_STORE::RestoreService(STG::ServiceConf * sc,
104 const std::string & name) const
106 STG_LOCKER lock(&mutex);
108 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
109 IBPP::Statement st = IBPP::StatementFactory(db, tr);
114 st->Prepare("select * from tb_services where name = ?");
119 st->Get(3, sc->comment);
120 st->Get(4, sc->cost);
123 sc->payDay = static_cast<uint8_t>(pd);
127 strError = "Service \"" + name + "\" not found in database";
128 printfd(__FILE__, "Service '%s' not found in database\n", name.c_str());
135 catch (IBPP::Exception & ex)
138 strError = "IBPP exception";
139 printfd(__FILE__, ex.what());
145 //-----------------------------------------------------------------------------
146 int FIREBIRD_STORE::AddService(const std::string & name) const
148 STG_LOCKER lock(&mutex);
150 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
151 IBPP::Statement st = IBPP::StatementFactory(db, tr);
156 st->Prepare("insert into tb_services (name, comment, cost, pay_day) \
157 values (?, '', 0, 0)");
163 catch (IBPP::Exception & ex)
166 strError = "IBPP exception";
167 printfd(__FILE__, ex.what());
173 //-----------------------------------------------------------------------------
174 int FIREBIRD_STORE::DelService(const std::string & name) const
176 STG_LOCKER lock(&mutex);
178 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
179 IBPP::Statement st = IBPP::StatementFactory(db, tr);
184 st->Prepare("execute procedure sp_delete_service(?)");
190 catch (IBPP::Exception & ex)
193 strError = "IBPP exception";
194 printfd(__FILE__, ex.what());
200 //-----------------------------------------------------------------------------