Aggiunta eliminazione dei record duplicati sulla 1a chiave
git-svn-id: svn://10.65.10.50/trunk@2700 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
364401f662
commit
f28253517a
152
include/codeb.c
152
include/codeb.c
@ -37,7 +37,8 @@
|
|||||||
#include <codeb.h>
|
#include <codeb.h>
|
||||||
#include <rectypes.h>
|
#include <rectypes.h>
|
||||||
#include <progind.h>
|
#include <progind.h>
|
||||||
#define MAXLEN 128 /* Lunghezza massima chiave */
|
#include <checks.h>
|
||||||
|
#define MAXLEN 137 /* Lunghezza massima chiave */
|
||||||
|
|
||||||
extern char* CUpString(char *);
|
extern char* CUpString(char *);
|
||||||
|
|
||||||
@ -562,23 +563,24 @@ HIDDEN int is_inkey(RecDes *r, int numfield)
|
|||||||
return(found);
|
return(found);
|
||||||
}
|
}
|
||||||
|
|
||||||
HIDDEN void do_key(char *fname, RecDes *r, TAG4INFO *tag_info)
|
HIDDEN void do_key(char *fname, RecDes *r, TAG4INFO *tag_info, int n_keys)
|
||||||
{
|
{
|
||||||
int i,j;
|
int i,j;
|
||||||
char tiname[9]; /* Tag name, max 8 characters long! */
|
char tiname[9]; /* Tag name, max 8 characters long! */
|
||||||
|
|
||||||
strcpy(tiname,fname);
|
strcpy(tiname,fname);
|
||||||
CUpString(tiname);
|
CUpString(tiname);
|
||||||
for (i=0; ((i < MaxKeys) && (i < r->NKeys)); i++)
|
for (i=0; ((i < MaxKeys) && (i < n_keys)); i++)
|
||||||
{
|
{
|
||||||
tag_info[i].name=(char *)u4alloc(9);
|
tag_info[i].name=(char *)u4alloc(9);
|
||||||
tag_info[i].expression=(char *)u4alloc(128);
|
tag_info[i].expression=(char *)u4alloc(256);
|
||||||
tag_info[i].filter=(char*)u4alloc(20);
|
tag_info[i].filter=(char*)u4alloc(20);
|
||||||
tag_info[i].descending=0;
|
tag_info[i].descending=0;
|
||||||
if (r->Ky[i].DupKeys)
|
if (r->Ky[i].DupKeys)
|
||||||
tag_info[i].unique=0;
|
tag_info[i].unique=0;
|
||||||
else
|
else
|
||||||
tag_info[i].unique=e4unique;
|
tag_info[i].unique= i == 0 ? e4unique : r4unique_continue;
|
||||||
|
// tag_info[i].unique=e4unique;
|
||||||
strcpy(tag_info[i].filter,".NOT. DELETED()"); /* Not available for DBIII and CLIPPER */
|
strcpy(tag_info[i].filter,".NOT. DELETED()"); /* Not available for DBIII and CLIPPER */
|
||||||
strcpy(tag_info[i].name,tiname) ;
|
strcpy(tag_info[i].name,tiname) ;
|
||||||
if (strlen(tiname) < 8)
|
if (strlen(tiname) < 8)
|
||||||
@ -750,6 +752,68 @@ int DB_packmemo(short vis, const char * filename)
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
Elimina i record duplicati
|
||||||
|
--------------------------------------------------------------------------*/
|
||||||
|
int DB_clean_file(int handle, const char * filename, char * ff, RecDes * r, bool vis)
|
||||||
|
{
|
||||||
|
TAG4INFO tags[2];
|
||||||
|
TAG4 * t;
|
||||||
|
char s[256];
|
||||||
|
int l = 0, rt = 0;
|
||||||
|
long cnt = 0;
|
||||||
|
INDEX4 *w = NULL;
|
||||||
|
long items = DB_reccount(handle);
|
||||||
|
|
||||||
|
if (items == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
s[0] = '\0';
|
||||||
|
do_key(ff, r, tags, 1);
|
||||||
|
strcat(tags[0].expression, "+STR(RECNO(),9)");
|
||||||
|
w = i4create(dbdata[handle],(char*)filename,tags);
|
||||||
|
u4free(tags[0].name);
|
||||||
|
u4free(tags[0].expression);
|
||||||
|
u4free(tags[0].filter);
|
||||||
|
if (w == NULL) return code_base.error_code;
|
||||||
|
t = d4tag_default(dbdata[handle]);
|
||||||
|
l = expr4key_len(t->expr) - 9;
|
||||||
|
#ifndef FOXPRO
|
||||||
|
if (vis)
|
||||||
|
progind_create(items,"Ricerca record duplicati",1,1,1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rt = t4bottom(t);
|
||||||
|
|
||||||
|
while (code_base.error_code == 0)
|
||||||
|
{
|
||||||
|
const char* s0 = t4key(t);
|
||||||
|
|
||||||
|
#ifndef FOXPRO
|
||||||
|
if (vis)
|
||||||
|
progind_set_status(++cnt);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!strncmp(s, s0, l))
|
||||||
|
{
|
||||||
|
x4go(&xdb[handle],t4recno(t));
|
||||||
|
d4delete(dbdata[handle]);
|
||||||
|
}
|
||||||
|
strncpy(s, s0, l);
|
||||||
|
if (t4skip(t, -1L) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
} // while
|
||||||
|
rt = code_base.error_code;
|
||||||
|
#ifndef FOXPRO
|
||||||
|
if (vis)
|
||||||
|
progind_destroy();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
i4close(w);
|
||||||
|
return rt;
|
||||||
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
Compatta gli indici
|
Compatta gli indici
|
||||||
--------------------------------------------------------------------------*/
|
--------------------------------------------------------------------------*/
|
||||||
@ -757,7 +821,8 @@ int DB_packindex(short vis, const char * filename, RecDes *r, long *peod)
|
|||||||
{
|
{
|
||||||
int rt=0,handle;
|
int rt=0,handle;
|
||||||
TAG4INFO tags[MaxKeys+1];
|
TAG4INFO tags[MaxKeys+1];
|
||||||
char s[82];
|
char s[82];
|
||||||
|
INDEX4 * w = NULL;
|
||||||
|
|
||||||
strcpy(s,"Ricostruzione indici file : ");
|
strcpy(s,"Ricostruzione indici file : ");
|
||||||
strcat(s,filename);
|
strcat(s,filename);
|
||||||
@ -769,47 +834,72 @@ int DB_packindex(short vis, const char * filename, RecDes *r, long *peod)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *ff = find_slash_backslash((char *)filename);
|
char *ff = find_slash_backslash((char *)filename);
|
||||||
if (vis)
|
|
||||||
{
|
|
||||||
#ifndef FOXPRO
|
#ifndef FOXPRO
|
||||||
|
if (vis)
|
||||||
progind_create((long)r->NKeys,s,1,1,1);
|
progind_create((long)r->NKeys,s,1,1,1);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
if ((ff == NULL) || *ff == '\0')
|
if ((ff == NULL) || *ff == '\0')
|
||||||
ff = (char *)filename;
|
ff = (char *)filename;
|
||||||
else
|
else
|
||||||
ff++;
|
ff++;
|
||||||
do_key(ff,r,tags);
|
do_key(ff,r,tags, r->NKeys);
|
||||||
if (u4switch() &2 || u4switch() & 8) /* Clipper and DBIII */
|
w = i4create(dbdata[handle],NULL,tags);
|
||||||
{
|
|
||||||
INDEX4 * w = i4create(dbdata[handle],(char*)filename,tags);
|
|
||||||
#ifndef FOXPRO
|
#ifndef FOXPRO
|
||||||
|
if (vis)
|
||||||
|
{
|
||||||
progind_set_status((long)r->NKeys);
|
progind_set_status((long)r->NKeys);
|
||||||
|
progind_destroy();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (w != NULL && code_base.error_code==0)
|
if (w == NULL) rt = code_base.error_code;
|
||||||
|
if (rt == e4unique || rt == r4unique)
|
||||||
|
{
|
||||||
|
rt = 0;
|
||||||
|
if (yesno_box("Sono stati rilevati alcuni record duplicati devo eliminarli ?"))
|
||||||
|
rt = DB_clean_file(handle, (char*) filename, ff, r, vis);
|
||||||
|
else
|
||||||
|
tags[0].unique = r4unique_continue;
|
||||||
|
if (rt == 0)
|
||||||
{
|
{
|
||||||
|
#ifndef FOXPRO
|
||||||
|
if (vis)
|
||||||
|
progind_create((long)r->NKeys,s,1,1,1);
|
||||||
|
#endif
|
||||||
|
w = i4create(dbdata[handle],(char*)filename,tags);
|
||||||
|
if (w == NULL) rt = code_base.error_code;
|
||||||
|
#ifndef FOXPRO
|
||||||
|
if (vis)
|
||||||
|
{
|
||||||
|
progind_set_status((long)r->NKeys);
|
||||||
|
progind_destroy();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (rt == 0)
|
||||||
|
{
|
||||||
|
if (u4switch() & 2 || u4switch() & 8) /* Clipper and DBIII */
|
||||||
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char cgp[81];
|
char cgp[81];
|
||||||
|
|
||||||
strcpy(cgp,filename);
|
strcpy(cgp,filename);
|
||||||
strcat(cgp,".CGP");
|
strcat(cgp,".cgp");
|
||||||
if ((fp=fopen(cgp,"w"))!=NULL)
|
if ((fp=fopen(cgp,"w"))!=NULL)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
for (j=0; j<r->NKeys;j++)
|
for (j=0; j<r->NKeys;j++)
|
||||||
fprintf(fp,"%s\n",tags[j].name);
|
fprintf(fp,"%s\n",tags[j].name);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
/*
|
||||||
if (u4switch() & 1 || u4switch() & 4) /* FOXPRO and DBIV */
|
else
|
||||||
{
|
if (u4switch() & 1 || u4switch() & 4) // FOXPRO and DBIV
|
||||||
INDEX4 * w = i4create(dbdata[handle],NULL,tags);
|
{
|
||||||
if (w == NULL) rt = code_base.error_code;
|
}
|
||||||
#ifndef FOXPRO
|
*/
|
||||||
progind_set_status((long)r->NKeys);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
for (i=0; ((i < MaxKeys) && (i < r->NKeys)); i++)
|
for (i=0; ((i < MaxKeys) && (i < r->NKeys)); i++)
|
||||||
{
|
{
|
||||||
@ -817,17 +907,11 @@ int DB_packindex(short vis, const char * filename, RecDes *r, long *peod)
|
|||||||
u4free(tags[i].expression);
|
u4free(tags[i].expression);
|
||||||
u4free(tags[i].filter);
|
u4free(tags[i].filter);
|
||||||
}
|
}
|
||||||
if (vis)
|
|
||||||
{
|
|
||||||
#ifndef FOXPRO
|
|
||||||
progind_destroy();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
*peod=DB_reccount(handle);
|
*peod=DB_reccount(handle);
|
||||||
DB_close(handle);
|
DB_close(handle);
|
||||||
}
|
}
|
||||||
code_base.auto_open = 1;
|
code_base.auto_open = 1;
|
||||||
return(code_base.error_code);
|
return(rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -887,7 +971,7 @@ int DB_build(const char * filename, RecDes *r)
|
|||||||
ff = (char *) filename;
|
ff = (char *) filename;
|
||||||
else
|
else
|
||||||
ff++;
|
ff++;
|
||||||
do_key(ff,r,tag_info);
|
do_key(ff,r,tag_info, r->NKeys);
|
||||||
|
|
||||||
if ((dbuilded=d4create(&code_base, (char *)filename, field_info, tag_info))==0) /* deve solo creare il file dati vuoto */
|
if ((dbuilded=d4create(&code_base, (char *)filename, field_info, tag_info))==0) /* deve solo creare il file dati vuoto */
|
||||||
rt=code_base.error_code;
|
rt=code_base.error_code;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user