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 : Maksym Mamontov <stg@madf.info>
23 * Messages manipualtion methods
26 * $Date: 2009/03/03 16:16:23 $
30 #include "firebird_store.h"
33 //-----------------------------------------------------------------------------
34 int FIREBIRD_STORE::AddMessage(STG_MSG * msg, const std::string & login) const
36 STG_LOCKER lock(&mutex);
38 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
39 IBPP::Statement st = IBPP::StatementFactory(db, tr);
44 st->Prepare("execute procedure sp_add_message(NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
46 st->Set(2, (int32_t)msg->header.ver);
47 st->Set(3, (int32_t)msg->header.type);
48 st->Set(4, (int32_t)msg->header.lastSendTime);
49 st->Set(5, (int32_t)msg->header.creationTime);
50 st->Set(6, (int32_t)msg->header.showTime);
51 st->Set(7, msg->header.repeat);
52 st->Set(8, (int32_t)msg->header.repeatPeriod);
53 st->Set(9, msg->text);
55 st->Get(1, (int64_t &)msg->header.id);
59 catch (IBPP::Exception & ex)
62 strError = "IBPP exception";
63 printfd(__FILE__, ex.what());
69 //-----------------------------------------------------------------------------
70 int FIREBIRD_STORE::EditMessage(const STG_MSG & msg,
71 const std::string & login) const
73 STG_LOCKER lock(&mutex);
75 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
76 IBPP::Statement st = IBPP::StatementFactory(db, tr);
81 st->Prepare("execute procedure sp_add_message(?, ?, ?, ?, ?, ?, ?, ?, ?)");
82 st->Set(1, (int64_t)msg.header.id);
84 st->Set(3, (int32_t)msg.header.ver);
85 st->Set(4, (int32_t)msg.header.type);
86 st->Set(5, (int32_t)msg.header.lastSendTime);
87 st->Set(6, (int32_t)msg.header.creationTime);
88 st->Set(7, (int32_t)msg.header.showTime);
89 st->Set(8, msg.header.repeat);
90 st->Set(9, (int32_t)msg.header.repeatPeriod);
91 st->Set(10, msg.text.c_str());
96 catch (IBPP::Exception & ex)
99 strError = "IBPP exception";
100 printfd(__FILE__, ex.what());
106 //-----------------------------------------------------------------------------
107 int FIREBIRD_STORE::GetMessage(uint64_t id,
109 const std::string &) const
111 STG_LOCKER lock(&mutex);
113 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
114 IBPP::Statement st = IBPP::StatementFactory(db, tr);
119 st->Prepare("select * from tb_messages where pk_message = ?");
120 st->Set(1, (int64_t)id);
124 st->Get(1, (int64_t &)msg->header.id);
125 st->Get(3, (int32_t &)msg->header.ver);
126 st->Get(4, (int32_t &)msg->header.type);
127 st->Get(5, (int32_t &)msg->header.lastSendTime);
128 st->Get(6, (int32_t &)msg->header.creationTime);
129 st->Get(7, (int32_t &)msg->header.showTime);
130 st->Get(8, msg->header.repeat);
131 st->Get(9, (int32_t &)msg->header.repeatPeriod);
132 st->Get(10, msg->text);
136 strprintf(&strError, "Message with id = %d not found in database", id);
137 printfd(__FILE__, "Message with id - %d not found in database\n", id);
144 catch (IBPP::Exception & ex)
147 strError = "IBPP exception";
148 printfd(__FILE__, ex.what());
154 //-----------------------------------------------------------------------------
155 int FIREBIRD_STORE::DelMessage(uint64_t id, const std::string &) const
157 STG_LOCKER lock(&mutex);
159 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
160 IBPP::Statement st = IBPP::StatementFactory(db, tr);
165 st->Prepare("delete from tb_messages where pk_message = ?");
166 st->Set(1, (int64_t)id);
171 catch (IBPP::Exception & ex)
174 strError = "IBPP exception";
175 printfd(__FILE__, ex.what());
181 //-----------------------------------------------------------------------------
182 int FIREBIRD_STORE::GetMessageHdrs(std::vector<STG_MSG_HDR> * hdrsList,
183 const std::string & login) const
185 STG_LOCKER lock(&mutex);
187 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
188 IBPP::Statement st = IBPP::StatementFactory(db, tr);
195 st->Prepare("select pk_message, ver, msg_type, \
196 last_send_time, creation_time, \
197 show_time, repeat, repeat_period \
198 from tb_messages where \
199 fk_user = (select pk_user from tb_users where name = ?)");
204 st->Get(1, (int64_t &)header.id);
205 st->Get(2, (int32_t &)header.ver);
206 st->Get(3, (int32_t &)header.type);
207 st->Get(4, (int32_t &)header.lastSendTime);
208 st->Get(5, (int32_t &)header.creationTime);
209 st->Get(6, (int32_t &)header.showTime);
210 st->Get(7, header.repeat);
211 st->Get(8, (int32_t &)header.repeatPeriod);
212 hdrsList->push_back(header);
217 catch (IBPP::Exception & ex)
220 strError = "IBPP exception";
221 printfd(__FILE__, ex.what());
227 //-----------------------------------------------------------------------------