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 : Maksym Mamontov <stg@madf.info>
23 * Services manipulation methods
26 * $Date: 2009/05/13 13:19:33 $
30 #include "firebird_store.h"
33 //-----------------------------------------------------------------------------
34 int FIREBIRD_STORE::GetServicesList(std::vector<std::string> * servicesList) const
36 STG_LOCKER lock(&mutex);
38 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
39 IBPP::Statement st = IBPP::StatementFactory(db, tr);
46 st->Execute("select name from tb_services");
50 servicesList->push_back(name);
55 catch (IBPP::Exception & ex)
58 strError = "IBPP exception";
59 printfd(__FILE__, ex.what());
65 //-----------------------------------------------------------------------------
66 int FIREBIRD_STORE::SaveService(const SERVICE_CONF & sc) const
68 STG_LOCKER lock(&mutex);
70 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
71 IBPP::Statement st = IBPP::StatementFactory(db, tr);
76 st->Prepare("update tb_services set \
81 st->Set(1, sc.comment);
83 st->Set(3, static_cast<int16_t>(sc.payDay));
89 catch (IBPP::Exception & ex)
92 strError = "IBPP exception";
93 printfd(__FILE__, ex.what());
99 //-----------------------------------------------------------------------------
100 int FIREBIRD_STORE::RestoreService(SERVICE_CONF * sc,
101 const std::string & name) const
103 STG_LOCKER lock(&mutex);
105 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
106 IBPP::Statement st = IBPP::StatementFactory(db, tr);
111 st->Prepare("select * from tb_services where name = ?");
116 st->Get(3, sc->comment);
117 st->Get(4, sc->cost);
120 sc->payDay = static_cast<uint8_t>(pd);
124 strError = "Service \"" + name + "\" not found in database";
125 printfd(__FILE__, "Service '%s' not found in database\n", name.c_str());
132 catch (IBPP::Exception & ex)
135 strError = "IBPP exception";
136 printfd(__FILE__, ex.what());
142 //-----------------------------------------------------------------------------
143 int FIREBIRD_STORE::AddService(const std::string & name) const
145 STG_LOCKER lock(&mutex);
147 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
148 IBPP::Statement st = IBPP::StatementFactory(db, tr);
153 st->Prepare("insert into tb_services (name, comment, cost, pay_day) \
154 values (?, '', 0, 0)");
160 catch (IBPP::Exception & ex)
163 strError = "IBPP exception";
164 printfd(__FILE__, ex.what());
170 //-----------------------------------------------------------------------------
171 int FIREBIRD_STORE::DelService(const std::string & name) const
173 STG_LOCKER lock(&mutex);
175 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
176 IBPP::Statement st = IBPP::StatementFactory(db, tr);
181 st->Prepare("execute procedure sp_delete_service(?)");
187 catch (IBPP::Exception & ex)
190 strError = "IBPP exception";
191 printfd(__FILE__, ex.what());
197 //-----------------------------------------------------------------------------