Patch level : 4.0 914
Files correlati : ba7.exe Ricompilazione Demo : [ ] Commento : Aggiunto il file relations.ini da piazzare in recdesc che contiene le relazioni tr i file. Uyilizzato nel postino. git-svn-id: svn://10.65.10.50/trunk@16362 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
abfd8beb37
commit
a916acb2f1
@ -51,13 +51,37 @@ void TRecipient::add_expr(char op, const TString& expr)
|
|||||||
bool TRecipient::can_receive(const TRectype& rec) const
|
bool TRecipient::can_receive(const TRectype& rec) const
|
||||||
{
|
{
|
||||||
TExpression e(_expr, _strexpr, TRUE);
|
TExpression e(_expr, _strexpr, TRUE);
|
||||||
|
TString val;
|
||||||
|
|
||||||
for (int v = 0; v < e.numvar(); v++)
|
for (int v = 0; v < e.numvar(); v++)
|
||||||
{
|
{
|
||||||
const char* name = e.varname(v);
|
const TFixed_string name(e.varname(v));
|
||||||
|
|
||||||
|
val.cut(0);
|
||||||
if (rec.exist(name))
|
if (rec.exist(name))
|
||||||
e.setvar(name, rec.get(name));
|
val = rec.get(name);
|
||||||
else
|
else
|
||||||
e.setvar(name, "");
|
{
|
||||||
|
|
||||||
|
const TFieldref f(name, 0);
|
||||||
|
const int logicnum = table2logic(f.id());
|
||||||
|
|
||||||
|
if (logicnum > 0 && logicnum != rec.num())
|
||||||
|
{
|
||||||
|
TToken_string & rel = prefix().get_relation(rec.num(), logicnum);
|
||||||
|
if (rel.full())
|
||||||
|
{
|
||||||
|
TToken_string key;
|
||||||
|
FOR_EACH_TOKEN(rel, tok)
|
||||||
|
key.add(rec.get(tok));
|
||||||
|
const TRectype & joined_rec = cache().get(logicnum, key);
|
||||||
|
val = f.read(joined_rec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
val = f.read(rec);
|
||||||
|
}
|
||||||
|
e.setvar(name, val);
|
||||||
}
|
}
|
||||||
bool yes = e.as_bool();
|
bool yes = e.as_bool();
|
||||||
return yes;
|
return yes;
|
||||||
|
@ -74,6 +74,8 @@ class TRecord_info : public TObject
|
|||||||
RecDes _recdes;
|
RecDes _recdes;
|
||||||
TDirtype _dirtype;
|
TDirtype _dirtype;
|
||||||
int _len;
|
int _len;
|
||||||
|
TString_array _relations;
|
||||||
|
int _logicnum;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void translate_key(TToken_string& t) const;
|
void translate_key(TToken_string& t) const;
|
||||||
@ -91,6 +93,7 @@ public:
|
|||||||
TDirtype dir_type() const { return _dirtype; }
|
TDirtype dir_type() const { return _dirtype; }
|
||||||
bool mutable_dir() const { return _dirtype <= _studir; }
|
bool mutable_dir() const { return _dirtype <= _studir; }
|
||||||
bool fixed_dir() const { return _dirtype > _studir; }
|
bool fixed_dir() const { return _dirtype > _studir; }
|
||||||
|
TToken_string & relation(int logicnum);
|
||||||
|
|
||||||
TRecord_info(int logicnum);
|
TRecord_info(int logicnum);
|
||||||
TRecord_info(const char* name);
|
TRecord_info(const char* name);
|
||||||
@ -170,8 +173,69 @@ void TRecord_info::compute_len()
|
|||||||
_len++;
|
_len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TToken_string & TRecord_info::relation(int logicnum)
|
||||||
|
{
|
||||||
|
if (_relations.empty())
|
||||||
|
{
|
||||||
|
const TFilename rels("recdesc/relations.ini");
|
||||||
|
if (rels.exist())
|
||||||
|
{
|
||||||
|
TString key; key.format("%d", _logicnum);
|
||||||
|
TConfig c(rels, key);
|
||||||
|
TString_array vars;
|
||||||
|
|
||||||
|
c.list_variables(vars, true);
|
||||||
|
|
||||||
|
FOR_EACH_ARRAY_ROW(vars, r, row)
|
||||||
|
{
|
||||||
|
const int num = row->get_int();
|
||||||
|
_relations.add(row->get(), num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TToken_string * rel = _relations.rowptr(logicnum);
|
||||||
|
|
||||||
|
if (rel == NULL)
|
||||||
|
{
|
||||||
|
const RecDes & fd = prefix().get_recdes(_logicnum);
|
||||||
|
const RecDes & rd = prefix().get_recdes(logicnum);
|
||||||
|
const KeyDes& kd = rd.Ky[0]; // Tracciato della chiave primaria
|
||||||
|
|
||||||
|
rel = new TToken_string(EMPTY_STRING);
|
||||||
|
|
||||||
|
for (int i = 0; i < kd.NkFields; i++) // Riempio tutta la chiave primaria
|
||||||
|
{
|
||||||
|
const int nPos = kd.FieldSeq[i] % MaxFields; // Posizione del campo i della chiave
|
||||||
|
const RecFieldDes& dfield = rd.Fd[nPos]; // Nome del campo i della chiave
|
||||||
|
int nBest = -1;
|
||||||
|
double dBest = 0.0;
|
||||||
|
|
||||||
|
for (int j = 0; i < fd.NFields; j++)
|
||||||
|
{
|
||||||
|
const RecFieldDes& field = fd.Fd[j];
|
||||||
|
if (field.TypeF == dfield.TypeF && field.Len == dfield.Len)
|
||||||
|
{
|
||||||
|
const double fuzzy = xvt_str_fuzzy_compare(field.Name, dfield.Name);
|
||||||
|
if (fuzzy > dBest)
|
||||||
|
{
|
||||||
|
nBest = j;
|
||||||
|
dBest = fuzzy;
|
||||||
|
if (dBest == 1.0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rel->add(nBest >= 0 ? fd.Fd[nBest].Name : "");
|
||||||
|
}
|
||||||
|
_relations.add(rel, logicnum);
|
||||||
|
}
|
||||||
|
return *((TToken_string *) rel);
|
||||||
|
}
|
||||||
|
|
||||||
TRecord_info::TRecord_info(int logicnum)
|
TRecord_info::TRecord_info(int logicnum)
|
||||||
{
|
{
|
||||||
|
_logicnum = logicnum;
|
||||||
memset(&_recdes, 0, sizeof(_recdes));
|
memset(&_recdes, 0, sizeof(_recdes));
|
||||||
|
|
||||||
FileDes fd; memset(&fd, 0, sizeof(fd));
|
FileDes fd; memset(&fd, 0, sizeof(fd));
|
||||||
@ -187,6 +251,7 @@ TRecord_info::TRecord_info(int logicnum)
|
|||||||
|
|
||||||
bool TRecord_info::create(TTrec& rec, TToken_string& keys)
|
bool TRecord_info::create(TTrec& rec, TToken_string& keys)
|
||||||
{
|
{
|
||||||
|
_logicnum = rec.num();
|
||||||
rec.rehash();
|
rec.rehash();
|
||||||
const int num_keys = rec.keys();
|
const int num_keys = rec.keys();
|
||||||
|
|
||||||
@ -697,6 +762,12 @@ const RecDes& TFile_manager::get_recdes(int logicnum) const
|
|||||||
const TRecord_info& i = recinfo(logicnum);
|
const TRecord_info& i = recinfo(logicnum);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
TToken_string& TFile_manager::get_relation(int fromlogic, int tologic) const
|
||||||
|
{
|
||||||
|
TRecord_info& i = recinfo(fromlogic);
|
||||||
|
|
||||||
|
return i.relation(tologic);
|
||||||
|
}
|
||||||
|
|
||||||
const RecDes& TFile_manager::update_recdes(int logicnum)
|
const RecDes& TFile_manager::update_recdes(int logicnum)
|
||||||
{
|
{
|
||||||
|
@ -40,6 +40,7 @@ public:
|
|||||||
|
|
||||||
const TFilename& get_filename(TIsam_handle num) const;
|
const TFilename& get_filename(TIsam_handle num) const;
|
||||||
const FileDes& get_filedes(TIsam_handle num) const;
|
const FileDes& get_filedes(TIsam_handle num) const;
|
||||||
|
TToken_string & get_relation(int fromlogic, int tologic) const;
|
||||||
const RecDes& get_recdes(int logicnum) const;
|
const RecDes& get_recdes(int logicnum) const;
|
||||||
TIsam_handle get_handle(TFilename& name);
|
TIsam_handle get_handle(TFilename& name);
|
||||||
const RecDes& update_recdes(int logicnum);
|
const RecDes& update_recdes(int logicnum);
|
||||||
@ -190,6 +191,9 @@ public:
|
|||||||
const RecDes& get_recdes(int logicnum) const
|
const RecDes& get_recdes(int logicnum) const
|
||||||
{ return _manager.get_recdes(logicnum); }
|
{ return _manager.get_recdes(logicnum); }
|
||||||
|
|
||||||
|
TToken_string & get_relation(int fromlogic, int tologic) const
|
||||||
|
{ return _manager.get_relation(fromlogic, tologic); }
|
||||||
|
|
||||||
bool add_recdes(int logicnum, TTrec& rec, TToken_string& keys)
|
bool add_recdes(int logicnum, TTrec& rec, TToken_string& keys)
|
||||||
{ return _manager.add_recdes(logicnum, rec, keys); }
|
{ return _manager.add_recdes(logicnum, rec, keys); }
|
||||||
|
|
||||||
|
@ -1368,9 +1368,14 @@ void TRelation_application::main_loop()
|
|||||||
query_mode();
|
query_mode();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
const TMask_field & f = _mask->focus_field();
|
||||||
|
|
||||||
|
_mask->first_focus(-f.dlg());
|
||||||
modify_mode();
|
modify_mode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case K_INS:
|
case K_INS:
|
||||||
if (_mask->query_mode() || save(TRUE))
|
if (_mask->query_mode() || save(TRUE))
|
||||||
|
2
include/relations.ini
Executable file
2
include/relations.ini
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
[23]
|
||||||
|
26=CODCAUS
|
Loading…
x
Reference in New Issue
Block a user