Ripristino EOD ed EOX originali in caso di conversione con errore.

git-svn-id: svn://10.65.10.50/trunk@1562 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
angelo 1995-07-05 14:56:36 +00:00
parent 094e90a18d
commit f0a7a654b7

View File

@ -10,7 +10,6 @@
#define DAYYEAR 365 #define DAYYEAR 365
extern "C" { extern "C" {
int CGetFieldBuff(char *, RecDes *, char *, char *);
int findfld(RecDes *, const char *); int findfld(RecDes *, const char *);
}; };
@ -64,7 +63,8 @@ HIDDEN int CGetField(const char *fieldname,RecDes* recd,RecType recin,long* d)
class TIsam_date_converter : public TApplication class TIsam_date_converter : public TApplication
{ {
TFilename _logfile;
protected: protected:
virtual bool create () ; virtual bool create () ;
virtual bool destroy(); virtual bool destroy();
@ -83,7 +83,9 @@ bool TIsam_date_converter::create() // initvar e arrmask
{ {
TApplication::create(); TApplication::create();
_logfile.temp("convlog");
FILE * fp = fopen((const char*)_logfile,"w");
fclose(fp);
update(); update();
return FALSE; return FALSE;
} }
@ -130,6 +132,9 @@ void TIsam_date_converter::update()
else prefix().set(pref); else prefix().set(pref);
set_autoload_new_files(TRUE); set_autoload_new_files(TRUE);
end_wait(); end_wait();
TString80 s;
s << "Esaminare il file di log " << _logfile << " in caso di errori." ;
message_box(s);
} }
void TIsam_date_converter::update_dir() void TIsam_date_converter::update_dir()
@ -199,9 +204,10 @@ int TIsam_date_converter::convert_file(int logicnum)
TDir dir; TDir dir;
TTrec r; TTrec r;
int err = NOERR; int err = NOERR;
bool restore_original=FALSE;
r.get(logicnum); r.get(logicnum);
RecDes *rd=r.rec(); RecDes *rd=r.rec();
TRecnotype i;
const int nflds = r.fields(); const int nflds = r.fields();
const int nkeys = r.keys(); const int nkeys = r.keys();
@ -209,7 +215,7 @@ int TIsam_date_converter::convert_file(int logicnum)
if (dir.len() == 0 || nflds < 1 || nkeys < 1) return 0; if (dir.len() == 0 || nflds < 1 || nkeys < 1) return 0;
const char * fp = dir.name(); const char * fp = dir.name();
TFilename old(fp); TFilename old(fp);
const TRecnotype nitems = dir.eod(); const TRecnotype nitems = dir.eod();
TFile f(dir.len()); TFile f(dir.len());
old.ext("dta"); old.ext("dta");
@ -230,7 +236,6 @@ int TIsam_date_converter::convert_file(int logicnum)
TLocalisamfile newfile(logicnum); TLocalisamfile newfile(logicnum);
TToken_string ts(128); // Build token_string with the names of date fields and logical fields TToken_string ts(128); // Build token_string with the names of date fields and logical fields
TToken_string tslog(128); TToken_string tslog(128);
TRecnotype i;
for (int j=0; j<r.fields(); j++) for (int j=0; j<r.fields(); j++)
if (rd->Fd[j].TypeF == _datefld) if (rd->Fd[j].TypeF == _datefld)
@ -270,6 +275,7 @@ int TIsam_date_converter::convert_file(int logicnum)
} }
p.setstatus((long)nitems); p.setstatus((long)nitems);
f.close(); f.close();
err=newfile.status();
if (newfile.good()) if (newfile.good())
{ {
old.ext("dta"); old.ext("dta");
@ -278,8 +284,11 @@ int TIsam_date_converter::convert_file(int logicnum)
::remove(old); ::remove(old);
} }
else else
error_box("Errore nella conversione dell' archivio %s record %ld : n.ro %d", {
fp, i, newfile.status()); error_box("Errore n.ro %d nella conversione dell' archivio %s:\n %ld records non convertiti.",
err, fp, nitems - i + 2);
restore_original=TRUE;
}
} }
else else
{ {
@ -305,6 +314,28 @@ int TIsam_date_converter::convert_file(int logicnum)
} }
} }
} }
if (restore_original)
{
// Remove files partially converted
old.ext("dbf");
::remove(old);
TToken_string t(10);
get_idx_names(logicnum,t);
for (const char * name=t.get(0); name != NULL; name=t.get())
::remove(name);
if (t.items() > 1) // A .cgp must be removed too!
{
old.ext("cgp");
::remove(old);
}
// Put dir to restore original EOD and EOX.
dir.put(logicnum);
FILE *fp = fopen((const char*)_logfile,"a");
old.ext("dta");
fprintf(fp,"File: %s (%d). %ld records non convertiti. Errore %d.\n",
(const char*) old, logicnum, nitems-i+2, err);
fclose(fp);
}
return err; return err;
} }