blob: 5456362aa57af3b0b9b4635ced5983807635cafc [file] [log] [blame]
Alexander Afanasyeva199f972013-01-02 19:37:26 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012-2013 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Zhenkai Zhu <zhenkai@cs.ucla.edu>
20 */
21
22#include "action-log.h"
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080023#include <action-item.pb.h>
Alexander Afanasyeva199f972013-01-02 19:37:26 -080024
25using namespace boost;
26using namespace std;
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -080027using namespace Ccnx;
Alexander Afanasyeva199f972013-01-02 19:37:26 -080028
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -080029ActionLog::ActionLog (Ccnx::CcnxWrapperPtr ccnx, const std::string &path, const std::string &localName, const std::string &sharedFolder)
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080030 : SyncLog (path, localName)
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -080031 , m_ccnx (ccnx)
32 , m_sharedFolderName (sharedFolder)
Alexander Afanasyeva199f972013-01-02 19:37:26 -080033{
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080034 int res = sqlite3_create_function (m_db, "apply_action", -1, SQLITE_ANY, reinterpret_cast<void*> (this),
35 ActionLog::apply_action_xFun,
36 0, 0);
37 if (res != SQLITE_OK)
38 {
39 BOOST_THROW_EXCEPTION (Error::Db ()
40 << errmsg_info_str ("Cannot create function ``apply_action''"));
41 }
Alexander Afanasyeva199f972013-01-02 19:37:26 -080042}
43
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080044tuple<sqlite3_int64, sqlite3_int64, sqlite3_int64, string>
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080045ActionLog::GetExistingRecord (const std::string &filename)
46{
47 // check if something already exists
48 sqlite3_stmt *stmt;
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080049 int res = sqlite3_prepare_v2 (m_db, "SELECT a.version,a.device_id,a.seq_no,a.action,s.device_name "
50 "FROM ActionLog a JOIN SyncNodes s ON s.device_id = a.device_id "
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080051 "WHERE filename=? ORDER BY a.version DESC LIMIT 1", -1, &stmt, 0);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080052
53 if (res != SQLITE_OK)
54 {
55 BOOST_THROW_EXCEPTION (Error::Db ()
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080056 << errmsg_info_str ("Some error with GetExistingRecord"));
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080057 }
58
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080059 // with parent with version number + 1
60 sqlite3_int64 version = 0;
61 sqlite3_int64 parent_device_id = -1;
62 sqlite3_int64 parent_seq_no = -1;
63 string parent_device_name;
64
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080065 sqlite3_bind_text (stmt, 1, filename.c_str (), filename.size (), SQLITE_STATIC);
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080066 if (sqlite3_step (stmt) == SQLITE_ROW)
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080067 {
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080068 version = sqlite3_column_int64 (stmt, 0) + 1;
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080069
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080070 if (sqlite3_column_int (stmt, 3) == 0) // prevent "linking" if the file was previously deleted
71 {
72 parent_device_id = sqlite3_column_int64 (stmt, 1);
73 parent_seq_no = sqlite3_column_int64 (stmt, 2);
Alexander Afanasyev707f6df2013-01-04 22:46:15 -080074 parent_device_name = string(reinterpret_cast<const char*> (sqlite3_column_blob (stmt, 4)), sqlite3_column_bytes (stmt, 4));
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080075 }
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080076 }
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080077
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080078 sqlite3_finalize (stmt);
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080079 return make_tuple (version, parent_device_id, parent_seq_no, parent_device_name);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080080}
81
Alexander Afanasyeva199f972013-01-02 19:37:26 -080082// local add action. remote action is extracted from content object
83void
84ActionLog::AddActionUpdate (const std::string &filename,
85 const Hash &hash,
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080086 time_t atime, time_t mtime, time_t ctime,
Alexander Afanasyeva199f972013-01-02 19:37:26 -080087 int mode)
88{
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080089 sqlite3_exec (m_db, "BEGIN TRANSACTION;", 0,0,0);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080090
91 sqlite3_int64 seq_no = GetNextLocalSeqNo ();
92 sqlite3_int64 version = 0;
93 sqlite3_int64 parent_device_id = -1;
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080094 string parent_device_name;
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080095 sqlite3_int64 parent_seq_no = -1;
Alexander Afanasyeva199f972013-01-02 19:37:26 -080096
Alexander Afanasyev433ecda2013-01-02 22:13:45 -080097 sqlite3_int64 action_time = time (0);
98
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080099 tie (version, parent_device_id, parent_seq_no, parent_device_name) = GetExistingRecord (filename);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800100
101 sqlite3_stmt *stmt;
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800102 int res = sqlite3_prepare_v2 (m_db, "INSERT INTO ActionLog "
103 "(device_id, seq_no, action, filename, version, action_timestamp, "
104 "file_hash, file_atime, file_mtime, file_ctime, file_chmod, "
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800105 "parent_device_id, parent_seq_no, "
106 "action_name, action_content_object) "
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800107 "VALUES (?, ?, ?, ?, ?, datetime(?, 'unixepoch'),"
108 " ?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?,"
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800109 " ?, ?, "
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800110 " ?, ?);", -1, &stmt, 0);
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800111
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800112 // cout << "INSERT INTO ActionLog "
113 // "(device_id, seq_no, action, filename, version, action_timestamp, "
114 // "file_hash, file_atime, file_mtime, file_ctime, file_chmod, "
115 // "parent_device_id, parent_seq_no) "
116 // "VALUES (?, ?, ?, ?, ?, datetime(?, 'unixepoch'),"
117 // " ?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?,"
118 // " ?, ?)" << endl;
119
120 if (res != SQLITE_OK)
121 {
122 BOOST_THROW_EXCEPTION (Error::Db ()
123 << errmsg_info_str (sqlite3_errmsg (m_db))
124 );
125 // << errmsg_info_str ("Some error with prepare AddActionUpdate"));
126 }
127
128
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800129 sqlite3_bind_int64 (stmt, 1, m_localDeviceId);
130 sqlite3_bind_int64 (stmt, 2, seq_no);
131 sqlite3_bind_int (stmt, 3, 0);
132 sqlite3_bind_text (stmt, 4, filename.c_str (), filename.size (), SQLITE_TRANSIENT);
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800133 sqlite3_bind_int64 (stmt, 5, version);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800134 sqlite3_bind_int64 (stmt, 6, action_time);
135
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800136 sqlite3_bind_blob (stmt, 7, hash.GetHash (), hash.GetHashBytes (), SQLITE_TRANSIENT);
137
138 sqlite3_bind_int64 (stmt, 8, atime);
139 sqlite3_bind_int64 (stmt, 9, mtime);
140 sqlite3_bind_int64 (stmt, 10, ctime);
141 sqlite3_bind_int (stmt, 11, mode);
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800142
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800143 if (parent_device_id > 0 && parent_seq_no > 0)
144 {
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800145 sqlite3_bind_int64 (stmt, 12, parent_device_id);
146 sqlite3_bind_int64 (stmt, 13, parent_seq_no);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800147 }
148 else
149 {
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800150 sqlite3_bind_null (stmt, 12);
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800151 sqlite3_bind_null (stmt, 13);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800152 }
153
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800154 // missing part: creating ContentObject for the action !!!
155
156 ActionItem item;
157 item.set_action (ActionItem::UPDATE);
158 item.set_filename (filename);
159 item.set_version (version);
160 item.set_timestamp (action_time);
161 item.set_file_hash (hash.GetHash (), hash.GetHashBytes ());
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800162 item.set_atime (atime);
163 item.set_mtime (mtime);
164 item.set_ctime (ctime);
165 item.set_mode (mode);
166
167 if (parent_device_id > 0 && parent_seq_no > 0)
168 {
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -0800169 cout << Name (reinterpret_cast<const unsigned char *> (parent_device_name.c_str ()),
170 parent_device_name.size ()) << endl;
Alexander Afanasyev707f6df2013-01-04 22:46:15 -0800171
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800172 item.set_parent_device_name (parent_device_name);
173 item.set_parent_seq_no (parent_seq_no);
174 }
175
176 // assign name to the action, serialize action, and create content object
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800177
178 string item_msg;
179 item.SerializeToString (&item_msg);
180 Name actionName (m_localName);
181 actionName
182 .appendComp ("action")
183 .appendComp (m_sharedFolderName)
184 .appendComp (seq_no);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800185
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800186 Bytes actionData = m_ccnx->createContentObject (actionName, item_msg.c_str (), item_msg.size ());
187 CcnxCharbufPtr namePtr = actionName.toCcnxCharbuf ();
188
189 sqlite3_bind_blob (stmt, 14, namePtr->buf (), namePtr->length (), SQLITE_TRANSIENT);
190 sqlite3_bind_blob (stmt, 15, &actionData[0], actionData.size (), SQLITE_TRANSIENT);
191
192 sqlite3_step (stmt);
193
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800194 sqlite3_finalize (stmt);
195
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800196 sqlite3_exec (m_db, "END TRANSACTION;", 0,0,0);
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800197}
198
199void
200ActionLog::AddActionMove (const std::string &oldFile, const std::string &newFile)
201{
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800202 // not supported yet
203 BOOST_THROW_EXCEPTION (Error::Db ()
204 << errmsg_info_str ("Move operation is not yet supported"));
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800205}
206
207void
208ActionLog::AddActionDelete (const std::string &filename)
209{
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800210 sqlite3_exec (m_db, "BEGIN TRANSACTION;", 0,0,0);
211
212 sqlite3_int64 version = 0;
213 sqlite3_int64 parent_device_id = -1;
214 string parent_device_name;
215 sqlite3_int64 parent_seq_no = -1;
216
217 sqlite3_int64 action_time = time (0);
218
219 tie (version, parent_device_id, parent_seq_no, parent_device_name) = GetExistingRecord (filename);
220 if (parent_device_id < 0) // no records exist or file was already deleted
221 {
222 sqlite3_exec (m_db, "END TRANSACTION;", 0,0,0);
223 return;
224 }
225
226 sqlite3_int64 seq_no = GetNextLocalSeqNo ();
227
228 sqlite3_stmt *stmt;
229 sqlite3_prepare_v2 (m_db, "INSERT INTO ActionLog "
230 "(device_id, seq_no, action, filename, version, action_timestamp, "
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800231 "parent_device_id, parent_seq_no, "
232 "action_name, action_content_object) "
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800233 "VALUES (?, ?, ?, ?, ?, datetime(?, 'unixepoch'),"
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800234 " ?, ?,"
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800235 " ?, ?)", -1, &stmt, 0);
236
237 sqlite3_bind_int64 (stmt, 1, m_localDeviceId);
238 sqlite3_bind_int64 (stmt, 2, seq_no);
239 sqlite3_bind_int (stmt, 3, 1);
240 sqlite3_bind_text (stmt, 4, filename.c_str (), filename.size (), SQLITE_TRANSIENT);
241 sqlite3_bind_int64 (stmt, 5, version);
242 sqlite3_bind_int64 (stmt, 6, action_time);
243
244 sqlite3_bind_int64 (stmt, 7, parent_device_id);
245 sqlite3_bind_int64 (stmt, 8, parent_seq_no);
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800246
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800247
248 ActionItem item;
249 item.set_action (ActionItem::UPDATE);
250 item.set_filename (filename);
251 item.set_version (version);
252 item.set_timestamp (action_time);
253 item.set_parent_device_name (parent_device_name);
254 item.set_parent_seq_no (parent_seq_no);
255
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -0800256 string item_msg;
257 item.SerializeToString (&item_msg);
258 Name actionName (m_localName);
259 actionName
260 .appendComp ("action")
261 .appendComp (m_sharedFolderName)
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800262 .appendComp (seq_no);
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -0800263
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800264 Bytes actionData = m_ccnx->createContentObject (actionName, item_msg.c_str (), item_msg.size ());
265 CcnxCharbufPtr namePtr = actionName.toCcnxCharbuf ();
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -0800266
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800267 sqlite3_bind_blob (stmt, 9, namePtr->buf (), namePtr->length (), SQLITE_TRANSIENT);
268 sqlite3_bind_blob (stmt, 10, &actionData[0], actionData.size (), SQLITE_TRANSIENT);
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -0800269
270 sqlite3_step (stmt);
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -0800271
272 // cout << Ccnx::Name (reinterpret_cast<const unsigned char *> (parent_device_name.c_str ()),
273 // parent_device_name.size ()) << endl;
Alexander Afanasyev707f6df2013-01-04 22:46:15 -0800274
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800275 // assign name to the action, serialize action, and create content object
276
277 sqlite3_finalize (stmt);
278
279 sqlite3_exec (m_db, "END TRANSACTION;", 0,0,0);
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800280}
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800281
282
283void
284ActionLog::apply_action_xFun (sqlite3_context *context, int argc, sqlite3_value **argv)
285{
286 ActionLog *the = reinterpret_cast<ActionLog*> (sqlite3_user_data (context));
287
Alexander Afanasyev3c2b7282013-01-04 20:34:51 -0800288 if (argc != 10)
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800289 {
290 sqlite3_result_error (context, "``apply_action'' expects 8 arguments", -1);
291 return;
292 }
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800293
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800294 // cout << "apply_function called with " << argc << endl;
295
296 // cout << "device_name: " << sqlite3_value_text (argv[0]) << endl;
297 // cout << "action: " << sqlite3_value_int (argv[1]) << endl;
298 // cout << "filename: " << sqlite3_value_text (argv[2]) << endl;
299
Alexander Afanasyevd09871f2013-01-04 22:36:37 -0800300 string device_name (reinterpret_cast<const char*> (sqlite3_value_blob (argv[0])), sqlite3_value_bytes (argv[0]));
Alexander Afanasyev3c2b7282013-01-04 20:34:51 -0800301 sqlite3_int64 device_id = sqlite3_value_int64 (argv[1]);
302 sqlite3_int64 seq_no = sqlite3_value_int64 (argv[2]);
303 int action = sqlite3_value_int (argv[3]);
304 string filename = reinterpret_cast<const char*> (sqlite3_value_text (argv[4]));
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800305
306 if (action == 0) // update
307 {
Alexander Afanasyev3c2b7282013-01-04 20:34:51 -0800308 Hash hash (sqlite3_value_blob (argv[5]), sqlite3_value_bytes (argv[5]));
309 time_t atime = static_cast<time_t> (sqlite3_value_int64 (argv[6]));
310 time_t mtime = static_cast<time_t> (sqlite3_value_int64 (argv[7]));
311 time_t ctime = static_cast<time_t> (sqlite3_value_int64 (argv[8]));
312 int mode = sqlite3_value_int (argv[9]);
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800313
Alexander Afanasyev3c2b7282013-01-04 20:34:51 -0800314 cout << "Update " << filename << " " << atime << " " << mtime << " " << ctime << " " << hash << endl;
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800315
316 sqlite3_stmt *stmt;
317 sqlite3_prepare_v2 (the->m_db, "UPDATE FileState "
Alexander Afanasyev3c2b7282013-01-04 20:34:51 -0800318 "SET "
319 "device_id=?, seq_no=?, "
320 "file_hash=?,"
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800321 "file_atime=datetime(?, 'unixepoch'),"
322 "file_mtime=datetime(?, 'unixepoch'),"
323 "file_ctime=datetime(?, 'unixepoch'),"
324 "file_chmod=? "
325 "WHERE type=0 AND filename=?", -1, &stmt, 0);
326
Alexander Afanasyev3c2b7282013-01-04 20:34:51 -0800327 sqlite3_bind_int64 (stmt, 1, device_id);
328 sqlite3_bind_int64 (stmt, 2, seq_no);
329 sqlite3_bind_blob (stmt, 3, hash.GetHash (), hash.GetHashBytes (), SQLITE_TRANSIENT);
330 sqlite3_bind_int64 (stmt, 4, atime);
331 sqlite3_bind_int64 (stmt, 5, mtime);
332 sqlite3_bind_int64 (stmt, 6, ctime);
333 sqlite3_bind_int (stmt, 7, mode);
334 sqlite3_bind_text (stmt, 8, filename.c_str (), -1, SQLITE_TRANSIENT);
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800335
336 sqlite3_step (stmt);
Alexander Afanasyev3c2b7282013-01-04 20:34:51 -0800337
338 // cout << sqlite3_errmsg (the->m_db) << endl;
339
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800340 sqlite3_finalize (stmt);
341
342 int affected_rows = sqlite3_changes (the->m_db);
343 if (affected_rows == 0) // file didn't exist
344 {
345 sqlite3_stmt *stmt;
346 sqlite3_prepare_v2 (the->m_db, "INSERT INTO FileState "
Alexander Afanasyev3c2b7282013-01-04 20:34:51 -0800347 "(type,filename,device_id,seq_no,file_hash,file_atime,file_mtime,file_ctime,file_chmod) "
348 "VALUES (0, ?, ?, ?, ?, "
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800349 "datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?)", -1, &stmt, 0);
350
351 sqlite3_bind_text (stmt, 1, filename.c_str (), -1, SQLITE_TRANSIENT);
Alexander Afanasyev3c2b7282013-01-04 20:34:51 -0800352 sqlite3_bind_int64 (stmt, 2, device_id);
353 sqlite3_bind_int64 (stmt, 3, seq_no);
354 sqlite3_bind_blob (stmt, 4, hash.GetHash (), hash.GetHashBytes (), SQLITE_TRANSIENT);
355 sqlite3_bind_int64 (stmt, 5, atime);
356 sqlite3_bind_int64 (stmt, 6, mtime);
357 sqlite3_bind_int64 (stmt, 7, ctime);
358 sqlite3_bind_int (stmt, 8, mode);
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800359
360 sqlite3_step (stmt);
Alexander Afanasyev3c2b7282013-01-04 20:34:51 -0800361 // cout << sqlite3_errmsg (the->m_db) << endl;
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800362 sqlite3_finalize (stmt);
363 }
364 }
365 else if (action == 1) // delete
366 {
367 sqlite3_stmt *stmt;
368 sqlite3_prepare_v2 (the->m_db, "DELETE FROM FileState WHERE type=0 AND filename=?", -1, &stmt, 0);
369 sqlite3_bind_text (stmt, 1, filename.c_str (), -1, SQLITE_STATIC);
370
371 cout << "Delete " << filename << endl;
372
373 sqlite3_step (stmt);
374 sqlite3_finalize (stmt);
375 }
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800376
377 sqlite3_result_null (context);
378}