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 $
32 #include "firebird_store.h"
35 //-----------------------------------------------------------------------------
36 int FIREBIRD_STORE::AddMessage(STG_MSG * msg, const string & login) const
38 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
40 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
41 IBPP::Statement st = IBPP::StatementFactory(db, tr);
46 st->Prepare("execute procedure sp_add_message(NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
48 st->Set(2, (int32_t)msg->header.ver);
49 st->Set(3, (int32_t)msg->header.type);
50 st->Set(4, (int32_t)msg->header.lastSendTime);
51 st->Set(5, (int32_t)msg->header.creationTime);
52 st->Set(6, (int32_t)msg->header.showTime);
53 st->Set(7, msg->header.repeat);
54 st->Set(8, (int32_t)msg->header.repeatPeriod);
55 st->Set(9, msg->text);
57 st->Get(1, (int64_t &)msg->header.id);
61 catch (IBPP::Exception & ex)
64 strError = "IBPP exception";
65 printfd(__FILE__, ex.what());
71 //-----------------------------------------------------------------------------
72 int FIREBIRD_STORE::EditMessage(const STG_MSG & msg,
73 const string & login) const
75 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
77 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
78 IBPP::Statement st = IBPP::StatementFactory(db, tr);
83 st->Prepare("execute procedure sp_add_message(?, ?, ?, ?, ?, ?, ?, ?, ?)");
84 st->Set(1, (int64_t)msg.header.id);
86 st->Set(3, (int32_t)msg.header.ver);
87 st->Set(4, (int32_t)msg.header.type);
88 st->Set(5, (int32_t)msg.header.lastSendTime);
89 st->Set(6, (int32_t)msg.header.creationTime);
90 st->Set(7, (int32_t)msg.header.showTime);
91 st->Set(8, msg.header.repeat);
92 st->Set(9, (int32_t)msg.header.repeatPeriod);
93 st->Set(10, msg.text.c_str());
98 catch (IBPP::Exception & ex)
101 strError = "IBPP exception";
102 printfd(__FILE__, ex.what());
108 //-----------------------------------------------------------------------------
109 int FIREBIRD_STORE::GetMessage(uint64_t id,
111 const string &) const
113 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
115 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
116 IBPP::Statement st = IBPP::StatementFactory(db, tr);
121 st->Prepare("select * from tb_messages where pk_message = ?");
122 st->Set(1, (int64_t)id);
126 st->Get(1, (int64_t &)msg->header.id);
127 st->Get(3, (int32_t &)msg->header.ver);
128 st->Get(4, (int32_t &)msg->header.type);
129 st->Get(5, (int32_t &)msg->header.lastSendTime);
130 st->Get(6, (int32_t &)msg->header.creationTime);
131 st->Get(7, (int32_t &)msg->header.showTime);
132 st->Get(8, msg->header.repeat);
133 st->Get(9, (int32_t &)msg->header.repeatPeriod);
134 st->Get(10, msg->text);
138 strprintf(&strError, "Message with id = %d not found in database", id);
139 printfd(__FILE__, "Message with id - %d not found in database\n", id);
146 catch (IBPP::Exception & ex)
149 strError = "IBPP exception";
150 printfd(__FILE__, ex.what());
156 //-----------------------------------------------------------------------------
157 int FIREBIRD_STORE::DelMessage(uint64_t id, const string &) const
159 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
161 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
162 IBPP::Statement st = IBPP::StatementFactory(db, tr);
167 st->Prepare("delete from tb_messages where pk_message = ?");
168 st->Set(1, (int64_t)id);
173 catch (IBPP::Exception & ex)
176 strError = "IBPP exception";
177 printfd(__FILE__, ex.what());
183 //-----------------------------------------------------------------------------
184 int FIREBIRD_STORE::GetMessageHdrs(vector<STG_MSG_HDR> * hdrsList,
185 const string & login) const
187 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
189 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
190 IBPP::Statement st = IBPP::StatementFactory(db, tr);
197 st->Prepare("select pk_message, ver, msg_type, \
198 last_send_time, creation_time, \
199 show_time, repeat, repeat_period \
200 from tb_messages where \
201 fk_user = (select pk_user from tb_users where name = ?)");
206 st->Get(1, (int64_t &)header.id);
207 st->Get(2, (int32_t &)header.ver);
208 st->Get(3, (int32_t &)header.type);
209 st->Get(4, (int32_t &)header.lastSendTime);
210 st->Get(5, (int32_t &)header.creationTime);
211 st->Get(6, (int32_t &)header.showTime);
212 st->Get(7, header.repeat);
213 st->Get(8, (int32_t &)header.repeatPeriod);
214 hdrsList->push_back(header);
219 catch (IBPP::Exception & ex)
222 strError = "IBPP exception";
223 printfd(__FILE__, ex.what());
229 //-----------------------------------------------------------------------------