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);
46 st->Execute("select name from tb_corporations");
51 corpsList->push_back(name);
56 catch (IBPP::Exception & ex)
59 strError = "IBPP exception";
60 printfd(__FILE__, ex.what());
66 //-----------------------------------------------------------------------------
67 int FIREBIRD_STORE::SaveCorp(const STG::CorpConf & cc) const
69 STG_LOCKER lock(&mutex);
71 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
72 IBPP::Statement st = IBPP::StatementFactory(db, tr);
77 st->Execute("update tb_corporations set cash = ? where name = ?");
84 catch (IBPP::Exception & ex)
87 strError = "IBPP exception";
88 printfd(__FILE__, ex.what());
94 //-----------------------------------------------------------------------------
95 int FIREBIRD_STORE::RestoreCorp(STG::CorpConf * cc, const std::string & name) const
97 STG_LOCKER lock(&mutex);
99 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
100 IBPP::Statement st = IBPP::StatementFactory(db, tr);
105 st->Prepare("select cash from tb_corporations where name = ?");
110 st->Get(1, cc->cash);
114 strError = "Corporation \"" + name + "\" not found in database";
116 printfd(__FILE__, "Corporation '%s' not found in database\n", name.c_str());
122 catch (IBPP::Exception & ex)
125 strError = "IBPP exception";
126 printfd(__FILE__, ex.what());
132 //-----------------------------------------------------------------------------
133 int FIREBIRD_STORE::AddCorp(const std::string & name) const
135 STG_LOCKER lock(&mutex);
137 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
138 IBPP::Statement st = IBPP::StatementFactory(db, tr);
143 st->Prepare("insert into tb_corporations (name, cash), values (?, 0)");
149 catch (IBPP::Exception & ex)
152 strError = "IBPP exception";
153 printfd(__FILE__, ex.what());
159 //-----------------------------------------------------------------------------
160 int FIREBIRD_STORE::DelCorp(const std::string & name) const
162 STG_LOCKER lock(&mutex);
164 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
165 IBPP::Statement st = IBPP::StatementFactory(db, tr);
170 st->Prepare("delete from tb_corporations where name = ?");
176 catch (IBPP::Exception & ex)
179 strError = "IBPP exception";
180 printfd(__FILE__, ex.what());
186 //-----------------------------------------------------------------------------