From e25384c3223cdd85412ef6580bf48b7d0a9afcc0 Mon Sep 17 00:00:00 2001 From: Harbour Date: Wed, 19 Dec 2007 20:13:09 +0200 Subject: [PATCH] Prepare for arbitrary object connection. The broken commits start. --- include/elements.H | 37 +++++++++++++++--- include/proto.H | 11 ++++++ include/sfinx.H | 6 ++- scripts/db.sql | 60 +++++++++++++++++++--------- sfinx/sfinx.C | 113 ++++++++++++++++++++++++++++++++++------------------- 5 files changed, 160 insertions(+), 67 deletions(-) diff --git a/include/elements.H b/include/elements.H index ef345f8..9726f86 100644 --- a/include/elements.H +++ b/include/elements.H @@ -71,6 +71,26 @@ protected: static sfinx_t *make_sfinx_element(u32_t id); +class sfinx_object_t : public sfinx_t { + + void update_size() { size(sizeof(u32_t) * 2); } + + public: + + u32_t oid, otype; + string name, description, sorted_path; + sfinx_object_t(u32_t _id = SFINX_ELEMENT_OBJECT) : sfinx_t(_id) { oid = otype = 0; } + void copy(sfinx_t *s) { + if (!dynamic_cast(s)) + bug(); + copy_size_id(s); + oid = ((sfinx_object_t *)s)->oid; + otype = ((sfinx_object_t *)s)->otype; + } + u32_t copy_from(u8_t *buf, u32_t object_size_in_buf) { bug(); } + u32_t copy_to(u8_t *buf, u32_t available_buf_space) { bug(); } +}; + class sfinx_8bit_t : public sfinx_t { u8_t val_; public: @@ -665,20 +685,20 @@ class sfinx_pair_vector_t : public sfinx_t { class sfinx_file_t : public sfinx_t { void update_size() { - size(sizeof(u32_t) * (2 + slices.size() + 1) + 2 * sizeof(u64_t) + name.size() + 1 + + size(sizeof(u32_t) * (3 + slices.size() + 1) + 2 * sizeof(u64_t) + name.size() + 1 + orig_name.size() + 1 + title.size() + 1 + authority.size() + 1 + description.size() + 1 + comments.size() + 1 + ctime.size() + etime.size() + 4 * sizeof(u8_t) + mimetype.size() + 1 + csum.size() + 1 + compressed_csum.size() + 1); } public: - u32_t file_id, main_slice_id; + u32_t file_id, main_obj_id, main_obj_type; u64_t fsize, compressed_fsize; string name, orig_name, title, authority, description, comments, mimetype, csum, compressed_csum; sfinx_timestamp_t ctime, etime; bool is_directory, sorted_location, store_compressed, generate_csum; vector slices; // ÍÁÓÓÉ× id ÄÏÐÏÌÎÉÔÅÌØÎÙÈ ÓÌÁÊÓÏ× sfinx_file_t(u32_t id = SFINX_ELEMENT_FILE) : sfinx_t(id) { clear(); } - void clear() { slices.clear(); file_id = main_slice_id = fsize = 0; is_directory = false; size(0); } + void clear() { slices.clear(); file_id = main_obj_type = main_obj_id = fsize = 0; is_directory = false; size(0); } const char *strid() { return "File"; } void copy(sfinx_t *s) { sfinx_file_t *src = dynamic_cast(s); @@ -688,7 +708,8 @@ class sfinx_file_t : public sfinx_t { src->update_size(); copy_size_id(src); file_id = src->file_id; - main_slice_id = src->main_slice_id; + main_obj_id = src->main_obj_id; + main_obj_type = src->main_obj_type; fsize = src->fsize; compressed_fsize = src->compressed_fsize; name = src->name; @@ -725,7 +746,9 @@ class sfinx_file_t : public sfinx_t { v = generate_csum; memcpy(buf + offset, &v, sizeof(u8_t)); offset += sizeof(u8_t); - memcpy(buf + offset, &main_slice_id, sizeof(u32_t)); + memcpy(buf + offset, &main_obj_id, sizeof(u32_t)); + offset += sizeof(u32_t); + memcpy(buf + offset, &main_obj_type, sizeof(u32_t)); offset += sizeof(u32_t); memcpy(buf + offset, &fsize, sizeof(u64_t)); offset += sizeof(u64_t); @@ -791,7 +814,9 @@ class sfinx_file_t : public sfinx_t { memcpy(&v, buf + offset, sizeof(u8_t)); generate_csum = v; offset += sizeof(u8_t); - memcpy(&main_slice_id, buf + offset, sizeof(u32_t)); + memcpy(&main_obj_id, buf + offset, sizeof(u32_t)); + offset += sizeof(u32_t); + memcpy(&main_obj_type, buf + offset, sizeof(u32_t)); offset += sizeof(u32_t); memcpy(&fsize, buf + offset, sizeof(u64_t)); offset += sizeof(u64_t); diff --git a/include/proto.H b/include/proto.H index 68639c2..c8deae7 100644 --- a/include/proto.H +++ b/include/proto.H @@ -92,6 +92,7 @@ #define SFINX_ELEMENT_PROGRESS 0x11c #define SFINX_ELEMENT_SEARCH_QUERY 0x11d #define SFINX_ELEMENT_SEARCH_RESULT 0x11e +#define SFINX_ELEMENT_OBJECT 0x11f // commands #define SFINX_GET_SLICES_STAT 0x200 @@ -127,6 +128,16 @@ #define SFINX_SEARCH_QUERY 0x224 #define SFINX_SEARCH_RESULT 0x225 +// objects +#define SFINX_SLICE_OBJECT 1 +#define SFINX_FILE_OBJECT 2 +#define SFINX_NOTE_OBJECT 3 +#define SFINX_EVENT_OBJECT 4 +#define SFINX_CONTACT_OBJECT 5 +#define SFINX_TASK_OBJECT 6 +#define SFINX_MESSAGE_OBJECT 7 +#define SFINX_KNOWLEDGE_OBJECT 8 + #define SFINX_KEY_UNASSIGNED 0 // files module conf keys #define FILES_MODULE_UNSORTED_PATH 1 diff --git a/include/sfinx.H b/include/sfinx.H index fc68ab9..1005c62 100644 --- a/include/sfinx.H +++ b/include/sfinx.H @@ -147,9 +147,11 @@ class sfinx_app : public F_App { void dbopen(); void listen(); void load_module_conf(u32_t mid); - void get_sorted_path(u32_t slice_id, string *sorted_location); - bool make_sorted_path(u32_t slice_id); + void set_sorted_path(sfinx_object_t &obj); + bool sorted_path_mkdir(sfinx_object_t &obj); + bool sorted_path_mkdir(u32_t slice_id); u32_t parent_id(u32_t slice_id); + bool parent_object(sfinx_object_t &src, sfinx_object_t *dst); string slice_name(u32_t slice_id); string slice_directory(u32_t slice_id); diff --git a/scripts/db.sql b/scripts/db.sql index 8e68a03..6309b3b 100644 --- a/scripts/db.sql +++ b/scripts/db.sql @@ -7,10 +7,32 @@ set sql dialect 3; set names koi8r; create database '/usr/local/sfinx/sfinx.fdb' user 'sysdba' password 'harbour' page_size 16384 default character set koi8r; +create table objects ( + id INTEGER not null, + name VARCHAR(64) not null, + description VARCHAR(256) not null, + /* TODO: ÉÍÑ ÔÁÂÌÉÃÙ Ó ÏÐÉÓÁÎÉÅÍ ÐÏÌÅÊ É Ô.Ä. */ + constraint pkobjects PRIMARY KEY (id), + UNIQUE (name) +); + +insert into objects (id, name, description) values (1, 'slice', 'User defined abstraction'); +insert into objects (id, name, description) values (2, 'file', 'Any file, containing some data'); +insert into objects (id, name, description) values (3, 'note', 'Note about smth.'); +insert into objects (id, name, description) values (4, 'event', 'Event'); +insert into objects (id, name, description) values (5, 'contact', 'Contact'); +insert into objects (id, name, description) values (6, 'task', 'Task or plan'); +insert into objects (id, name, description) values (7, 'message', 'Mail or IM'); +insert into objects (id, name, description) values (8, 'knowledge', 'Knowledge / kh [ know how ]'); + +/* TODO: rule / intention / aim / dream */ + create sequence slice_id; set generator slice_id to 0; -/* slices - ÔÁÂÌÉÃÁ ËÁÔÅÇÏÒÉÊ/ÓÒÅÚÏ× */ +/* slices - ÔÁÂÌÉÃÁ ËÁÔÅÇÏÒÉÊ/ÓÒÅÚÏ×/ÁÂÓÔÒÁËÃÉÊ. Slice ÏÔÌÉÞÁÅÔÓÑ ÏÔ ÏÓÔÁÌØÎÙÈ + ÏÂØÅËÔÏ× ÏÔÓÔÕÔÓÔ×ÉÅÍ ÇÌÁ×ÎÏÊ Ó×ÑÚÉ, Ô.Å. Ñ×ÌÑÅÔÓÑ ÉÚÎÁÞÁÌØÎÙÍ [ Dao ] É + ÍÏÖÅÔ ÓÕÝÅÓÔ×Ï×ÁÔØ ÓÁÍ ÐÏ-ÓÅÂÅ */ create table slices ( id BIGINT not null, @@ -32,7 +54,7 @@ create index slices_ctime on slices(ctime); set term ^ ; -/* ÕÎÉ×ÅÒÓÁÌØÎÙÊ ÔÒÉÇÇÅÒ */ +/* ÕÎÉ×ÅÒÓÁÌØÎÙÊ ÔÒÉÇÇÅÒ: firebird >= 2.x ËÁÖÉÓØ */ create trigger slice_trg for slices active before insert or update position 0 @@ -90,7 +112,8 @@ create table files ( /* ÄÁÔÁ ÉÚÍÅÎÅÎÉÑ ÉÎÆÙ Ï ÆÁÊÌÅ × ÂÁÚÅ */ etime timestamp not null, - main_slice_id BIGINT not null, + main_obj_id BIGINT not null, + main_obj_type INTEGER not null, fsize BIGINT default 0, sha256 VARCHAR(64), @@ -117,7 +140,7 @@ create table files ( /* added_by_uid INTEGER not null */ constraint pkfiles PRIMARY KEY (id), - UNIQUE (main_slice_id, name) + UNIQUE (main_obj_id, main_obj_type, name) ); create index files_etime on files(etime); @@ -145,12 +168,13 @@ end set term ^ ; -/* ÄÏÐ-ÔÁÂÌÉÃÁ file-ÓÌÁÊÓÏ× */ +/* ÄÏÐ-ÔÁÂÌÉÃÁ Ó×ÑÚÉ ÆÁÊÌÏ× É ÏÂØÅËÔÏ× */ -create table file_slices ( +create table file_objects ( file_id BIGINT, - slice_id BIGINT, - constraint pkfile_slices PRIMARY KEY (file_id, slice_id) + obj_id BIGINT, + obj_type INTEGER, + constraint pkfile_slices PRIMARY KEY (file_id, obj_id, obj_type) ); create sequence note_id; @@ -168,12 +192,13 @@ create table notes ( /* ÄÁÔÁ ÉÚÍÅÎÅÎÉÑ ÉÎÆÙ × ÂÁÚÅ */ etime timestamp not null, - main_slice_id BIGINT not null, + main_obj_id BIGINT not null, + main_obj_type INTEGER not null, /* text field is crypted */ private SMALLINT default 0, constraint pknotes PRIMARY KEY (id), - UNIQUE (main_slice_id, name), + UNIQUE (main_obj_id, main_obj_type, name), UNIQUE (url) ); @@ -184,7 +209,7 @@ create index notes_url on notes(url); /* ÅÓÌÉ Ë ÐÒÉÍÅÒÕ text crypted - ÉÎÄÅËÓ ÎÅ ÎÕÖÅÎ: ÉÎÔÅÒÅÓÎÏ ÅÓÔØ ÌÉ ÔÁËÁÑ ÆÉÇÎÑ ËÁË ÕÓÌÏ×ÎÙÊ ÉÎÄÅËÓ - ÉÎÄÅËÓÉÒÏ×ÁÔØ ÔÏÌØËÏ ÞÁÓÔØ ÔÁÂÌÉÃÙ ÐÏ ÕÓÌÏ×ÉÀ - ËÁËÉÈ-ÌÉÂÏ ÐÏÌÅÊ × row ? */ + ËÁËÉÈ-ÌÉÂÏ ÐÏÌÅÊ × ÔÅËÕÝÅÍ row ? */ /* create index notes_text on notes(text); */ set term ^ ; @@ -204,20 +229,19 @@ end set term ^ ; -/* ÄÏÐ-ÔÁÂÌÉÃÁ note-ÓÌÁÊÓÏ× */ +/* ÄÏÐ-ÔÁÂÌÉÃÁ note-Ó×ÑÚÅÊ */ -create table note_slices ( +create table note_objects ( note_id BIGINT, - slice_id BIGINT, - constraint pknote_slices PRIMARY KEY (note_id, slice_id) + obj_id BIGINT, + obj_type INTEGER, + constraint pknote_slices PRIMARY KEY (note_id, obj_id, obj_type) ); commit; -/* - TODO: +/* TODO: - - ÐÅÒÅÄÅÌÁÔØ yyy_slices ÎÁ yyy_objects É ÄÏÂÁ×ÉÔØ obj_id ÐÏÌÅ - ÔÁÂÌÉÃÁ ÀÚÅÒÏ× - ÔÁÂÌÉÃÁ ÒÅÊÔÉÎÇÏ× ÄÌÑ ÏÂØÅËÔÏ× (files/notes/events/contacts/etc.) - ÔÁÂÌÉÃÁ ÓÔÁÔÉÓÔÉËÉ ÄÌÑ ÄÅÍÏÎÁ diff --git a/sfinx/sfinx.C b/sfinx/sfinx.C index c94ae55..2b8ed05 100644 --- a/sfinx/sfinx.C +++ b/sfinx/sfinx.C @@ -102,22 +102,47 @@ string sfinx_app::slice_directory(u32_t slice_id) return t; } -void sfinx_app::get_sorted_path(u32_t slice_id, string *sorted_location) +bool sfinx_app::parent_object(sfinx_object_t &src, sfinx_object_t *dst) { - string path, sorted_tree_path; - sfinx->files_module_conf.get(FILES_MODULE_SORTED_TREE_PATH, sorted_tree_path); - while(slice_id && (slice_id != 1)) { - path.insert(0, "/" + slice_directory(slice_id)); // TODO: handle spaces in names - slice_id = parent_id(slice_id); - } - *sorted_location = sorted_tree_path + path; + bug(); + return true; } -bool sfinx_app::make_sorted_path(u32_t slice_id) +// for objects other than slices if the main_obj_id == SFINX_SLICE_OBJECT +// directory is the slice one +// for other main_obj_id we look up in the hierarchy - all is created from the +// some slice +void sfinx_app::set_sorted_path(sfinx_object_t &obj) { string path; - get_sorted_path(slice_id, &path); - return system(("mkdir -p " + path).c_str()); + sfinx->files_module_conf.get(FILES_MODULE_SORTED_TREE_PATH, obj.sorted_path); + sfinx_object_t tobj; + tobj.copy(&obj); + while (1) { + if (tobj.otype == SFINX_SLICE_OBJECT) { + path.insert(0, "/" + slice_directory(tobj.oid)); // TODO: handle spaces in names + if (tobj.oid == 1) // root slice + break; + } + if (!parent_object(obj, &tobj)) + bug(); + } + obj.sorted_path += path; +} + +bool sfinx_app::sorted_path_mkdir(u32_t slice_id) +{ + sfinx_object_t obj; + obj.oid = slice_id; + obj.otype = SFINX_SLICE_OBJECT; + set_sorted_path(obj); + return system(("mkdir -p " + obj.sorted_path).c_str()); +} + +bool sfinx_app::sorted_path_mkdir(sfinx_object_t &obj) +{ + set_sorted_path(obj); + return system(("mkdir -p " + obj.sorted_path).c_str()); } int main(int argc, char **argv) @@ -286,7 +311,11 @@ void faraon_session::update_slice(sfinx_slice_t *slice) string old_dir = sfinx->slice_directory(slice->slice_id); if (old_dir != slice->directory()) { string from, to; - sfinx->get_sorted_path(slice->slice_id, &from); + sfinx_object_t o; + o.otype = SFINX_SLICE_OBJECT; + o.oid = slice->slice_id; + sfinx->set_sorted_path(o); + from = o.sorted_path; const char *p = strrchr(from.c_str(), '/'); if (!p) bug(); @@ -374,16 +403,16 @@ void faraon_session::delete_slice_mark_data_unsorted(u32_t slice_id, bool recurs void faraon_session::mark_files_unsorted(u32_t slice_id, bool recursivly, bool remove) { - // delete from file_slices + // delete from file_objects IBPP::Transaction tr = sfinx->driver_->TransactionFactory(sfinx->db_, IBPP::amWrite, IBPP::ilConcurrency, IBPP::lrWait); tr->Start(); IBPP::Statement st = sfinx->driver_->StatementFactory(sfinx->db_, tr); - st->Prepare("delete from file_slices where slice_id = ?"); + st->Prepare("delete from file_objects where obj_type = 1 and obj_id = ?"); st->Set(1, (int32_t)slice_id); st->Execute(); // move to unsorted location - st->Prepare("select name from files where main_slice_id = ?"); + st->Prepare("select name from files where main_obj_type = 1 and main_obj_id = ?"); st->Set(1, (int32_t)slice_id); st->Execute(); string udir, sdir; @@ -400,7 +429,7 @@ void faraon_session::mark_files_unsorted(u32_t slice_id, bool recursivly, bool r move(from, udir); } // delete from files - st->Prepare("delete from files where main_slice_id = ?"); + st->Prepare("delete from files where main_obj_id = 1 and main_obj_id = ?"); st->Set(1, (int32_t)slice_id); st->Execute(); gen_desc_file(slice_id); @@ -412,17 +441,17 @@ void faraon_session::mark_files_unsorted(u32_t slice_id, bool recursivly, bool r tr->Commit(); } -// ÕÓÔÁÎÏ×ÌÅÎ file_id = main_slice_id É name +// ÕÓÔÁÎÏ×ÌÅÎ file_id = main_obj_id [obj_type ???] É name void faraon_session::mark_file_unsorted(sfinx_file_t *f, bool remove) { - // delete from file_slices + // delete from file_objects IBPP::Transaction tr = sfinx->driver_->TransactionFactory(sfinx->db_, IBPP::amWrite, IBPP::ilConcurrency, IBPP::lrWait); tr->Start(); IBPP::Statement st = sfinx->driver_->StatementFactory(sfinx->db_, tr); - f->main_slice_id = f->file_id; + f->main_obj_id = f->file_id; // get file_id - st->Prepare("select id from files where main_slice_id = ? and name = ?"); + st->Prepare("select id from files where main_obj_type = 1 and main_obj_id = ? and name = ?"); st->Set(1, (int32_t)f->file_id); st->Set(2, f->name); int32_t file_id; @@ -431,12 +460,12 @@ void faraon_session::mark_file_unsorted(sfinx_file_t *f, bool remove) return; else st->Get(1, file_id); - st->Prepare("delete from file_slices where file_id = ?"); + st->Prepare("delete from file_objects where file_id = ?"); st->Set(1, file_id); st->Execute(); // move to unsorted location string udir, sdir; - sfinx->get_sorted_path(f->main_slice_id, &sdir); + sfinx->get_sorted_path(f->main_obj_type, f->main_obj_id, &sdir); sdir += "/"; sfinx->files_module_conf.get(FILES_MODULE_UNSORTED_PATH, udir); string from = sdir + f->name; @@ -526,7 +555,7 @@ void faraon_session::relink_slice(sfinx_slice_t *slice) string from, to; sfinx->get_sorted_path(slice->slice_id, &from); sfinx->get_sorted_path(slice->parent_slice_id, &to); - sfinx->make_sorted_path(slice->parent_slice_id); + sfinx->sorted_path_mkdir(slice->parent_slice_id, SFINX_SLICE_OBJECT); move(from, to); // relink IBPP::Transaction tr = sfinx->driver_->TransactionFactory(sfinx->db_, IBPP::amWrite, @@ -734,7 +763,7 @@ bool faraon_session::gen_desc_file(u32_t slice_id) // mimetype st->Prepare("select id, name, title, authority, description, comments, ctime, etime, main_slice_id, " "fsize, sha256, fsize_compressed, sha256_compressed, csum_last_checked, csum_valid, " - "store_in_sorted_location from files where main_slice_id = ?"); + "store_in_sorted_location from files where main_obj_type = 1 and main_obj_id = ?"); st->Set(1, (int32_t)slice_id); st->Execute(); while (st->Fetch()) { @@ -781,7 +810,7 @@ bool faraon_session::gen_desc_file(u32_t slice_id) f << "Compressed csum: " << t << endl; // additional slices IBPP::Statement st1 = sfinx->driver_->StatementFactory(sfinx->db_, tr); - st1->Prepare("select s.name, s.description from slices s, file_slices fs where fs.file_id = ? and fs.slice_id = s.id"); + st1->Prepare("select s.name, s.description from slices s, file_objects fs where fs.file_id = ? and fs.obj_id = s.id and fs.obj_type = 1"); st1->Set(1, (int32_t)fid); st1->Execute(); if (st1->Fetch()) { @@ -815,7 +844,7 @@ void faraon_session::send_file(sfinx_file_t *f) // mimetype st->Prepare("select id, name, title, authority, description, comments, ctime, etime, main_slice_id, " "fsize, sha256, fsize_compressed, sha256_compressed, csum_last_checked, csum_valid, " - "store_in_sorted_location from files where main_slice_id = ? and name = ?"); + "store_in_sorted_location from files where main_obj_type = 1 and main_obj_id = ? and name = ?"); st->Set(1, (int32_t)f->file_id); st->Set(2, f->name); st->Execute(); @@ -852,12 +881,13 @@ void faraon_session::send_file(sfinx_file_t *f) file.mimetype = "Not Set"; } // fill file slices - st->Prepare("select slice_id from file_slices where file_id = ?"); + st->Prepare("select obj_id, obj_type from file_objects where file_id = ?"); st->Set(1, fid); st->Execute(); while (st->Fetch()) { - int32_t slice_id; + int32_t slice_id; //, obj_type; st->Get(1, &slice_id); +// st->Get(2, &slice_id); file.slices.push_back(slice_id); } tr->Commit(); @@ -934,8 +964,8 @@ void faraon_session::files_module_classify(sfinx_file_t *f) tr = sfinx->driver_->TransactionFactory(sfinx->db_, IBPP::amWrite, IBPP::ilConcurrency, IBPP::lrWait); tr->Start(); st = sfinx->driver_->StatementFactory(sfinx->db_, tr); - st->Prepare("insert into files (name, title, authority, description, comments, main_slice_id, fsize, " - "sha256, fsize_compressed, sha256_compressed, store_in_sorted_location) values (?, ?, ?, ?, ?, ?, " + st->Prepare("insert into files (name, title, authority, description, comments, main_obj_id, main_obj_type, fsize, " + "sha256, fsize_compressed, sha256_compressed, store_in_sorted_location) values (?, ?, ?, ?, ?, ?, 1, " "?, ?, ?, ?, ?)"); st->Set(1, f->name); st->Set(2, f->title); @@ -950,7 +980,7 @@ void faraon_session::files_module_classify(sfinx_file_t *f) st->Set(11, f->sorted_location); st->Execute(); - st->Prepare("select id from files where name = ? and main_slice_id = ?"); + st->Prepare("select id from files where name = ? and main_obj_type = 1 and main_obj_id = ?"); st->Set(1, f->name); st->Set(2, (int32_t)f->main_slice_id); st->Execute(); @@ -961,9 +991,9 @@ void faraon_session::files_module_classify(sfinx_file_t *f) st->Get(1, &file_id); debug("added file has id - %d", file_id); } - // add to file_slices + // add to file_objects for (u32_t i = 0; i < f->slices.size(); i++) { - st->Prepare("insert into file_slices (file_id, slice_id) values (?, ?)"); + st->Prepare("insert into file_objects (file_id, obj_id. obj_type) values (?, ?, 1)"); st->Set(1, file_id); st->Set(2, (int64_t)f->slices[i]); st->Execute(); @@ -989,7 +1019,7 @@ bool faraon_session::get_file_by_id(sfinx_file_t *f) IBPP::Statement st = sfinx->driver_->StatementFactory(sfinx->db_, tr); // store_compressed // mimetype - st->Prepare("select name, title, authority, description, comments, ctime, etime, main_slice_id, " + st->Prepare("select name, title, authority, description, comments, ctime, etime, main_obj_id, " "fsize, sha256, fsize_compressed, sha256_compressed, csum_last_checked, csum_valid, " "store_in_sorted_location from files where id = ?"); st->Set(1, (int32_t)f->file_id); @@ -1021,7 +1051,7 @@ bool faraon_session::get_file_by_id(sfinx_file_t *f) } // fill file slices f->slices.clear(); - st->Prepare("select slice_id from file_slices where file_id = ?"); + st->Prepare("select obj_id, obj_type from file_objects where file_id = ?"); st->Set(1, (int32_t)f->file_id); st->Execute(); while (st->Fetch()) { @@ -1060,7 +1090,7 @@ void faraon_session::edit_file(sfinx_file_t *f) tr->Start(); st = sfinx->driver_->StatementFactory(sfinx->db_, tr); st->Prepare("update files set name = ?, title = ?, authority = ?, description = ?, comments = ?, " - "main_slice_id = ?, fsize = ?, sha256 = ?, fsize_compressed = ?, sha256_compressed = ?, " + "main_obj_id = ?, fsize = ?, sha256 = ?, fsize_compressed = ?, sha256_compressed = ?, " "store_in_sorted_location = ? where id = ?"); st->Set(1, f->name); st->Set(2, f->title); @@ -1074,14 +1104,15 @@ void faraon_session::edit_file(sfinx_file_t *f) st->Set(10, f->compressed_csum); st->Set(11, f->sorted_location); st->Set(12, (int32_t)f->file_id); + // main_obj_type ???? st->Execute(); - // add to file_slices - st->Prepare("delete from file_slices where file_id = ?"); + // add to file_objects + st->Prepare("delete from file_objects where file_id = ?"); st->Set(1, (int32_t)f->file_id); st->Execute(); for (u32_t i = 0; i < f->slices.size(); i++) { - st->Prepare("insert into file_slices (file_id, slice_id) values (?, ?)"); + st->Prepare("insert into file_objects (file_id, obj_id, obj_type) values (?, ?, 1)"); st->Set(1, (int32_t)f->file_id); st->Set(2, (int64_t)f->slices[i]); st->Execute(); @@ -1119,7 +1150,7 @@ void faraon_session::search_in_files(string &pattern, sfinx_pair_vector_t *r) tr->Start(); IBPP::Statement st = sfinx->driver_->StatementFactory(sfinx->db_, tr), st1 = sfinx->driver_->StatementFactory(sfinx->db_, tr); - st->Prepare("select id, name, title, authority, description, comments, ctime, etime, main_slice_id, " + st->Prepare("select id, name, title, authority, description, comments, ctime, etime, main_obj_id, " "fsize, sha256, fsize_compressed, sha256_compressed, csum_last_checked, csum_valid, " "store_in_sorted_location from files where name like ? or title like ? or authority like ? or " "description like ? or comments like ?"); @@ -1157,7 +1188,7 @@ void faraon_session::search_in_files(string &pattern, sfinx_pair_vector_t *r) file.sorted_location = sorted_location; file.mimetype = "Not Set"; // fill file slices - st1->Prepare("select slice_id from file_slices where file_id = ?"); + st1->Prepare("select obj_id, obj_type from file_objects where file_id = ?"); st1->Set(1, fid); st1->Execute(); while (st1->Fetch()) { -- 2.11.4.GIT