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 //-----------------------------------------------------------------------------
34 int FIREBIRD_STORE::GetServicesList(vector<string> * servicesList) const
36 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
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, __FILE__, __LINE__);
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, 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 string & name) const
103 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
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);
118 st->Get(5, sc->payDay);
122 strError = "Service \"" + name + "\" not found in database";
123 printfd(__FILE__, "Service '%s' not found in database\n", name.c_str());
130 catch (IBPP::Exception & ex)
133 strError = "IBPP exception";
134 printfd(__FILE__, ex.what());
140 //-----------------------------------------------------------------------------
141 int FIREBIRD_STORE::AddService(const string & name) const
143 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
145 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
146 IBPP::Statement st = IBPP::StatementFactory(db, tr);
151 st->Prepare("insert into tb_services (name, comment, cost, pay_day) \
152 values (?, '', 0, 0)");
158 catch (IBPP::Exception & ex)
161 strError = "IBPP exception";
162 printfd(__FILE__, ex.what());
168 //-----------------------------------------------------------------------------
169 int FIREBIRD_STORE::DelService(const string & name) const
171 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
173 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
174 IBPP::Statement st = IBPP::StatementFactory(db, tr);
179 st->Prepare("execute procedure sp_delete_service(?)");
185 catch (IBPP::Exception & ex)
188 strError = "IBPP exception";
189 printfd(__FILE__, ex.what());
195 //-----------------------------------------------------------------------------