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 //-----------------------------------------------------------------------------
33 int FIREBIRD_STORE::GetCorpsList(vector<string> * corpsList) const
35 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
37 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
38 IBPP::Statement st = IBPP::StatementFactory(db, tr);
45 st->Execute("select name from tb_corporations");
49 corpsList->push_back(name);
54 catch (IBPP::Exception & ex)
57 strError = "IBPP exception";
58 printfd(__FILE__, ex.what());
64 //-----------------------------------------------------------------------------
65 int FIREBIRD_STORE::SaveCorp(const CORP_CONF & cc) const
67 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
69 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
70 IBPP::Statement st = IBPP::StatementFactory(db, tr);
75 st->Execute("update tb_corporations set cash = ? where name = ?");
82 catch (IBPP::Exception & ex)
85 strError = "IBPP exception";
86 printfd(__FILE__, ex.what());
92 //-----------------------------------------------------------------------------
93 int FIREBIRD_STORE::RestoreCorp(CORP_CONF * cc, const string & name) const
95 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
97 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
98 IBPP::Statement st = IBPP::StatementFactory(db, tr);
103 st->Prepare("select cash from tb_corporations where name = ?");
108 st->Get(1, cc->cash);
112 strError = "Corporation \"" + name + "\" not found in database";
114 printfd(__FILE__, "Corporation '%s' not found in database\n", name.c_str());
120 catch (IBPP::Exception & ex)
123 strError = "IBPP exception";
124 printfd(__FILE__, ex.what());
130 //-----------------------------------------------------------------------------
131 int FIREBIRD_STORE::AddCorp(const string & name) const
133 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
135 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
136 IBPP::Statement st = IBPP::StatementFactory(db, tr);
141 st->Prepare("insert into tb_corporations (name, cash), values (?, 0)");
147 catch (IBPP::Exception & ex)
150 strError = "IBPP exception";
151 printfd(__FILE__, ex.what());
157 //-----------------------------------------------------------------------------
158 int FIREBIRD_STORE::DelCorp(const string & name) const
160 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
162 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
163 IBPP::Statement st = IBPP::StatementFactory(db, tr);
168 st->Prepare("delete from tb_corporations where name = ?");
174 catch (IBPP::Exception & ex)
177 strError = "IBPP exception";
178 printfd(__FILE__, ex.what());
184 //-----------------------------------------------------------------------------