Patch level : 12.0 no patch

Files correlati     :
Commento            :

Aggiunto ai record il campo update_memo per verificare se un memo è stato mofificato
This commit is contained in:
Alessandro Bonazzi 2020-02-23 23:31:24 +01:00
parent 18284e3fb7
commit 4443d366f4
4 changed files with 108 additions and 82 deletions

View File

@ -679,7 +679,7 @@ TBaseisamfile::TBaseisamfile(int logicnum)
_curr_key = 0; _curr_key = 0;
_lasterr = NOERR; _lasterr = NOERR;
_current = new TRectype(logicnum); _current = new TRectype(logicnum);
} }
// @doc EXTERNAL // @doc EXTERNAL
@ -712,8 +712,7 @@ TBaseisamfile::TBaseisamfile(
TBaseisamfile::~TBaseisamfile() TBaseisamfile::~TBaseisamfile()
{ {
if (_current) SAFE_DELETE(_current);
delete _current;
} }
TCodeb_handle TBaseisamfile::handle(int key) const TCodeb_handle TBaseisamfile::handle(int key) const
@ -868,7 +867,7 @@ int TBaseisamfile::_read(TRectype& rec, word op, word lockop)
prefix().lock_record(_isam_handle, _recno); else prefix().lock_record(_isam_handle, _recno); else
if (lockop == _unlock) if (lockop == _unlock)
prefix().unlock_record(_isam_handle, _recno); prefix().unlock_record(_isam_handle, _recno);
} }
return _lasterr; return _lasterr;
} }
@ -938,8 +937,10 @@ int TBaseisamfile::_write(const TRectype& rec)
if (_lasterr == NOERR) if (_lasterr == NOERR)
{ {
if (rec.has_memo()) if (rec.has_memo())
((TRectype&)rec).write_memo(_isam_handle, _recno ); ((TRectype&)rec).write_memo(_isam_handle, _recno );
rec_cache(_logicnum).notify_change();
} }
else else
_lasterr = get_error(_lasterr); _lasterr = get_error(_lasterr);
@ -980,6 +981,7 @@ int TBaseisamfile::rewrite_write()
int TBaseisamfile::_rewrite(const TRectype& rec) int TBaseisamfile::_rewrite(const TRectype& rec)
{ {
CHECK(!rec.empty(), "Can't write an empty record"); CHECK(!rec.empty(), "Can't write an empty record");
bool changed = false;
TRectype save_rec(rec); TRectype save_rec(rec);
@ -996,26 +998,31 @@ int TBaseisamfile::_rewrite(const TRectype& rec)
browse_null(rec.string(), len); browse_null(rec.string(), len);
if (memcmp(rec.string(), save_rec.string(), len) != 0) if (memcmp(rec.string(), save_rec.string(), len) != 0)
{ {
memcpy(DB_getrecord(fhnd), rec.string(), len); memcpy(DB_getrecord(fhnd), rec.string(), len);
_lasterr = DB_rewrite(fhnd); _lasterr = DB_rewrite(fhnd);
if (_lasterr == NOERR) if (_lasterr == NOERR)
rec_cache(_logicnum).notify_change(); rec_cache(_logicnum).notify_change();
else else
_lasterr = get_error(_lasterr); _lasterr = get_error(_lasterr);
} }
else DB_unlock(fhnd); // non vale la pena farlo sempre ?
DB_unlock(fhnd); // non vale la pena farlo sempre ?
_recno = DB_recno(fhnd); _recno = DB_recno(fhnd);
prefix().unlock_record(_isam_handle, _recno); prefix().unlock_record(_isam_handle, _recno);
if (_lasterr == NOERR) if (_lasterr == NOERR)
{ {
if (curr().has_memo()) if (rec.has_memo())
((TRectype&)rec).write_memo(_isam_handle, _recno); {
} ((TRectype&)rec).update_memo();
changed |= rec.memo_dirty();
if (changed)
((TRectype&)rec).write_memo(_isam_handle, _recno);
}
if (changed)
rec_cache(_logicnum).notify_change();
}
} }
return _lasterr; return _lasterr;
} }
@ -1032,6 +1039,7 @@ int TBaseisamfile::rewrite()
int TBaseisamfile::rewriteat(const TRectype& rec, TRecnotype nrec) int TBaseisamfile::rewriteat(const TRectype& rec, TRecnotype nrec)
{ {
const int fhnd = handle(); const int fhnd = handle();
bool changed = false;
if ((_lasterr=DB_go(fhnd,nrec))== NOERR) if ((_lasterr=DB_go(fhnd,nrec))== NOERR)
{ {
@ -1044,13 +1052,18 @@ int TBaseisamfile::rewriteat(const TRectype& rec, TRecnotype nrec)
_lasterr = get_error(_lasterr); _lasterr = get_error(_lasterr);
_recno = DB_recno(fhnd); _recno = DB_recno(fhnd);
if(_lasterr == NOERR) if (_lasterr == NOERR)
{ {
if (curr().has_memo()) if (rec.has_memo())
((TRectype &)rec).write_memo(_isam_handle, _recno); {
rec_cache(_logicnum).notify_change(); ((TRectype&)rec).update_memo();
} changed |= rec.memo_dirty();
if (changed)
((TRectype&)rec).write_memo(_isam_handle, _recno);
}
if (changed)
rec_cache(_logicnum).notify_change();
}
return _lasterr; return _lasterr;
} }
@ -1064,8 +1077,8 @@ int TBaseisamfile::_remove(const TRectype& rec)
CHECK(!rec.empty(), "Can't remove an empty record"); CHECK(!rec.empty(), "Can't remove an empty record");
const int fhnd = handle(1); // Forza l'uso della chiave principale (per chiavi duplicate?) const int fhnd = handle(1); // Forza l'uso della chiave principale (per chiavi duplicate?)
TRectype save_rec(rec); TRectype save_rec(rec);
_lasterr = cisread(fhnd, 1, save_rec, _isequal + _nolock, _recno); // Si Posiziona per sicurezza... _lasterr = cisread(fhnd, 1, save_rec, _isequal + _nolock, _recno); // Si Posiziona per sicurezza...
if (_lasterr == NOERR) if (_lasterr == NOERR)
@ -1278,9 +1291,13 @@ int TBaseisamfile::is_valid(bool exclusive)
if (dbfreclen != trcreclen) if (dbfreclen != trcreclen)
{ {
err = _istrcerr; err = _istrcerr;
if (_logicnum == LF_CLIFO)
error_box("Clifo trc=%d dbf=%d", trcreclen, dbfreclen); TString msg;
}
msg.format("Lunghezza record incoerente sul file %d (%s): file=%d trc=%d",
num(), (const char*)description(), dbfreclen, trcreclen);
error_box(msg);
}
} }
} }
else else
@ -1459,7 +1476,6 @@ TIsamtempfile::TIsamtempfile(int logicnum, const char* radix, bool create, bool
open(n, create, eod, eox); open(n, create, eod, eox);
} }
TIsamtempfile::~TIsamtempfile() TIsamtempfile::~TIsamtempfile()
{ {
close(); close();
@ -2441,7 +2457,7 @@ int TSystemisamfile::load(
const int l = fldlen.get_int(j); const int l = fldlen.get_int(j);
s1 = s.mid(pos, l); s1 = s.mid(pos, l);
s1.rtrim(); s1.rtrim();
put(fld.row(j), s1); put(fld.row(j), s1);
pos += l; pos += l;
} }
} }
@ -2654,7 +2670,7 @@ int TSystemisamfile::overwrite(
s1 = s.mid(pos,len[j]); s1 = s.mid(pos,len[j]);
s1.rtrim(); s1.rtrim();
vals.add(fldname, s1); vals.add(fldname, s1);
pos += len[j]; pos += len[j];
} }
} }
@ -2672,9 +2688,9 @@ int TSystemisamfile::overwrite(
s1.ltrim(1); s1.ltrim(1);
} }
if (curr().type(fldname) == _memofld) if (curr().type(fldname) == _memofld)
{ {
TString s2 = s1; TString s2 = s1;
s1 = esc(s2); s1 = esc(s2);
} }
vals.add(fldname, s1); vals.add(fldname, s1);
} }
@ -2738,7 +2754,7 @@ int TSystemisamfile::dump(
SELECTIONFUNCTION select_func, // @parm funzione filtro SELECTIONFUNCTION select_func, // @parm funzione filtro
TObject * filter_obj) // @parm oggetto di filtro TObject * filter_obj) // @parm oggetto di filtro
// @xref <mf TSystemisamfile::load> // @xref <mf TSystemisamfile::dump>
{ {
FILE* f = NULL; fopen_s(&f, to, "w"); FILE* f = NULL; fopen_s(&f, to, "w");
@ -2818,7 +2834,7 @@ int TSystemisamfile::dump(
if (fixedlen) if (fixedlen)
{ {
s1 = get(fname); s1 = get(fname);
if (rjust[j]) s1.right_just(len[j]); if (rjust[j]) s1.right_just(len[j]);
else s1.left_just(len[j]); else s1.left_just(len[j]);
} }
else else
@ -2839,13 +2855,13 @@ int TSystemisamfile::dump(
break; break;
case _memofld: case _memofld:
if (sfld.full()) if (sfld.full())
{ {
int p = 0; int p = 0;
while ((p = sfld.find('\n', 0)) >= 0) while ((p = sfld.find('\n', 0)) >= 0)
{ {
sfld.overwrite("\\", p); sfld.overwrite("\\", p);
sfld.insert("n", p+1); sfld.insert("n", p+1);
} }
} }
else else
sfld.cut(0); sfld.cut(0);
@ -2900,7 +2916,7 @@ int TSystemisamfile::dump(
if (fixedlen) if (fixedlen)
{ {
s1 = get((const TString&)fld[j]); s1 = get((const TString&)fld[j]);
if (rjust[j]) s1.right_just(len[j]); if (rjust[j]) s1.right_just(len[j]);
else s1.left_just(len[j]); else s1.left_just(len[j]);
} }
else else
@ -2910,14 +2926,14 @@ int TSystemisamfile::dump(
if (fd) s1 << fd; if (fd) s1 << fd;
sfld = get((const TString&)fld[j]); sfld = get((const TString&)fld[j]);
if (curr().type((const TString&) fld[j]) == _memofld) if (curr().type((const TString&) fld[j]) == _memofld)
{ {
int p = 0; int p = 0;
while ((p = sfld.find('\n', 0)) >= 0) while ((p = sfld.find('\n', 0)) >= 0)
{ {
sfld.overwrite("\\", p); sfld.overwrite("\\", p);
sfld.insert("n", p+1); sfld.insert("n", p+1);
} }
} }
s1 << sfld; s1 << sfld;
if (fd) s1 << fd; if (fd) s1 << fd;
} }
@ -2947,7 +2963,7 @@ int TSystemisamfile::dump(
SELECTIONFUNCTION select_func, // @parm funzione filtro SELECTIONFUNCTION select_func, // @parm funzione filtro
TObject * filter_obj) // @parm oggetto di filtro TObject * filter_obj) // @parm oggetto di filtro
// @xref <mf TSystemisamfile::load> // @xref <mf TSystemisamfile::dump>
{ {
FILE* f = NULL; fopen_s(&f, to, "w"); FILE* f = NULL; fopen_s(&f, to, "w");
@ -3031,7 +3047,7 @@ int TSystemisamfile::dump(
if (fixedlen) if (fixedlen)
{ {
s1 = get(fldname); s1 = get(fldname);
if (rjust[j]) s1.right_just(len[j]); if (rjust[j]) s1.right_just(len[j]);
else s1.left_just(len[j]); else s1.left_just(len[j]);
} }
else else
@ -3041,15 +3057,15 @@ int TSystemisamfile::dump(
if (fd) s1 << fd; if (fd) s1 << fd;
sfld = get(fldname); sfld = get(fldname);
if (curr().type(fldname) == _memofld) if (curr().type(fldname) == _memofld)
{ {
int p = 0; int p = 0;
while ((p = sfld.find('\n', 0)) >= 0) while ((p = sfld.find('\n', 0)) >= 0)
{ {
sfld.overwrite("\\", p); sfld.overwrite("\\", p);
sfld.insert("n", p+1); sfld.insert("n", p+1);
} }
} }
s1 << sfld; s1 << sfld;
if (fd) s1 << fd; if (fd) s1 << fd;
} }
s << s1; s << s1;
@ -3090,7 +3106,7 @@ int TSystemisamfile::dump(
if (fixedlen) if (fixedlen)
{ {
s1 = get(fldname); s1 = get(fldname);
if (rjust[j]) s1.right_just(len[j]); if (rjust[j]) s1.right_just(len[j]);
else s1.left_just(len[j]); else s1.left_just(len[j]);
} }
else else
@ -3100,15 +3116,15 @@ int TSystemisamfile::dump(
if (fd) s1 << fd; if (fd) s1 << fd;
sfld = get(fldname); sfld = get(fldname);
if (curr().type(fldname) == _memofld) if (curr().type(fldname) == _memofld)
{ {
int p = 0; int p = 0;
while ((p = sfld.find('\n', 0)) >= 0) while ((p = sfld.find('\n', 0)) >= 0)
{ {
sfld.overwrite("\\", p); sfld.overwrite("\\", p);
sfld.insert("n", p+1); sfld.insert("n", p+1);
} }
} }
s1 << sfld; s1 << sfld;
if (fd) s1 << fd; if (fd) s1 << fd;
} }
s << s1; s << s1;
@ -3500,7 +3516,7 @@ int TRectype::ndec(const char* fieldname) const
bool TRectype::exist(const char* fieldname) const bool TRectype::exist(const char* fieldname) const
{ {
return findfld(&rec_des(), fieldname) != FIELDERR; return findfld(&rec_des(), fieldname) != FIELDERR;
} }
const char* TRectype::fieldname(int i) const const char* TRectype::fieldname(int i) const
@ -3657,7 +3673,7 @@ void TRectype::put_str(const char* fieldname, const char* val)
const TFieldtypes ft = TFieldtypes(fd.TypeF); const TFieldtypes ft = TFieldtypes(fd.TypeF);
if (val == NULL) if (val == NULL)
val = ""; val = "";
if (ft == _boolfld) if (ft == _boolfld)
val = (*val && strchr("1STXY", toupper(*val)) != NULL) ? "T" : "F"; val = (*val && strchr("1STXY", toupper(*val)) != NULL) ? "T" : "F";
@ -4125,7 +4141,7 @@ void TRecfield::put_subfield(const char* s)
{ {
if (_name == _sub_field) if (_name == _sub_field)
return; return;
const TString& str = _rec->get(_name); const TString& str = _rec->get(_name);
int p = str.find(_sub_field); int p = str.find(_sub_field);
if (p == 0 || (p > 0 && str[p - 1] < ' ')) if (p == 0 || (p > 0 && str[p - 1] < ' '))
@ -4156,10 +4172,10 @@ void TRecfield::put_subfield(const char* s)
int TRecfield::operator =(int i) int TRecfield::operator =(int i)
{ {
TString16 buff; buff << i; TString16 buff; buff << i;
if (_sub_field.empty()) if (_sub_field.empty())
__putfieldbuff( _len, _dec, _type, buff, _p); __putfieldbuff( _len, _dec, _type, buff, _p);
else else
put_subfield(buff); put_subfield(buff);
_rec->setempty(FALSE); _rec->setempty(FALSE);
return i; return i;
} }
@ -4201,7 +4217,7 @@ const TDate& TRecfield::operator =(const TDate& d)
const char* TRecfield::operator =(const char* s) const char* TRecfield::operator =(const char* s)
{ {
if (_sub_field.empty()) if (_sub_field.empty())
{ {
if (_type == _memofld) if (_type == _memofld)
_rec->put(_name, s); _rec->put(_name, s);
else else

View File

@ -44,6 +44,7 @@ public:
TIsam_handle file() const { return _isamfile; } TIsam_handle file() const { return _isamfile; }
void copy(const TMemo_data& m); void copy(const TMemo_data& m);
bool is_dirty(int i) const { return _dirty[i]; } bool is_dirty(int i) const { return _dirty[i]; }
bool dirty() const { return _dirty.some_one(); }
void set_dirty(int i, bool d = true) { _dirty.set(i, d); } void set_dirty(int i, bool d = true) { _dirty.set(i, d); }
TMemo_data& operator=(const TMemo_data& m) { copy(m); return *this; } TMemo_data& operator=(const TMemo_data& m) { copy(m); return *this; }
@ -260,8 +261,10 @@ public:
virtual void init_memo(const TRecnotype recno = RECORD_NON_FISICO, TIsam_handle file = 0); virtual void init_memo(const TRecnotype recno = RECORD_NON_FISICO, TIsam_handle file = 0);
virtual void reset_memo() { _memo_data->init(RECORD_NON_FISICO, 0); } virtual void reset_memo() { _memo_data->init(RECORD_NON_FISICO, 0); }
virtual void update_memo() {}
virtual void write_memo(TIsam_handle file, const TRecnotype recno); virtual void write_memo(TIsam_handle file, const TRecnotype recno);
bool has_memo() const { return _memo_data != NULL; } bool has_memo() const { return _memo_data != NULL; }
bool memo_dirty() const { return has_memo() && _memo_data->dirty(); }
// Gestione posta elettronica // Gestione posta elettronica
virtual void fill_transaction(TConfig& cfg, int row = 0) const; virtual void fill_transaction(TConfig& cfg, int row = 0) const;

View File

@ -168,24 +168,30 @@ void TVariable_rectype::unknown_field(const char* name) const
TRectype::unknown_field(name); TRectype::unknown_field(name);
} }
void TVariable_rectype::write_memo(TIsam_handle file, const TRecnotype recno) void TVariable_rectype::update_memo()
{ {
if (_memo_fld.full()) if (_memo_fld.full())
{ {
TToken_string t(256, '\n'); TToken_string t(256, '\n');
FOR_EACH_ASSOC_OBJECT(_virtual_fields, h, key, o)
{ FOR_EACH_ASSOC_OBJECT(_virtual_fields, h, key, o)
const TVariable_field* vf = (TVariable_field*)o; {
const TString& val = vf->get(); const TVariable_field* vf = (TVariable_field*)o;
const TString& val = vf->get();
if (val.full() && val != "0") if (val.full() && val != "0")
{ {
t.add(key); t.add(key);
t << '=' << val; t << '=' << val;
} }
} }
put(_memo_fld, t); put(_memo_fld, t);
} }
}
void TVariable_rectype::write_memo(TIsam_handle file, const TRecnotype recno)
{
update_memo();
TRectype::write_memo(file, recno); TRectype::write_memo(file, recno);
} }

View File

@ -139,7 +139,8 @@ public:
void set_memo_fld(const char * fieldname); void set_memo_fld(const char * fieldname);
void reset_memo_fld() { set_memo_fld(NULL); } void reset_memo_fld() { set_memo_fld(NULL); }
virtual void init_memo(const TRecnotype recno = RECORD_NON_FISICO, TIsam_handle file = 0); virtual void init_memo(const TRecnotype recno = RECORD_NON_FISICO, TIsam_handle file = 0);
virtual void write_memo(TIsam_handle file, const TRecnotype recno); virtual void update_memo();
virtual void write_memo(TIsam_handle file, const TRecnotype recno);
virtual void add_field(TVariable_field * f); virtual void add_field(TVariable_field * f);
virtual void remove_field(const char * fieldname = NULL); virtual void remove_field(const char * fieldname = NULL);