Corretti alcuni errori inerenti i lock, e la gestione dei campi booleani.
git-svn-id: svn://10.65.10.50/trunk@1548 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
2fbfb0a6b5
commit
d4e8e2d49e
427
include/codeb.c
427
include/codeb.c
@ -1,20 +1,20 @@
|
||||
/*
|
||||
Attenzione!. Per costruire la DLL accertarsi che siano attivati i seguenti switch:
|
||||
1) S4DLL_BUILD definito da command line del compilatore
|
||||
2) Uno solo tra S4FOX S4CLIPPER S4NDX e S4MDX, definito in d4all.h
|
||||
Attenzione!. Per costruire la DLL accertarsi che siano attivati i seguenti switch:
|
||||
1) S4DLL_BUILD definito da command line del compilatore
|
||||
2) Uno solo tra S4FOX S4CLIPPER S4NDX e S4MDX, definito in d4all.h
|
||||
|
||||
Gli altri switch di configurazione generale sono a piacere (S4DEBUG, S4ERROR_HOOK, ecc.)
|
||||
Gli altri switch di configurazione generale sono a piacere (S4DEBUG, S4ERROR_HOOK, ecc.)
|
||||
|
||||
Per costruire WINUNO.LIB Accertarsi che d4all.h non abbia definito S4DLL o S4UNIX,
|
||||
e tanto meno S4DLL_BUILD, altrimenti per costruire la library di UNIX e' necessario
|
||||
cambiare ogni volta. La definizione di tali simboli avviene qui dentro.
|
||||
Inoltre deve essere attivo uno solo degli switch di selezione formato database
|
||||
(S4FOX, S4MDX ecc.); nel caso si faccia uso della DLL non importa quale si e' definito.
|
||||
E' importante solo in caso di utilizzo di una static Library.
|
||||
Per costruire WINUNO.LIB Accertarsi che d4all.h non abbia definito S4DLL o S4UNIX,
|
||||
e tanto meno S4DLL_BUILD, altrimenti per costruire la library di UNIX e' necessario
|
||||
cambiare ogni volta. La definizione di tali simboli avviene qui dentro.
|
||||
Inoltre deve essere attivo uno solo degli switch di selezione formato database
|
||||
(S4FOX, S4MDX ecc.); nel caso si faccia uso della DLL non importa quale si e' definito.
|
||||
E' importante solo in caso di utilizzo di una static Library.
|
||||
|
||||
Per costruire l'aga.fll e' necessario togliere le funzioni progind* e definire S4DLL.
|
||||
Per costruire l'aga.fll e' necessario togliere le funzioni progind* e definire S4DLL.
|
||||
|
||||
*/
|
||||
*/
|
||||
#if XVT_OS == XVT_OS_SCOUNIX
|
||||
#define S4UNIX
|
||||
#else
|
||||
@ -48,17 +48,17 @@ static X4FILTER xdb[CB4FILES];
|
||||
|
||||
static char * find_slash_backslash(char * str)
|
||||
{
|
||||
int l=strlen(str);
|
||||
static char * xstr ;
|
||||
xstr = str + l;
|
||||
int l=strlen(str);
|
||||
static char * xstr ;
|
||||
xstr = str + l;
|
||||
|
||||
while (xstr-- && l--)
|
||||
if (*xstr == '\\' || *xstr == '/')
|
||||
break;
|
||||
if (l == 0)
|
||||
return NULL;
|
||||
else
|
||||
return xstr;
|
||||
while (xstr-- && l--)
|
||||
if (*xstr == '\\' || *xstr == '/')
|
||||
break;
|
||||
if (l == 0)
|
||||
return NULL;
|
||||
else
|
||||
return xstr;
|
||||
}
|
||||
|
||||
|
||||
@ -80,7 +80,7 @@ void DB_init(void)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<CB4FILES;i++) {
|
||||
dbdata[i]=(DATA4 *) 0;
|
||||
dbdata[i]=(DATA4 *) 0;
|
||||
}
|
||||
d4init(&code_base);
|
||||
code_base.read_lock=0;
|
||||
@ -114,10 +114,10 @@ int DB_open(const char *filename,int mode)
|
||||
// cerca il primo posto libero nel vettore dbdata
|
||||
found=-1;
|
||||
for(i=0;i<CB4FILES;i++) {
|
||||
if(dbdata[i]==(DATA4 *) 0) {
|
||||
found=i;
|
||||
break;
|
||||
}
|
||||
if(dbdata[i]==(DATA4 *) 0) {
|
||||
found=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// se non ci sono posti liberi torna -1
|
||||
if(found==-1) return(found);
|
||||
@ -128,7 +128,7 @@ int DB_open(const char *filename,int mode)
|
||||
code_base.exclusive=0;
|
||||
d4tag_select(dbdata[found],d4tag_default(dbdata[found]));
|
||||
if (d4reccount(dbdata[found]) > 0)
|
||||
x4top(&xdb[found]);
|
||||
x4top(&xdb[found]);
|
||||
return(found);
|
||||
}
|
||||
|
||||
@ -210,8 +210,8 @@ int DB_tagselect(int handle,int index_no)
|
||||
tt=d4tag_next(dbdata[handle],NULL);
|
||||
if(tt==NULL) return(-1);
|
||||
for(i=1;i<index_no;i++) {
|
||||
tt=d4tag_next(dbdata[handle],tt);
|
||||
if(tt==NULL) return(-1);
|
||||
tt=d4tag_next(dbdata[handle],tt);
|
||||
if(tt==NULL) return(-1);
|
||||
}
|
||||
d4tag_select(dbdata[handle],tt);
|
||||
return(0);
|
||||
@ -235,8 +235,8 @@ int DB_tagget(int handle)
|
||||
tt1=d4tag_next(dbdata[handle],NULL);
|
||||
i=1;
|
||||
while(tt!=tt1 && tt1!=NULL) {
|
||||
tt1=d4tag_next(dbdata[handle],tt1);
|
||||
i++;
|
||||
tt1=d4tag_next(dbdata[handle],tt1);
|
||||
i++;
|
||||
}
|
||||
return(i);
|
||||
}
|
||||
@ -297,8 +297,7 @@ int DB_skip(int handle,long int recno)
|
||||
int DB_lock(int handle)
|
||||
{
|
||||
if(dbdata[handle]==0) return(-1);
|
||||
if(d4lock(dbdata[handle],d4recno(dbdata[handle]))==r4locked) return(-1);
|
||||
else return(0);
|
||||
return(d4lock(dbdata[handle],d4recno(dbdata[handle])));
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
@ -384,14 +383,14 @@ int DB_delkey(int handle, char* key, long recno)
|
||||
t=d4tag_default(dbdata[handle]);
|
||||
|
||||
if (u4switch() & 2 || u4switch() & 8) // Clipper & DBIII
|
||||
u4name_piece(fn,32,dbdata[handle]->file.name,0,0);
|
||||
u4name_piece(fn,32,dbdata[handle]->file.name,0,0);
|
||||
else
|
||||
strcpy(fn,dbdata[handle]->file.name);
|
||||
strcpy(fn,dbdata[handle]->file.name);
|
||||
if ((i=d4index(dbdata[handle],fn)) == NULL)
|
||||
return(e4index);
|
||||
return(e4index);
|
||||
rt=i4lock(i);
|
||||
if (rt == 0)
|
||||
rt=t4remove_calc(t,recno);
|
||||
rt=t4remove_calc(t,recno);
|
||||
i4unlock(i);
|
||||
return(rt);
|
||||
}
|
||||
@ -435,9 +434,9 @@ HIDDEN int is_inkey(RecDes *r, int numfield)
|
||||
int found=0,i,j;
|
||||
|
||||
for (i=0; ((i < MaxKeys) && (i < r->NKeys) && !found); i++)
|
||||
for (j=0; ((j < r->Ky[i].NkFields) && !found); j++)
|
||||
if (numfield == r->Ky[i].FieldSeq[j])
|
||||
found=1;
|
||||
for (j=0; ((j < r->Ky[i].NkFields) && !found); j++)
|
||||
if (numfield == r->Ky[i].FieldSeq[j])
|
||||
found=1;
|
||||
return(found);
|
||||
}
|
||||
|
||||
@ -450,95 +449,95 @@ HIDDEN void do_key(char *fname, RecDes *r, TAG4INFO *tag_info)
|
||||
CUpString(tiname);
|
||||
for (i=0; ((i < MaxKeys) && (i < r->NKeys)); i++)
|
||||
{
|
||||
tag_info[i].name=(char *)u4alloc(9);
|
||||
tag_info[i].expression=(char *)u4alloc(128);
|
||||
tag_info[i].filter=(char*)u4alloc(20);
|
||||
tag_info[i].descending=0;
|
||||
if (r->Ky[i].DupKeys)
|
||||
tag_info[i].unique=0;
|
||||
else
|
||||
tag_info[i].unique=e4unique;
|
||||
strcpy(tag_info[i].filter,""); // Not available for DBIII and CLIPPER
|
||||
strcpy(tag_info[i].name,tiname) ;
|
||||
if (strlen(tiname) < 8)
|
||||
strcat(tag_info[i].name," ");
|
||||
tag_info[i].name[strlen(tag_info[i].name)-1] = '0' + i + 1;
|
||||
for (j=0; j < r->Ky[i].NkFields; j++)
|
||||
{
|
||||
int nf= r->Ky[i].FieldSeq[j];
|
||||
if (nf > MaxFields) // When Upper field is specified
|
||||
{
|
||||
nf -= MaxFields;
|
||||
strcat(tag_info[i].expression,"UPPER(");
|
||||
}
|
||||
if (r->Ky[i].FromCh[j] != 255) // When partial field is specified
|
||||
strcat(tag_info[i].expression,"SUBSTR(");
|
||||
tag_info[i].name=(char *)u4alloc(9);
|
||||
tag_info[i].expression=(char *)u4alloc(128);
|
||||
tag_info[i].filter=(char*)u4alloc(20);
|
||||
tag_info[i].descending=0;
|
||||
if (r->Ky[i].DupKeys)
|
||||
tag_info[i].unique=0;
|
||||
else
|
||||
tag_info[i].unique=e4unique;
|
||||
strcpy(tag_info[i].filter,""); // Not available for DBIII and CLIPPER
|
||||
strcpy(tag_info[i].name,tiname) ;
|
||||
if (strlen(tiname) < 8)
|
||||
strcat(tag_info[i].name," ");
|
||||
tag_info[i].name[strlen(tag_info[i].name)-1] = '0' + i + 1;
|
||||
for (j=0; j < r->Ky[i].NkFields; j++)
|
||||
{
|
||||
int nf= r->Ky[i].FieldSeq[j];
|
||||
if (nf > MaxFields) // When Upper field is specified
|
||||
{
|
||||
nf -= MaxFields;
|
||||
strcat(tag_info[i].expression,"UPPER(");
|
||||
}
|
||||
if (r->Ky[i].FromCh[j] != 255) // When partial field is specified
|
||||
strcat(tag_info[i].expression,"SUBSTR(");
|
||||
|
||||
switch (r->Fd[nf].TypeF) // When numeric field in key is specified
|
||||
{
|
||||
case _intfld:
|
||||
case _longfld:
|
||||
case _realfld:
|
||||
case _wordfld:
|
||||
case _intzerofld:
|
||||
case _longzerofld:
|
||||
strcat(tag_info[i].expression,"STR(");
|
||||
break;
|
||||
case _datefld:
|
||||
strcat(tag_info[i].expression,"DTOS(");
|
||||
break;
|
||||
case _boolfld:
|
||||
strcat(tag_info[i].expression,"IIF("); // Logical fields are in key too...
|
||||
break;
|
||||
default: // It's a non sense to keep _realfld in key...
|
||||
break; // however it's possible to have it...
|
||||
} // Le chiavi composte da campi data non necessitano di funzioni di traduzione.
|
||||
switch (r->Fd[nf].TypeF) // When numeric field in key is specified
|
||||
{
|
||||
case _intfld:
|
||||
case _longfld:
|
||||
case _realfld:
|
||||
case _wordfld:
|
||||
case _intzerofld:
|
||||
case _longzerofld:
|
||||
strcat(tag_info[i].expression,"STR(");
|
||||
break;
|
||||
case _datefld:
|
||||
strcat(tag_info[i].expression,"DTOS(");
|
||||
break;
|
||||
case _boolfld:
|
||||
strcat(tag_info[i].expression,"IIF("); // Logical fields are in key too...
|
||||
break;
|
||||
default: // It's a non sense to keep _realfld in key...
|
||||
break; // however it's possible to have it...
|
||||
} // Le chiavi composte da campi data non necessitano di funzioni di traduzione.
|
||||
|
||||
strcat(tag_info[i].expression,r->Fd[nf].Name); // Append field name
|
||||
strcat(tag_info[i].expression,r->Fd[nf].Name); // Append field name
|
||||
|
||||
if (r->Ky[i].FromCh[j] != 255) // If partial field was specified
|
||||
{ // add parameters to SUBSTR
|
||||
char ts[8];
|
||||
if (r->Ky[i].FromCh[j] != 255) // If partial field was specified
|
||||
{ // add parameters to SUBSTR
|
||||
char ts[8];
|
||||
|
||||
strcat(tag_info[i].expression,",");
|
||||
sprintf(ts,"%d",r->Ky[i].FromCh[j]);
|
||||
strcat(tag_info[i].expression,ts);
|
||||
strcat(tag_info[i].expression,",");
|
||||
sprintf(ts,"%d",r->Ky[i].ToCh[j] - r->Ky[i].FromCh[j] + 1);
|
||||
strcat(tag_info[i].expression,ts);
|
||||
strcat(tag_info[i].expression,")");
|
||||
}
|
||||
strcat(tag_info[i].expression,",");
|
||||
sprintf(ts,"%d",r->Ky[i].FromCh[j]);
|
||||
strcat(tag_info[i].expression,ts);
|
||||
strcat(tag_info[i].expression,",");
|
||||
sprintf(ts,"%d",r->Ky[i].ToCh[j] - r->Ky[i].FromCh[j] + 1);
|
||||
strcat(tag_info[i].expression,ts);
|
||||
strcat(tag_info[i].expression,")");
|
||||
}
|
||||
|
||||
switch (r->Fd[nf].TypeF) // If numeric field was specified
|
||||
{ // add parameters to STR
|
||||
case _intfld:
|
||||
case _longfld:
|
||||
case _realfld: // Questo tipo di campo(real) non ha senso in un a chiave...
|
||||
case _wordfld:
|
||||
case _intzerofld:
|
||||
case _longzerofld:
|
||||
{
|
||||
char ts[8];
|
||||
strcat(tag_info[i].expression,",");
|
||||
sprintf(ts,"%d",r->Fd[nf].Len);
|
||||
strcat(tag_info[i].expression,ts);
|
||||
strcat(tag_info[i].expression,",0)");
|
||||
}
|
||||
break;
|
||||
case _boolfld: // Orgssbb... Che culo.
|
||||
strcat(tag_info[i].expression,",\"T\",\"F\")");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (r->Fd[nf].TypeF) // If numeric field was specified
|
||||
{ // add parameters to STR
|
||||
case _intfld:
|
||||
case _longfld:
|
||||
case _realfld: // Questo tipo di campo(real) non ha senso in un a chiave...
|
||||
case _wordfld:
|
||||
case _intzerofld:
|
||||
case _longzerofld:
|
||||
{
|
||||
char ts[8];
|
||||
strcat(tag_info[i].expression,",");
|
||||
sprintf(ts,"%d",r->Fd[nf].Len);
|
||||
strcat(tag_info[i].expression,ts);
|
||||
strcat(tag_info[i].expression,",0)");
|
||||
}
|
||||
break;
|
||||
case _boolfld: // Orgssbb... Che culo.
|
||||
strcat(tag_info[i].expression,",\"T\",\"F\")");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Close parentheses if UPPER or DTOS operators were used:
|
||||
if (r->Ky[i].FieldSeq[j] > MaxFields || (r->Fd[nf].TypeF == _datefld))
|
||||
strcat(tag_info[i].expression,")");
|
||||
if (r->Ky[i].FieldSeq[j] > MaxFields || (r->Fd[nf].TypeF == _datefld))
|
||||
strcat(tag_info[i].expression,")");
|
||||
// If there's another field in key adds "+" operator:
|
||||
if (j < (r->Ky[i].NkFields-1))
|
||||
strcat(tag_info[i].expression,"+");
|
||||
}
|
||||
if (j < (r->Ky[i].NkFields-1))
|
||||
strcat(tag_info[i].expression,"+");
|
||||
}
|
||||
}
|
||||
tag_info[i].name=NULL;
|
||||
tag_info[i].expression=NULL;
|
||||
@ -560,32 +559,32 @@ int DB_packfile(short vis, const char * filename, long eod)
|
||||
handle=DB_open(filename,1); // Exclusive mode open!
|
||||
if (handle > -1)
|
||||
{
|
||||
char s[81];
|
||||
char s[81];
|
||||
|
||||
if (vis)
|
||||
{
|
||||
strcpy(s,"Compattamento dati file : ");
|
||||
strcat(s,(char*)filename);
|
||||
if (vis)
|
||||
{
|
||||
strcpy(s,"Compattamento dati file : ");
|
||||
strcat(s,(char*)filename);
|
||||
#ifndef FOXPRO
|
||||
progind_create(10L,s,1,1,1);
|
||||
progind_create(10L,s,1,1,1);
|
||||
#endif
|
||||
}
|
||||
if (eod < d4reccount(dbdata[handle]))
|
||||
{
|
||||
rt=d4zap(dbdata[handle],++eod,d4reccount(dbdata[handle]));
|
||||
} else
|
||||
rt=d4pack(dbdata[handle]);
|
||||
if (vis)
|
||||
{
|
||||
}
|
||||
if (eod < d4reccount(dbdata[handle]))
|
||||
{
|
||||
rt=d4zap(dbdata[handle],++eod,d4reccount(dbdata[handle]));
|
||||
} else
|
||||
rt=d4pack(dbdata[handle]);
|
||||
if (vis)
|
||||
{
|
||||
#ifndef FOXPRO
|
||||
progind_set_status((long)10);
|
||||
progind_destroy();
|
||||
progind_set_status((long)10);
|
||||
progind_destroy();
|
||||
#endif
|
||||
}
|
||||
DB_close(handle);
|
||||
}
|
||||
DB_close(handle);
|
||||
}
|
||||
else
|
||||
rt=code_base.error_code;
|
||||
else
|
||||
rt=code_base.error_code;
|
||||
code_base.auto_open = 1;
|
||||
return rt;
|
||||
}
|
||||
@ -607,63 +606,63 @@ int DB_packindex(short vis, const char * filename, RecDes *r, long *peod)
|
||||
handle=DB_open(filename,1); // Exclusive mode open
|
||||
if (handle > -1)
|
||||
{
|
||||
int i;
|
||||
char *ff = find_slash_backslash((char *)filename);
|
||||
if (vis)
|
||||
{
|
||||
int i;
|
||||
char *ff = find_slash_backslash((char *)filename);
|
||||
if (vis)
|
||||
{
|
||||
#ifndef FOXPRO
|
||||
progind_create((long)r->NKeys,s,1,1,1);
|
||||
progind_create((long)r->NKeys,s,1,1,1);
|
||||
#endif
|
||||
}
|
||||
if (ff == NULL || *ff == NULL)
|
||||
ff = filename;
|
||||
else
|
||||
ff++;
|
||||
do_key(ff,r,tags);
|
||||
if (u4switch() &2 || u4switch() & 8) // Clipper and DBIII
|
||||
{
|
||||
rt = (int)i4create(dbdata[handle],(char*)filename,tags);
|
||||
}
|
||||
if (ff == NULL || *ff == NULL)
|
||||
ff = filename;
|
||||
else
|
||||
ff++;
|
||||
do_key(ff,r,tags);
|
||||
if (u4switch() &2 || u4switch() & 8) // Clipper and DBIII
|
||||
{
|
||||
rt = (int)i4create(dbdata[handle],(char*)filename,tags);
|
||||
#ifndef FOXPRO
|
||||
progind_set_status((long)r->NKeys);
|
||||
progind_set_status((long)r->NKeys);
|
||||
#endif
|
||||
if (rt!=0 && code_base.error_code==0)
|
||||
{
|
||||
FILE *fp;
|
||||
char cgp[81];
|
||||
if (rt!=0 && code_base.error_code==0)
|
||||
{
|
||||
FILE *fp;
|
||||
char cgp[81];
|
||||
|
||||
strcpy(cgp,filename);
|
||||
strcat(cgp,".CGP");
|
||||
if ((fp=fopen(cgp,"w"))!=NULL)
|
||||
{
|
||||
int j;
|
||||
strcpy(cgp,filename);
|
||||
strcat(cgp,".CGP");
|
||||
if ((fp=fopen(cgp,"w"))!=NULL)
|
||||
{
|
||||
int j;
|
||||
|
||||
for (j=0; j<r->NKeys;j++)
|
||||
fprintf(fp,"%s\n",tags[j].name);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (u4switch() & 1 || u4switch() & 4) // FOXPRO and DBIV
|
||||
{
|
||||
rt = (int)i4create(dbdata[handle],NULL,tags);
|
||||
for (j=0; j<r->NKeys;j++)
|
||||
fprintf(fp,"%s\n",tags[j].name);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (u4switch() & 1 || u4switch() & 4) // FOXPRO and DBIV
|
||||
{
|
||||
rt = (int)i4create(dbdata[handle],NULL,tags);
|
||||
#ifndef FOXPRO
|
||||
progind_set_status((long)r->NKeys);
|
||||
progind_set_status((long)r->NKeys);
|
||||
#endif
|
||||
}
|
||||
for (i=0; ((i < MaxKeys) && (i < r->NKeys)); i++)
|
||||
{
|
||||
u4free(tags[i].name);
|
||||
u4free(tags[i].expression);
|
||||
u4free(tags[i].filter);
|
||||
}
|
||||
if (vis)
|
||||
{
|
||||
}
|
||||
for (i=0; ((i < MaxKeys) && (i < r->NKeys)); i++)
|
||||
{
|
||||
u4free(tags[i].name);
|
||||
u4free(tags[i].expression);
|
||||
u4free(tags[i].filter);
|
||||
}
|
||||
if (vis)
|
||||
{
|
||||
#ifndef FOXPRO
|
||||
progind_destroy();
|
||||
progind_destroy();
|
||||
#endif
|
||||
}
|
||||
*peod=DB_reccount(handle);
|
||||
DB_close(handle);
|
||||
}
|
||||
*peod=DB_reccount(handle);
|
||||
DB_close(handle);
|
||||
}
|
||||
code_base.auto_open = 1;
|
||||
return(code_base.error_code);
|
||||
@ -692,24 +691,24 @@ int DB_build(const char * filename, RecDes *r)
|
||||
field_info[i].dec = r->Fd[i].Dec;
|
||||
switch (r->Fd[i].TypeF)
|
||||
{
|
||||
case _intfld:
|
||||
case _longfld:
|
||||
case _realfld: // It's a non sense to keep this in key!
|
||||
case _wordfld:
|
||||
case _intzerofld:
|
||||
case _longzerofld:
|
||||
field_info[i].type=r4num;
|
||||
break;
|
||||
case _boolfld:
|
||||
field_info[i].type=r4log;
|
||||
break;
|
||||
case _datefld:
|
||||
field_info[i].type=r4date;
|
||||
break;
|
||||
case _charfld:
|
||||
default:
|
||||
field_info[i].type=r4str;
|
||||
break;
|
||||
case _intfld:
|
||||
case _longfld:
|
||||
case _realfld: // It's a non sense to keep this in key!
|
||||
case _wordfld:
|
||||
case _intzerofld:
|
||||
case _longzerofld:
|
||||
field_info[i].type=r4num;
|
||||
break;
|
||||
case _boolfld:
|
||||
field_info[i].type=r4log;
|
||||
break;
|
||||
case _datefld:
|
||||
field_info[i].type=r4date;
|
||||
break;
|
||||
case _charfld:
|
||||
default:
|
||||
field_info[i].type=r4str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
field_info[i].name=NULL;
|
||||
@ -726,7 +725,7 @@ int DB_build(const char * filename, RecDes *r)
|
||||
if ((dbuilded=d4create(&code_base, (char *)filename, field_info, tag_info))==0) // deve solo creare il file dati vuoto
|
||||
rt=code_base.error_code;
|
||||
else
|
||||
rt=d4close(dbuilded);
|
||||
rt=d4close(dbuilded);
|
||||
if (u4switch() & 2 || u4switch() & 8) // Rebuild filename.cgp for CLIPPER AND DBIII only
|
||||
{
|
||||
FILE* fp;
|
||||
@ -762,9 +761,9 @@ int DB_build(const char * filename, RecDes *r)
|
||||
|
||||
int DB_get_error(void)
|
||||
{
|
||||
int rt = code_base.error_code;
|
||||
code_base.error_code=0;
|
||||
return (rt);
|
||||
int rt = code_base.error_code;
|
||||
code_base.error_code=0;
|
||||
return (rt);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
@ -773,7 +772,7 @@ int DB_get_error(void)
|
||||
|
||||
void DB_zero_error(void)
|
||||
{
|
||||
code_base.error_code=0;
|
||||
code_base.error_code=0;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
@ -904,9 +903,9 @@ long DB_changed(int handle)
|
||||
|
||||
if(dbdata[handle]==0) return(-1);
|
||||
if (u4switch() & 2 || u4switch() & 8) // Clipper & DBIII
|
||||
u4name_piece(fn,32,dbdata[handle]->file.name,0,0);
|
||||
u4name_piece(fn,32,dbdata[handle]->file.name,0,0);
|
||||
else
|
||||
strcpy(fn,dbdata[handle]->file.name);
|
||||
strcpy(fn,dbdata[handle]->file.name);
|
||||
i=d4index(dbdata[handle],fn);
|
||||
if (i == NULL) return(-1);
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
CODEBASE.H
|
||||
data : 23.01.95
|
||||
scopo: interfaccia verso CodeBase 5.0
|
||||
--------------------------------------------------------------------------*/
|
||||
--------------------------------------------------------------------------*/
|
||||
#ifndef __CODEBASE_H
|
||||
#define __CODEBASE_H
|
||||
|
||||
@ -12,59 +12,59 @@
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
numero massimo di database aperti contemporaneamente
|
||||
--------------------------------------------------------------------------*/
|
||||
--------------------------------------------------------------------------*/
|
||||
#define CB4FILES 50
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
prototipi funzioni
|
||||
--------------------------------------------------------------------------*/
|
||||
--------------------------------------------------------------------------*/
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void DB_init(void);
|
||||
void DB_exit(void);
|
||||
int DB_open(const char *filename,int mode);
|
||||
int DB_close(int handle);
|
||||
char *DB_getrecord(int handle);
|
||||
int DB_reclen(int handle);
|
||||
int DB_keylen(int handle);
|
||||
long int DB_recno(int handle);
|
||||
long int DB_reccount(int handle);
|
||||
int DB_tagselect(int handle,int index_no);
|
||||
int DB_tagget(int handle);
|
||||
int DB_first(int handle);
|
||||
int DB_last(int handle);
|
||||
int DB_next(int handle);
|
||||
int DB_prev(int handle);
|
||||
int DB_skip(int handle,long int recno);
|
||||
int DB_lock(int handle);
|
||||
int DB_lockrec(int handle, long recno); // Per sbloccare il record basta la DB_unlock()
|
||||
int DB_unlock(int handle);
|
||||
int DB_seek(int handle,char *key);
|
||||
int DB_eof(int handle);
|
||||
int DB_bof(int handle);
|
||||
int DB_go(int handle,long int recno);
|
||||
int DB_delete(int handle);
|
||||
int DB_recall(int handle);
|
||||
int DB_delkey(int handle, char* key, long recno);
|
||||
int DB_rewrite(int handle);
|
||||
int DB_add(int handle);
|
||||
int DB_lockfile(int handle); // Per sbloccare il file basta la DB_unlock()
|
||||
int DB_packfile(short vis, const char * filename, long eod);
|
||||
int DB_packindex(short vis, const char * filename, RecDes *r, long *peod );
|
||||
int DB_build(const char * filename, RecDes *r);
|
||||
int DB_get_error(void);
|
||||
void DB_zero_error(void);
|
||||
int DB_index_seek(int handle, char* from);
|
||||
long DB_index_recno(int handle);
|
||||
long DB_index_next(int handle);
|
||||
char* DB_index_getkey(int handle);
|
||||
int DB_index_eof(int handle);
|
||||
int DB_lock_rec(int handle,long nrec);
|
||||
int DB_file_locked(int handle);
|
||||
int DB_rec_locked(int handle,long nrec);
|
||||
long DB_getconf();
|
||||
long DB_changed(int handle); // returns true if the index of the key is changed
|
||||
void DB_init(void);
|
||||
void DB_exit(void);
|
||||
int DB_open(const char *filename,int mode);
|
||||
int DB_close(int handle);
|
||||
char *DB_getrecord(int handle);
|
||||
int DB_reclen(int handle);
|
||||
int DB_keylen(int handle);
|
||||
long int DB_recno(int handle);
|
||||
long int DB_reccount(int handle);
|
||||
int DB_tagselect(int handle,int index_no);
|
||||
int DB_tagget(int handle);
|
||||
int DB_first(int handle);
|
||||
int DB_last(int handle);
|
||||
int DB_next(int handle);
|
||||
int DB_prev(int handle);
|
||||
int DB_skip(int handle,long int recno);
|
||||
int DB_lock(int handle);
|
||||
int DB_lockrec(int handle, long recno); // Per sbloccare il record basta la DB_unlock()
|
||||
int DB_unlock(int handle);
|
||||
int DB_seek(int handle,char *key);
|
||||
int DB_eof(int handle);
|
||||
int DB_bof(int handle);
|
||||
int DB_go(int handle,long int recno);
|
||||
int DB_delete(int handle);
|
||||
int DB_recall(int handle);
|
||||
int DB_delkey(int handle, char* key, long recno);
|
||||
int DB_rewrite(int handle);
|
||||
int DB_add(int handle);
|
||||
int DB_lockfile(int handle); // Per sbloccare il file basta la DB_unlock()
|
||||
int DB_packfile(short vis, const char * filename, long eod);
|
||||
int DB_packindex(short vis, const char * filename, RecDes *r, long *peod );
|
||||
int DB_build(const char * filename, RecDes *r);
|
||||
int DB_get_error(void);
|
||||
void DB_zero_error(void);
|
||||
int DB_index_seek(int handle, char* from);
|
||||
long DB_index_recno(int handle);
|
||||
long DB_index_next(int handle);
|
||||
char* DB_index_getkey(int handle);
|
||||
int DB_index_eof(int handle);
|
||||
int DB_lock_rec(int handle,long nrec);
|
||||
int DB_file_locked(int handle);
|
||||
int DB_rec_locked(int handle,long nrec);
|
||||
long DB_getconf();
|
||||
long DB_changed(int handle); // returns true if the index of the key is changed
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
@ -300,17 +300,18 @@ HIDDEN int cisread(isfdptr isfd, TRectype & record, int mode)
|
||||
}
|
||||
if (rmode != _isequal && err == _iseof)
|
||||
DB_last(isfd->fhnd);
|
||||
if (err == NOERR && (lmode == _lock || lmode == _testandlock)) // _lock e _testandlock
|
||||
{
|
||||
err=DB_lock(isfd->fhnd);
|
||||
if (err != NOERR) err=get_error(err);
|
||||
if (err == _islocked && lmode == _testandlock) break;
|
||||
}
|
||||
if (!tlock && err == _islocked)
|
||||
{
|
||||
CBuildKey(isfd->r, DB_tagget(isfd->fhnd), record.string(), key);
|
||||
message_box("Codice %s in uso da parte\ndi un altro utente.", key);
|
||||
}
|
||||
} while (!tlock && err ==_islocked);
|
||||
if (err == NOERR && lmode == _lock)
|
||||
{
|
||||
err=DB_lock(isfd->fhnd);
|
||||
if (err != NOERR) err=get_error(err);
|
||||
}
|
||||
if (err == NOERR && unlock)
|
||||
{
|
||||
err=DB_unlock(isfd->fhnd);
|
||||
@ -675,16 +676,6 @@ int TBaseisamfile::skip(TRecnotype nrec, word lockop)
|
||||
}
|
||||
_lasterr=cisread(_isamfile,curr(),_iscurr + lockop);
|
||||
} while (!tlock && _lasterr ==_islocked);
|
||||
if (_lasterr == NOERR && lmode == _lock)
|
||||
{
|
||||
_lasterr=DB_lock(_isamfile->fhnd);
|
||||
if (_lasterr != NOERR) _lasterr=get_error(_lasterr);
|
||||
}
|
||||
if (_lasterr == NOERR && unlock)
|
||||
{
|
||||
_lasterr=DB_unlock(_isamfile->fhnd);
|
||||
if (_lasterr != NOERR) _lasterr=get_error(_lasterr);
|
||||
}
|
||||
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
|
||||
return _lasterr;
|
||||
}
|
||||
@ -748,10 +739,18 @@ int TBaseisamfile::write(TDate& atdate)
|
||||
|
||||
{
|
||||
NOT_OPEN();
|
||||
int oldkey=getkey();
|
||||
browse_null(curr().string(),DB_reclen(_isamfile->fhnd));
|
||||
memcpy(DB_getrecord(_isamfile->fhnd),curr().string(),DB_reclen(_isamfile->fhnd));
|
||||
_lasterr = DB_add(_isamfile->fhnd);
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
setkey(1);
|
||||
if (cisread(_isamfile, curr(), _isequal + _nolock) == _iskeynotfound)
|
||||
{
|
||||
_lasterr = DB_add(_isamfile->fhnd);
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
}
|
||||
else
|
||||
_lasterr=_isreinsert;
|
||||
setkey(oldkey);
|
||||
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
|
||||
return _lasterr;
|
||||
}
|
||||
@ -761,10 +760,18 @@ int TBaseisamfile::write(const TRectype& rec, TDate& atdate)
|
||||
|
||||
{
|
||||
NOT_OPEN();
|
||||
int oldkey=getkey();
|
||||
browse_null(rec.string(),DB_reclen(_isamfile->fhnd));
|
||||
memcpy(DB_getrecord(_isamfile->fhnd),rec.string(),DB_reclen(_isamfile->fhnd));
|
||||
_lasterr = DB_add(_isamfile->fhnd);
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
setkey(1);
|
||||
if (cisread(_isamfile, (TRectype&)rec, _isequal + _nolock) == _iskeynotfound)
|
||||
{
|
||||
_lasterr = DB_add(_isamfile->fhnd);
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
}
|
||||
else
|
||||
_lasterr=_isreinsert;
|
||||
setkey(oldkey);
|
||||
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
|
||||
return _lasterr;
|
||||
}
|
||||
@ -952,12 +959,17 @@ int TBaseisamfile::_open(unsigned int mode)
|
||||
{
|
||||
TRecnotype n=DB_reccount(filehnd()->fhnd);
|
||||
TDir d;
|
||||
d.get(num());
|
||||
// d.get(num());
|
||||
d.get(num(),_nolock,_nordir,_sysdirop);
|
||||
if (d.is_com()) d.get(num(),_nolock,_comdir);
|
||||
if ((filehnd()->d->EOD != n && n > 0) || (n >= d.eox()))
|
||||
{
|
||||
filehnd()->d->EOD = d.eod() = n;
|
||||
filehnd()->d->EOX = d.eox() = (TRecnotype) (n*1.2);
|
||||
d.put(num());
|
||||
if (d.is_com())
|
||||
d.put(num(),_comdir);
|
||||
else
|
||||
d.put(num());
|
||||
}
|
||||
filehnd()->ln = num();
|
||||
openf[num() - 1] = filehnd();
|
||||
@ -987,12 +999,17 @@ int TBaseisamfile::_close()
|
||||
{
|
||||
TDir d;
|
||||
TRecnotype n=DB_reccount(filehnd()->fhnd);
|
||||
d.get(num());
|
||||
//d.get(num());
|
||||
d.get(num(),_nolock,_nordir,_sysdirop);
|
||||
if (d.is_com()) d.get(num(),_nolock,_comdir);
|
||||
if ((filehnd()->d->EOD != n && n > 0) || (n >= d.eox()))
|
||||
{
|
||||
filehnd()->d->EOD=d.eod()=n;
|
||||
filehnd()->d->EOX = d.eox() = (TRecnotype) (n*1.2);
|
||||
d.put(num());
|
||||
if (d.is_com())
|
||||
d.put(num(),_comdir);
|
||||
else
|
||||
d.put(num());
|
||||
}
|
||||
CHECK(openf[num() - 1] != NULL, "Open file array corrupted");
|
||||
err=DB_close(filehnd()->fhnd);
|
||||
@ -1062,12 +1079,17 @@ int TLocalisamfile::close()
|
||||
{
|
||||
TRecnotype n = DB_reccount(filehnd()->fhnd);
|
||||
TDir d;
|
||||
d.get(num());
|
||||
//d.get(num());
|
||||
d.get(num(),_nolock,_nordir,_sysdirop);
|
||||
if (d.is_com()) d.get(num(),_nolock,_comdir);
|
||||
if ((filehnd()->d->EOD!=n && n > 0) || (n > d.eox()))
|
||||
{
|
||||
filehnd()->d->EOD = d.eod() = n;
|
||||
filehnd()->d->EOX = d.eox() = n;
|
||||
d.put(num());
|
||||
if (d.is_com())
|
||||
d.put(num(),_comdir);
|
||||
else
|
||||
d.put(num());
|
||||
}
|
||||
err = DB_close(_isamfile->fhnd);
|
||||
if (err != NOERR) err = get_error(err);
|
||||
@ -2578,6 +2600,14 @@ HIDDEN void __getfieldbuff(byte l, byte t, const char* recin, char *s)
|
||||
TDate dt(atol(s));
|
||||
strcpy(s, dt.string(full));
|
||||
}
|
||||
if (t == _boolfld && *s)
|
||||
{
|
||||
if (toupper(*s) == 'T' || toupper(*s) == 'Y'
|
||||
|| toupper(*s) == 'S' || toupper(*s) == 'X')
|
||||
strcpy(s,"X");
|
||||
else
|
||||
strcpy(s," ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2599,8 +2629,18 @@ HIDDEN void __putfieldbuff(byte l, byte d, byte t, const char* s, char* recout)
|
||||
TDate dt(s2);
|
||||
sprintf(s2,"%8s", dt.string(ANSI));
|
||||
}
|
||||
} else
|
||||
if (t == _realfld) setdec(s2, d);
|
||||
}
|
||||
else
|
||||
if (t == _boolfld)
|
||||
{
|
||||
if (toupper(*s2) == 'T' || toupper(*s2) == 'Y'
|
||||
|| toupper(*s2) == 'S' || toupper(*s2) == 'X')
|
||||
strcpy(s2,"T");
|
||||
else
|
||||
strcpy(s2,"F");
|
||||
}
|
||||
else
|
||||
if (t == _realfld) setdec(s2, d);
|
||||
|
||||
len = strlen(s2);
|
||||
if (len > l) return ;
|
||||
|
Loading…
x
Reference in New Issue
Block a user