From e0d16ec6b8e8fd8dc6c7440b221312512ac26614 Mon Sep 17 00:00:00 2001 From: Mattia Tollari Date: Thu, 27 Jun 2019 15:01:44 +0200 Subject: [PATCH] =?UTF-8?q?Patch=20level=20=20=20=20=20=20=20=20=20:=2012.?= =?UTF-8?q?0=20no-patch=20Files=20correlati=20=20=20=20=20:=20include=20Co?= =?UTF-8?q?mmento=20=20=20=20=20=20=20=20=20=20=20=20:=20Aggiunta=20possib?= =?UTF-8?q?ilit=C3=A0=20di=20passare=20la=20chiave=20a=20TDB=5Fcache,=20il?= =?UTF-8?q?=20caso=20pi=C3=B9=20comune=20per=20usare=20questa=20classe=20?= =?UTF-8?q?=C3=A8=20utilizzare=20il=20singleton=20cache()=20all'interno=20?= =?UTF-8?q?del=20programma?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/include/recarray.cpp | 33 +++++++++++++++++++++++++++++++-- src/include/recarray.h | 3 +++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/include/recarray.cpp b/src/include/recarray.cpp index bafdd3ced..f6ef8ac1d 100755 --- a/src/include/recarray.cpp +++ b/src/include/recarray.cpp @@ -957,13 +957,42 @@ int TDB_cache::build_table_key(const char* table, const char* key, TToken_string return file; } -const TRectype& TDB_cache::get(const char* table, const char* key) +const TRectype& TDB_cache::get(const int file, const char* key_tok, const int key) +{ + // Prendo la vecchia chiave + const int old_key = rec_cache(file).key_number(); + // Setto la nuova chiave + rec_cache(file).set_key(key); + // Poi chiamo la get normale + const TRectype& app = get(file, key_tok); + // Ripristino la vecchia chiave per mantenere la compatibilità con i metodi vecchi + // non vorrei rischiare che altre applicazioni si basano sulla chiave vecchia + rec_cache(file).set_key(old_key); + return app; +} + +const TRectype& TDB_cache::get(const char* table, const char* key_tok) { TToken_string tabkey; - const int file = build_table_key(table, key, tabkey); + const int file = build_table_key(table, key_tok, tabkey); return rec_cache(table).get(tabkey); } +const TRectype& TDB_cache::get(const char* table, const char* key_tok, const int key) +{ + TToken_string tabkey; + const int file = build_table_key(table, key_tok, tabkey); + + // Per il giro della vecchia chiave guardare get(const int, const char*, const int) + const int old_key = rec_cache(file).key_number(); + rec_cache(table).set_key(key); + const TRectype& app = rec_cache(table).get(tabkey); + + rec_cache(file).set_key(old_key); + return app; +} + + const TRectype& TDB_cache::get(const TRectype& curr) { const int num = curr.num(); // Numero logico del file (o tabella) diff --git a/src/include/recarray.h b/src/include/recarray.h index 2dfb7d425..b49293570 100755 --- a/src/include/recarray.h +++ b/src/include/recarray.h @@ -184,6 +184,7 @@ public: int io_result(); const int key_number() const { return _key; } + void set_key(const int key) { _key = key; } bool already_loaded(const char* code) const; bool already_loaded(long code) const; @@ -263,9 +264,11 @@ public: void flush(int file) { rec_cache(file).flush(); } void discard(int file); + const TRectype& get(int file, const char* key_tok, const int key); const TRectype& get(int file, const char* key_tok) { return rec_cache(file).get(key_tok); } const TRectype& get(int file, long key) { return rec_cache(file).get(key); } const TRectype& get(const char* table, const char* key_tok); + const TRectype& get(const char* table, const char* key_tok, const int key); const TRectype& get(const TRectype& key); const TRectype& get_rec(int file, char c, long n);