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>
22 * Corporations manipulation methods
25 * $Date: 2007/12/23 13:39:59 $
29 #include "firebird_store.h"
32 #include "stg/corp_conf.h"
33 #include "stg/common.h"
35 //-----------------------------------------------------------------------------
36 int FIREBIRD_STORE::GetCorpsList(std::vector<std::string> * corpsList) const
38 STG_LOCKER lock(&mutex);
40 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
41 IBPP::Statement st = IBPP::StatementFactory(db, tr);
48 st->Execute("select name from tb_corporations");
52 corpsList->push_back(name);
57 catch (IBPP::Exception & ex)
60 strError = "IBPP exception";
61 printfd(__FILE__, ex.what());
67 //-----------------------------------------------------------------------------
68 int FIREBIRD_STORE::SaveCorp(const STG::CorpConf & cc) 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->Execute("update tb_corporations set cash = ? where name = ?");
85 catch (IBPP::Exception & ex)
88 strError = "IBPP exception";
89 printfd(__FILE__, ex.what());
95 //-----------------------------------------------------------------------------
96 int FIREBIRD_STORE::RestoreCorp(STG::CorpConf * cc, const std::string & name) const
98 STG_LOCKER lock(&mutex);
100 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
101 IBPP::Statement st = IBPP::StatementFactory(db, tr);
106 st->Prepare("select cash from tb_corporations where name = ?");
111 st->Get(1, cc->cash);
115 strError = "Corporation \"" + name + "\" not found in database";
117 printfd(__FILE__, "Corporation '%s' not found in database\n", name.c_str());
123 catch (IBPP::Exception & ex)
126 strError = "IBPP exception";
127 printfd(__FILE__, ex.what());
133 //-----------------------------------------------------------------------------
134 int FIREBIRD_STORE::AddCorp(const std::string & name) const
136 STG_LOCKER lock(&mutex);
138 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
139 IBPP::Statement st = IBPP::StatementFactory(db, tr);
144 st->Prepare("insert into tb_corporations (name, cash), values (?, 0)");
150 catch (IBPP::Exception & ex)
153 strError = "IBPP exception";
154 printfd(__FILE__, ex.what());
160 //-----------------------------------------------------------------------------
161 int FIREBIRD_STORE::DelCorp(const std::string & name) const
163 STG_LOCKER lock(&mutex);
165 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
166 IBPP::Statement st = IBPP::StatementFactory(db, tr);
171 st->Prepare("delete from tb_corporations where name = ?");
177 catch (IBPP::Exception & ex)
180 strError = "IBPP exception";
181 printfd(__FILE__, ex.what());
187 //-----------------------------------------------------------------------------