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 * Messages manipualtion methods
26 * $Date: 2009/03/03 16:16:23 $
30 #include "firebird_store.h"
33 #include "stg/message.h"
34 #include "stg/common.h"
36 //-----------------------------------------------------------------------------
37 int FIREBIRD_STORE::AddMessage(STG::Message * msg, const std::string & login) const
39 STG_LOCKER lock(&mutex);
41 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
42 IBPP::Statement st = IBPP::StatementFactory(db, tr);
47 st->Prepare("execute procedure sp_add_message(NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
49 st->Set(2, (int32_t)msg->header.ver);
50 st->Set(3, (int32_t)msg->header.type);
51 st->Set(4, (int32_t)msg->header.lastSendTime);
52 st->Set(5, (int32_t)msg->header.creationTime);
53 st->Set(6, (int32_t)msg->header.showTime);
54 st->Set(7, msg->header.repeat);
55 st->Set(8, (int32_t)msg->header.repeatPeriod);
56 st->Set(9, msg->text);
58 st->Get(1, (int64_t &)msg->header.id);
62 catch (IBPP::Exception & ex)
65 strError = "IBPP exception";
66 printfd(__FILE__, ex.what());
72 //-----------------------------------------------------------------------------
73 int FIREBIRD_STORE::EditMessage(const STG::Message & msg,
74 const std::string & login) const
76 STG_LOCKER lock(&mutex);
78 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
79 IBPP::Statement st = IBPP::StatementFactory(db, tr);
84 st->Prepare("execute procedure sp_add_message(?, ?, ?, ?, ?, ?, ?, ?, ?)");
85 st->Set(1, (int64_t)msg.header.id);
87 st->Set(3, (int32_t)msg.header.ver);
88 st->Set(4, (int32_t)msg.header.type);
89 st->Set(5, (int32_t)msg.header.lastSendTime);
90 st->Set(6, (int32_t)msg.header.creationTime);
91 st->Set(7, (int32_t)msg.header.showTime);
92 st->Set(8, msg.header.repeat);
93 st->Set(9, (int32_t)msg.header.repeatPeriod);
94 st->Set(10, msg.text.c_str());
99 catch (IBPP::Exception & ex)
102 strError = "IBPP exception";
103 printfd(__FILE__, ex.what());
109 //-----------------------------------------------------------------------------
110 int FIREBIRD_STORE::GetMessage(uint64_t id,
112 const std::string &) const
114 STG_LOCKER lock(&mutex);
116 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
117 IBPP::Statement st = IBPP::StatementFactory(db, tr);
122 st->Prepare("select * from tb_messages where pk_message = ?");
123 st->Set(1, (int64_t)id);
127 st->Get(1, (int64_t &)msg->header.id);
128 st->Get(3, (int32_t &)msg->header.ver);
129 st->Get(4, (int32_t &)msg->header.type);
130 st->Get(5, (int32_t &)msg->header.lastSendTime);
131 st->Get(6, (int32_t &)msg->header.creationTime);
132 st->Get(7, (int32_t &)msg->header.showTime);
133 st->Get(8, msg->header.repeat);
134 st->Get(9, (int32_t &)msg->header.repeatPeriod);
135 st->Get(10, msg->text);
139 strprintf(&strError, "Message with id = %d not found in database", id);
140 printfd(__FILE__, "Message with id - %d not found in database\n", id);
147 catch (IBPP::Exception & ex)
150 strError = "IBPP exception";
151 printfd(__FILE__, ex.what());
157 //-----------------------------------------------------------------------------
158 int FIREBIRD_STORE::DelMessage(uint64_t id, const std::string &) const
160 STG_LOCKER lock(&mutex);
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_messages where pk_message = ?");
169 st->Set(1, (int64_t)id);
174 catch (IBPP::Exception & ex)
177 strError = "IBPP exception";
178 printfd(__FILE__, ex.what());
184 //-----------------------------------------------------------------------------
185 int FIREBIRD_STORE::GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList,
186 const std::string & login) const
188 STG_LOCKER lock(&mutex);
190 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
191 IBPP::Statement st = IBPP::StatementFactory(db, tr);
193 STG::Message::Header header;
198 st->Prepare("select pk_message, ver, msg_type, \
199 last_send_time, creation_time, \
200 show_time, repeat, repeat_period \
201 from tb_messages where \
202 fk_user = (select pk_user from tb_users where name = ?)");
207 st->Get(1, (int64_t &)header.id);
208 st->Get(2, (int32_t &)header.ver);
209 st->Get(3, (int32_t &)header.type);
210 st->Get(4, (int32_t &)header.lastSendTime);
211 st->Get(5, (int32_t &)header.creationTime);
212 st->Get(6, (int32_t &)header.showTime);
213 st->Get(7, header.repeat);
214 st->Get(8, (int32_t &)header.repeatPeriod);
215 hdrsList->push_back(header);
220 catch (IBPP::Exception & ex)
223 strError = "IBPP exception";
224 printfd(__FILE__, ex.what());
230 //-----------------------------------------------------------------------------