Patch level : 12.0 no-patch

Files correlati     : include
Commento            : Aggiunta possibilità di passare la chiave a TDB_cache, il caso più comune per usare questa classe è utilizzare il singleton cache() all'interno del programma
This commit is contained in:
Mattia Tollari 2019-06-27 15:01:44 +02:00
parent 3ffa118088
commit e0d16ec6b8
2 changed files with 34 additions and 2 deletions

View File

@ -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)

View File

@ -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);