Aggiunta la funzione virtual bool can_write(TRecord_text&, TRelation&) per
effettuare operazioni sul record operazioni prima della scrittura sul file di testo. git-svn-id: svn://10.65.10.50/trunk@5744 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
4e6b6887e0
commit
d2c462a792
@ -200,6 +200,7 @@ void TFile_text::set_rec_parm(TConfig& config, const char* section)
|
||||
TString lavoro;
|
||||
TString_array variables;
|
||||
const int numvar = config.list_variables(variables, TRUE);//scarico tutte le variabili della sezione
|
||||
variables.sort(FALSE);
|
||||
TBit_array indici(numvar);
|
||||
indici.reset();
|
||||
for (int j = 0; j < numvar; j++)//scandisco tutte le variabili della sezione
|
||||
@ -232,7 +233,7 @@ void TFile_text::set_rec_parm(TConfig& config, const char* section)
|
||||
}
|
||||
if (lavoro == "JOI") // setta i join
|
||||
{
|
||||
CHECKS(tmprel, "Can't join to NULL relation ", (const char*)j);
|
||||
CHECKS(tmprel, "Can't join to NULL relation %s", (const char*)j);
|
||||
|
||||
TToken_string join_expr((const char *)obj,' '); // Join expression
|
||||
int token=0;
|
||||
@ -244,9 +245,9 @@ void TFile_text::set_rec_parm(TConfig& config, const char* section)
|
||||
to = name2log(t);
|
||||
} else
|
||||
token --;
|
||||
int key = 1;
|
||||
int nkey = 1;
|
||||
if (strcmp(join_expr.get(token++),"KEY")==0)
|
||||
key = join_expr.get_int(token++);
|
||||
nkey = join_expr.get_int(token++);
|
||||
else
|
||||
token--;
|
||||
int alias = 0;
|
||||
@ -270,17 +271,21 @@ void TFile_text::set_rec_parm(TConfig& config, const char* section)
|
||||
#endif
|
||||
|
||||
if (isdigit(j[0]))
|
||||
tmprel->add(atoi(j), exp, key, to, alias); // join file
|
||||
else
|
||||
{
|
||||
tmprel->add(atoi(j), exp, nkey, to, alias); // join file
|
||||
tmprel->write_enable(atoi(j),key.left(6)!="JOINRO");
|
||||
} else
|
||||
{
|
||||
#ifdef DBG
|
||||
if (j.len() > 4)
|
||||
yesnofatal_box("'%s' non e' una tabella valida: %d", (const char*)j);
|
||||
else
|
||||
#endif
|
||||
tmprel->add(j, exp, key, to, alias); // join table
|
||||
#endif
|
||||
{
|
||||
tmprel->add(j, exp, nkey, to, alias); // join table
|
||||
tmprel->write_enable(j,key.left(6)!="JOINRO");
|
||||
}
|
||||
}
|
||||
tmprel->write_enable();
|
||||
continue;
|
||||
}
|
||||
TTracciato_campo& tc = tr->get(n);//prendo il tracciato campo con indice <n>
|
||||
@ -534,7 +539,7 @@ int TFile_text::write(TRecord_text& rec)
|
||||
|
||||
// Carica tutti i dati del tracciato record (anche header o footer)
|
||||
// nel record_text
|
||||
void TFile_text::autoload(TRecord_text& rec, int mainfile)
|
||||
bool TFile_text::autoload(TRecord_text& rec, int mainfile)
|
||||
{
|
||||
TTracciato_record* tr = t_rec(mainfile);
|
||||
if (tr)
|
||||
@ -542,27 +547,29 @@ void TFile_text::autoload(TRecord_text& rec, int mainfile)
|
||||
// esiste il tracciato e posso fare l'autoload
|
||||
TCursor cur(tr->relation());
|
||||
rec.set_type(tr->type());
|
||||
_autoload(rec,cur,*tr);
|
||||
}
|
||||
return _autoload(rec,cur,*tr);
|
||||
}
|
||||
//CHECK (FALSE,"Il tracciato record non esiste");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//Carica tutti i dati nel tracciato record (valido anche per header e footer) nel record_text
|
||||
void TFile_text::autoload(TRecord_text& rec, TCursor& cur , const TString* tipo)
|
||||
bool TFile_text::autoload(TRecord_text& rec, TCursor& cur , const TString* tipo)
|
||||
{
|
||||
const TString& type = rec.type();
|
||||
if (tipo == NULL) tipo = &type;
|
||||
TTracciato_record& tr = *t_rec(*tipo);
|
||||
_autoload(rec,cur,tr);
|
||||
return _autoload(rec,cur,tr);
|
||||
}
|
||||
|
||||
void TFile_text::autoload(TCursor& cur, const TString* tipo)
|
||||
bool TFile_text::autoload(TCursor& cur, const TString* tipo)
|
||||
{
|
||||
CHECK(_current,"Record corrente non settato");
|
||||
autoload(*_current, cur, tipo);
|
||||
return autoload(*_current, cur, tipo);
|
||||
}
|
||||
|
||||
//Carica tutti i dati nel tracciato record (valido anche per header e footer) nel record_text
|
||||
void TFile_text::_autoload(TRecord_text& rec, TCursor& cur , TTracciato_record& tr )
|
||||
bool TFile_text::_autoload(TRecord_text& rec, TCursor& cur , TTracciato_record& tr )
|
||||
{
|
||||
TString campo;
|
||||
TRelation& rel = *cur.relation();
|
||||
@ -586,7 +593,8 @@ void TFile_text::_autoload(TRecord_text& rec, TCursor& cur , TTracciato_record&
|
||||
|
||||
rec.add(campo, i);
|
||||
campo.cut(0);
|
||||
}
|
||||
}
|
||||
return can_write(rec,rel);
|
||||
}
|
||||
|
||||
int TFile_text::autosave(int mainfile, const TRecord_text& rec)
|
||||
@ -661,7 +669,8 @@ int TFile_text::_autosave(TRelation& rel, const TRecord_text& rec, TTracciato_re
|
||||
break;
|
||||
}
|
||||
|
||||
field.write(valore, rel);//faccio una write sulla relazione del fieldref
|
||||
if (rel.exist(field.file()))
|
||||
field.write(valore, rel);//faccio una write sulla relazione del fieldref
|
||||
}
|
||||
}
|
||||
if (pre_writerel(rel,rec))
|
||||
|
@ -120,8 +120,9 @@ public:
|
||||
virtual ~TRecord_text(){}
|
||||
const TString& type() const {return _type;}
|
||||
void set_type(const TString& type) {_type = type;}
|
||||
const TString& row(int pos) const;//ritorna il campo dell'array della posizione <pos>
|
||||
const TString& row(int pos) const;//usare la get!!!
|
||||
TString& row(int pos);
|
||||
const TString& get(int pos) const {return row(pos);}//ritorna il campo dell'array della posizione <pos>
|
||||
void add(const TString& c, int pos = -1);//scrive il campo <c> nell'array alla posizione <pos>
|
||||
const int items() const {return _array.items();}//ritorna il numero di elementi dell'array
|
||||
virtual bool destroy(int index = -1, bool pack = FALSE) {return _array.destroy(index, pack);}
|
||||
@ -156,7 +157,7 @@ protected:
|
||||
const TString& fpicture(const TTracciato_campo &tc ) const;
|
||||
|
||||
// @cmember caricamento automatico del record_text corrente dalla relazione l
|
||||
void _autoload(TRecord_text& rec, TCursor& cur , TTracciato_record& tr );
|
||||
bool _autoload(TRecord_text& rec, TCursor& cur , TTracciato_record& tr );
|
||||
// @cmember caricamento automatico della relazione definita nel tracciato dal record_text
|
||||
int _autosave(TRelation& rel, const TRecord_text& rec, TTracciato_record& tr );
|
||||
|
||||
@ -178,6 +179,7 @@ protected:
|
||||
virtual void preformat_field(const TFieldref&field,TString &str,TRelation& rel,const TString &tipo_tr) {}
|
||||
//effettua modifiche sui record della relazione prima di effettuarne la write; ritorna TRUE se deve effettuare la write
|
||||
virtual bool pre_writerel(TRelation& rel,const TRecord_text& rec) {return TRUE;}
|
||||
virtual bool can_write(TRecord_text&, TRelation&) {return TRUE;}
|
||||
public:
|
||||
TFile_text(const char* file_name, const char* config_name);
|
||||
virtual ~TFile_text();
|
||||
@ -214,11 +216,11 @@ public:
|
||||
const int items_tr() const {return _tracciati_record.items();}//ritorna il numero di tracciati record nel file
|
||||
TAssoc_array& tracciati() {return _tracciati_record;}//ritorna un riferimento all'assoc_array dei tracciati record
|
||||
// @cmember caricamento automatico del record_text dalla relazione
|
||||
void autoload(TRecord_text& rec, TCursor& cur, const TString* tipo = NULL);
|
||||
bool autoload(TRecord_text& rec, TCursor& cur, const TString* tipo = NULL);
|
||||
// @cmember caricamento automatico del record_text corrente dalla relazione l
|
||||
void autoload(TCursor& cur, const TString* tipo = NULL) ;
|
||||
bool autoload(TCursor& cur, const TString* tipo = NULL) ;
|
||||
// @cmember caricamento automatico del record_text passato dalla relazione di file principale mainfile definita sul tracciato
|
||||
void autoload(TRecord_text& rec, int mainfile);
|
||||
bool autoload(TRecord_text& rec, int mainfile);
|
||||
// @cmember caricamento automatico del record_text corrente dalla relazione di file principale mainfile definita sul tracciato
|
||||
void autoload(int mainfile) {autoload(*_current, mainfile);}
|
||||
int write(TRecord_text & rec);//scrive su file di testo il record
|
||||
|
Loading…
x
Reference in New Issue
Block a user