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

View File

@ -44,6 +44,7 @@ public:
TIsam_handle file() const { return _isamfile; }
void copy(const TMemo_data& m);
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); }
TMemo_data& operator=(const TMemo_data& m) { copy(m); return *this; }
@ -260,9 +261,11 @@ public:
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 update_memo() {}
virtual void write_memo(TIsam_handle file, const TRecnotype recno);
bool has_memo() const { return _memo_data != NULL; }
bool memo_dirty() const { return has_memo() && _memo_data->dirty(); }
// Gestione posta elettronica
virtual void fill_transaction(TConfig& cfg, int row = 0) const;
bool send_mail(const char* action = "MODIFY") const;

View File

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

View File

@ -139,7 +139,8 @@ public:
void set_memo_fld(const char * fieldname);
void reset_memo_fld() { set_memo_fld(NULL); }
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 remove_field(const char * fieldname = NULL);