Patch level : 10.0

Files correlati     : lv
Ricompilazione Demo : [ ]
Commento            :
Corretta cache sulle tabelle di modulo
Aumentata lunghezza massima del nome del produttore da 50 a 255 caratteri


git-svn-id: svn://10.65.10.50/trunk@17198 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2008-09-09 14:57:58 +00:00
parent 49f97904ae
commit 602827b7ea
3 changed files with 52 additions and 39 deletions

View File

@ -1,12 +1,9 @@
#include <prefix.h> #include <prefix.h>
#include <recarray.h> #include <recarray.h>
#include <tabmod.h>
#include <tabutil.h> #include <tabutil.h>
#include <user.h> #include <user.h>
#include <user.h>
#include <stdlib.h>
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// TRecord_Array // TRecord_Array
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
@ -465,7 +462,7 @@ void TFile_cache::construct(int key)
_changed = false; _changed = false;
} }
TFile_cache::TFile_cache(TLocalisamfile *f , int key) TFile_cache::TFile_cache(TLocalisamfile* f , int key)
{ {
construct(key); construct(key);
_filecode << f->num(); _filecode << f->num();
@ -473,7 +470,7 @@ TFile_cache::TFile_cache(TLocalisamfile *f , int key)
} }
TFile_cache::TFile_cache(int num, int key) TFile_cache::TFile_cache(int num, int key)
: _key(key) : _key(key)
{ {
construct(key); construct(key);
_filecode << num; _filecode << num;
@ -512,7 +509,10 @@ void TFile_cache::init_file(TLocalisamfile* f)
int logicnum = atoi(_filecode); int logicnum = atoi(_filecode);
if (logicnum == 0) if (logicnum == 0)
{ {
_file = new TTable(_filecode); if (_filecode == '&')
_file = new TModule_table(_filecode);
else
_file = new TTable(_filecode);
logicnum = _file->num(); logicnum = _file->num();
} }
else else
@ -599,16 +599,17 @@ const TObject& TFile_cache::query(const char* code)
{ {
TLocalisamfile& f = file(); TLocalisamfile& f = file();
TRectype& curr = f.curr(); TRectype& curr = f.curr();
if (_code.not_empty()) if (_code.full())
{ {
const RecDes* recd = curr.rec_des(); // Descrizione del record della testata const RecDes* recd = curr.rec_des(); // Descrizione del record della testata
const KeyDes& kd = recd->Ky[_key-1]; // Elenco dei campi della chiave const KeyDes& kd = recd->Ky[_key-1]; // Elenco dei campi della chiave
for (int i = f.tab() ? 1 : 0; i < kd.NkFields; i++) // Riempie la chiave selezionata const int fi = f.tab() ? 1 : (f.num() == LF_TABMOD ? 2 : 0);
for (int i = fi; i < kd.NkFields; i++) // Riempie la chiave selezionata
{ {
const int nf = kd.FieldSeq[i] % MaxFields; const int nf = kd.FieldSeq[i] % MaxFields;
const RecFieldDes& rf = recd->Fd[nf]; const RecFieldDes& rf = recd->Fd[nf];
const char* val = _code.get(); const char* val = _code.get();
if (val) if (val && *val)
curr.put(rf.Name, val); curr.put(rf.Name, val);
else else
curr.zero(rf.Name); curr.zero(rf.Name);
@ -619,14 +620,14 @@ const TObject& TFile_cache::query(const char* code)
_error = _iskeyerr; _error = _iskeyerr;
switch (_error) switch (_error)
{ {
case NOERR: case NOERR:
break; break;
case _iskeynotfound: case _iskeynotfound:
case _iseof: case _iseof:
case _isemptyfile: case _isemptyfile:
default: default:
curr.zero(); curr.zero();
break; break;
} }
obj = rec2obj(curr); obj = rec2obj(curr);
_cache.add(_code, obj); _cache.add(_code, obj);
@ -792,24 +793,39 @@ TRecord_cache& TDB_cache::rec_cache(int file)
return *rc; return *rc;
} }
int TDB_cache::build_table_key(const char* table, const char* key, TToken_string& k) const
{
int file = LF_TAB;
if (!isalnum(*table)) // gestisco i casi come %IVA e &AUT
{
switch (*table)
{
case '%': file = LF_TABCOM; break;
case '^': file = LF_TABGEN; break;
case '&': file = LF_TABMOD; break;
case '$':
default : file = LF_TAB; break;
}
table++; // Skippa il primo carattere speciale
}
k = table;
k.add(key);
return file;
}
const TRectype& TDB_cache::get(const char* table, const char* key) const TRectype& TDB_cache::get(const char* table, const char* key)
{ {
CHECKS(table && *table, "Invalid Table code ", table); CHECKS(table && *table, "Invalid Table code ", table);
int file = LF_TAB;
if (*table == '%') TToken_string tabkey;
{ const int file = build_table_key(table, key, tabkey);
file = LF_TABCOM;
table++;
}
TString80 tabkey;
tabkey.format("%s|%s", table, key);
return get(file, tabkey); return get(file, tabkey);
} }
const TRectype& TDB_cache::get(const TRectype& curr) const TRectype& TDB_cache::get(const TRectype& curr)
{ {
const int num = curr.num(); const int num = curr.num();
if (num == LF_TAB || num == LF_TABCOM) if (num == LF_TAB || num == LF_TABCOM || num == LF_TABGEN || num == LF_TABMOD)
return get(curr.get("COD"), curr.get("CODTAB")); return get(curr.get("COD"), curr.get("CODTAB"));
const RecDes& recd = *curr.rec_des(); // Descrizione del record della testata const RecDes& recd = *curr.rec_des(); // Descrizione del record della testata
@ -833,14 +849,8 @@ bool TDB_cache::discard(const char *table, const char* key)
{ {
CHECK(table && *table, "Invalid Table code"); CHECK(table && *table, "Invalid Table code");
int file = LF_TAB; TToken_string tabkey;
if (*table == '%') const int file = build_table_key(table, key, tabkey);
{
file = LF_TABCOM;
table++;
}
TString80 tabkey;
tabkey << table << '|' << key;
return rec_cache(file).discard(tabkey); return rec_cache(file).discard(tabkey);
} }
@ -879,7 +889,7 @@ const TString_array& user_and_groups()
if (_uag.empty() || _uag.row(0) != user()) if (_uag.empty() || _uag.row(0) != user())
{ {
_uag.destroy(); _uag.destroy();
_uag.add(user()); // Inserisco l'utente stesso come primo _uag.add(user()); // Inserisco l'utente corrente come primo
if (prefix_valid()) // Costruisce lista dei gruppi solo se possibile if (prefix_valid()) // Costruisce lista dei gruppi solo se possibile
{ {
TLocalisamfile user(LF_USER); TLocalisamfile user(LF_USER);

View File

@ -228,7 +228,7 @@ public:
virtual const TRectype& get(const char* chiave); virtual const TRectype& get(const char* chiave);
// @cmember ritorna il campo (chiama get(chiave)) // @cmember ritorna il campo (chiama get(chiave))
const TString& get(const char* chiave, const char* campo); const TString& get(const char* chiave, const char* campo);
// @cmember ritorna il record con una determinata chiave numerica // @cmember ritorna il record con una determinata chiave numerica
const TRectype& get(long chiave); const TRectype& get(long chiave);
const TString& get(long chiave, const char* campo); const TString& get(long chiave, const char* campo);
@ -242,6 +242,9 @@ public:
class TDB_cache : public TArray class TDB_cache : public TArray
{ {
protected:
int build_table_key(const char* table, const char* key, TToken_string& k) const;
public: public:
TRecord_cache& rec_cache(int file); TRecord_cache& rec_cache(int file);

View File

@ -528,7 +528,7 @@ const char * encode(
// @xref <f decode> // @xref <f decode>
{ {
char* tmp = get_tmp_string(50).get_buffer(); char* tmp = get_tmp_string(255).get_buffer();
int i; int i;
for (i = 0; data[i]; i++) for (i = 0; data[i]; i++)
tmp[i] = data[i] + (i < 8 ? encryption_key[i] : data[i - 8]); tmp[i] = data[i] + (i < 8 ? encryption_key[i] : data[i - 8]);
@ -546,7 +546,7 @@ const char * decode(
// @xref <f encode> // @xref <f encode>
{ {
char* tmp = get_tmp_string(50).get_buffer(); char* tmp = get_tmp_string(255).get_buffer();
int i; int i;
for (i = 0; data[i]; i++) for (i = 0; data[i]; i++)