Rif. mod. 95/33. Sistemata la DB_delkeys() e la DB_add() sui lock.
Cambiata la DB_locked(). Sostituite le msg_box() di debug con yesnofatal_box(). Eliminati i messaggi di warning in compilazione. git-svn-id: svn://10.65.10.50/trunk@1858 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
c7c98364fb
commit
0eb80acad6
@ -396,6 +396,8 @@ int DB_delkey(int handle, char* key, long recno)
|
|||||||
INDEX4* i;
|
INDEX4* i;
|
||||||
TAG4* t;
|
TAG4* t;
|
||||||
int rt=0;
|
int rt=0;
|
||||||
|
int is_locked = 0; /* Diverso da 0 se il file e' bloccato in modo esclusivo */
|
||||||
|
/* (dati o indice) da me stesso*/
|
||||||
char fn[64];
|
char fn[64];
|
||||||
|
|
||||||
if(dbdata[handle]==0) return(-1);
|
if(dbdata[handle]==0) return(-1);
|
||||||
@ -406,16 +408,21 @@ int DB_delkey(int handle, char* key, long recno)
|
|||||||
else
|
else
|
||||||
strcpy(fn,dbdata[handle]->file.name);
|
strcpy(fn,dbdata[handle]->file.name);
|
||||||
if ((i=d4index(dbdata[handle],fn)) == NULL)
|
if ((i=d4index(dbdata[handle],fn)) == NULL)
|
||||||
return(e4index);
|
return(e4index);
|
||||||
while ((rt=i4lock(i)) == r4locked)
|
is_locked = DB_file_locked(handle);
|
||||||
|
if (is_locked == 0) /* Se non e' stato bloccato in modo esclusivo */
|
||||||
|
{
|
||||||
|
while ((rt=i4lock(i)) == r4locked)
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
message_box("Sono in attesa nella DB_delkeys");
|
yesnofatal_box("Sono in attesa nella DB_delkeys");
|
||||||
#else
|
#else
|
||||||
u4delay_sec();
|
u4delay_sec();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
if (rt == 0)
|
if (rt == 0)
|
||||||
rt=t4remove_calc(t,recno);
|
rt=t4remove_calc(t,recno);
|
||||||
i4unlock(i);
|
if (is_locked == 0) /* Siccome ho fatto il lock dell'indice, devo anche sbloccarlo */
|
||||||
|
i4unlock(i);
|
||||||
return(rt);
|
return(rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,7 +435,7 @@ int DB_flush(int handle)
|
|||||||
|
|
||||||
while ((rt = d4flush(dbdata[handle])) == r4locked)
|
while ((rt = d4flush(dbdata[handle])) == r4locked)
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
message_box("Sono in attesa nella DB_add (d4append)");
|
yesnofatal_box("Sono in attesa nella DB_flush");
|
||||||
#else
|
#else
|
||||||
u4delay_sec();
|
u4delay_sec();
|
||||||
#endif
|
#endif
|
||||||
@ -444,7 +451,7 @@ int DB_rewrite(int handle)
|
|||||||
if(dbdata[handle]==0) return(-1);
|
if(dbdata[handle]==0) return(-1);
|
||||||
while ((rt=d4write(dbdata[handle],d4recno(dbdata[handle]))) == r4locked)
|
while ((rt=d4write(dbdata[handle],d4recno(dbdata[handle]))) == r4locked)
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
message_box("Sono in attesa nella DB_rewrite");
|
yesnofatal_box("Sono in attesa nella DB_rewrite");
|
||||||
#else
|
#else
|
||||||
u4delay_sec();
|
u4delay_sec();
|
||||||
#endif
|
#endif
|
||||||
@ -452,7 +459,7 @@ int DB_rewrite(int handle)
|
|||||||
{
|
{
|
||||||
while ((rt = d4flush(dbdata[handle])) == r4locked)
|
while ((rt = d4flush(dbdata[handle])) == r4locked)
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
message_box("Sono in attesa nella DB_add (d4append)");
|
yesnofatal_box("Sono in attesa nella DB_rewrite (d4flush)");
|
||||||
#else
|
#else
|
||||||
u4delay_sec();
|
u4delay_sec();
|
||||||
#endif
|
#endif
|
||||||
@ -460,7 +467,8 @@ int DB_rewrite(int handle)
|
|||||||
if (rt == e4unique)
|
if (rt == e4unique)
|
||||||
{
|
{
|
||||||
DB_get_error();
|
DB_get_error();
|
||||||
fatal_box("Errore : chiave duplicata nell' indice %d", dbdata[handle]->rec_num + 1);
|
fatal_box("Errore in DB_rewrite(): chiave duplicata nell' indice %d, file %s",
|
||||||
|
dbdata[handle]->rec_num + 1, dbdata[handle]->file.name);
|
||||||
}
|
}
|
||||||
rt=DB_unlock(handle);
|
rt=DB_unlock(handle);
|
||||||
return (rt);
|
return (rt);
|
||||||
@ -473,18 +481,23 @@ int DB_rewrite(int handle)
|
|||||||
int DB_add(int handle)
|
int DB_add(int handle)
|
||||||
{
|
{
|
||||||
int rt;
|
int rt;
|
||||||
|
int is_locked = 0;
|
||||||
DATA4 * data = dbdata[handle];
|
DATA4 * data = dbdata[handle];
|
||||||
|
|
||||||
if (data==0) return(-1);
|
if (data==0) return(-1);
|
||||||
while (file4lock(&data->file, L4LOCK_POS_OLD, 1L) == r4locked)
|
is_locked = DB_file_locked(handle);
|
||||||
|
if (is_locked == 0) /* Se non e' stato gia' bloccato in modo esclusivo */
|
||||||
|
{
|
||||||
|
while (file4lock(&data->file, L4LOCK_POS_OLD, 1L) == r4locked)
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
message_box("Sono in attesa nella DB_add");
|
yesnofatal_box("Sono in attesa nella DB_add");
|
||||||
#else
|
#else
|
||||||
u4delay_sec();
|
u4delay_sec();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
while ((rt = d4append_start(data,0)) == r4locked)
|
while ((rt = d4append_start(data,0)) == r4locked)
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
message_box("Sono in attesa nella DB_add (d4append_start)");
|
yesnofatal_box("Sono in attesa nella DB_add (d4append_start)");
|
||||||
#else
|
#else
|
||||||
u4delay_sec();
|
u4delay_sec();
|
||||||
#endif
|
#endif
|
||||||
@ -493,7 +506,7 @@ int DB_add(int handle)
|
|||||||
d4recall(data);
|
d4recall(data);
|
||||||
while ((rt = d4append(data)) == r4locked)
|
while ((rt = d4append(data)) == r4locked)
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
message_box("Sono in attesa nella DB_add (d4append)");
|
yesnofatal_box("Sono in attesa nella DB_add (d4append)");
|
||||||
#else
|
#else
|
||||||
u4delay_sec();
|
u4delay_sec();
|
||||||
#endif
|
#endif
|
||||||
@ -501,7 +514,8 @@ int DB_add(int handle)
|
|||||||
{
|
{
|
||||||
DB_get_error();
|
DB_get_error();
|
||||||
if (data->rec_num > 0)
|
if (data->rec_num > 0)
|
||||||
fatal_box("Errore : chiave duplicata nell' indice %d", data->rec_num + 1);
|
fatal_box("Errore in DB_add(): chiave duplicata nell' indice %d, file %s",
|
||||||
|
data->rec_num + 1, data->file.name);
|
||||||
else
|
else
|
||||||
rt = _isreinsert;
|
rt = _isreinsert;
|
||||||
}
|
}
|
||||||
@ -510,14 +524,17 @@ int DB_add(int handle)
|
|||||||
{
|
{
|
||||||
while ((rt = d4flush(data)) == r4locked)
|
while ((rt = d4flush(data)) == r4locked)
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
message_box("Sono in attesa nella DB_add (d4append)");
|
yesnofatal_box("Sono in attesa nella DB_add (d4flush)");
|
||||||
#else
|
#else
|
||||||
u4delay_sec();
|
u4delay_sec();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DB_unlock(handle);
|
DB_unlock(handle);
|
||||||
file4unlock(&data->file, L4LOCK_POS_OLD, 1L);
|
if (is_locked == 0)
|
||||||
|
{
|
||||||
|
file4unlock(&data->file, L4LOCK_POS_OLD, 1L);
|
||||||
|
}
|
||||||
return(rt);
|
return(rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -721,8 +738,8 @@ int DB_packindex(short vis, const char * filename, RecDes *r, long *peod)
|
|||||||
progind_create((long)r->NKeys,s,1,1,1);
|
progind_create((long)r->NKeys,s,1,1,1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (ff == NULL || *ff == NULL)
|
if ((ff == NULL) || *ff == '\0')
|
||||||
ff = filename;
|
ff = (char *)filename;
|
||||||
else
|
else
|
||||||
ff++;
|
ff++;
|
||||||
do_key(ff,r,tags);
|
do_key(ff,r,tags);
|
||||||
@ -824,7 +841,7 @@ int DB_build(const char * filename, RecDes *r)
|
|||||||
field_info[i].len=0;
|
field_info[i].len=0;
|
||||||
field_info[i].dec=0;
|
field_info[i].dec=0;
|
||||||
|
|
||||||
if (ff == NULL || *ff == NULL)
|
if (ff == NULL || *ff == '\0')
|
||||||
ff = (char *) filename;
|
ff = (char *) filename;
|
||||||
else
|
else
|
||||||
ff++;
|
ff++;
|
||||||
@ -971,18 +988,20 @@ int DB_lock_rec(int handle,long nrec)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
Ritorna vero se il file e' bloccato in modo exclusive
|
Ritorna vero(non zero) se il file dati od indice sono stati bloccati
|
||||||
|
in modo esclusivo dalla presente applicazione, non da altri programmi!!!
|
||||||
--------------------------------------------------------------------------*/
|
--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
int DB_file_locked(int handle)
|
int DB_file_locked(int handle)
|
||||||
{
|
{
|
||||||
if(dbdata[handle]==0) return(-1);
|
if(dbdata[handle]==0) return(-1);
|
||||||
return(d4lock_test_file(dbdata[handle]));
|
return(d4lock_test_file(dbdata[handle]) + d4lock_test_index(dbdata[handle]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
Ritorna vero se il record nrec e' bloccato
|
Ritorna vero se il record nrec e' bloccato dalla presente applicazione,
|
||||||
|
non da altri programmi!!!
|
||||||
--------------------------------------------------------------------------*/
|
--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
int DB_rec_locked(int handle,long nrec)
|
int DB_rec_locked(int handle,long nrec)
|
||||||
|
@ -38,7 +38,6 @@ extern "C" {
|
|||||||
int DB_prev(int handle);
|
int DB_prev(int handle);
|
||||||
int DB_skip(int handle,long int recno);
|
int DB_skip(int handle,long int recno);
|
||||||
int DB_lock(int handle);
|
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_unlock(int handle);
|
||||||
int DB_seek(int handle,char *key);
|
int DB_seek(int handle,char *key);
|
||||||
int DB_eof(int handle);
|
int DB_eof(int handle);
|
||||||
@ -50,7 +49,7 @@ extern "C" {
|
|||||||
int DB_flush(int handle);
|
int DB_flush(int handle);
|
||||||
int DB_rewrite(int handle);
|
int DB_rewrite(int handle);
|
||||||
int DB_add(int handle);
|
int DB_add(int handle);
|
||||||
int DB_lockfile(int handle); // Per sbloccare il file basta la DB_unlock()
|
int DB_lockfile(int handle); /* Per sbloccare il record basta la DB_unlock()*/
|
||||||
int DB_packfile(short vis, const char * filename, long eod);
|
int DB_packfile(short vis, const char * filename, long eod);
|
||||||
int DB_packindex(short vis, const char * filename, RecDes *r, long *peod );
|
int DB_packindex(short vis, const char * filename, RecDes *r, long *peod );
|
||||||
int DB_build(const char * filename, RecDes *r);
|
int DB_build(const char * filename, RecDes *r);
|
||||||
@ -65,7 +64,7 @@ extern "C" {
|
|||||||
int DB_file_locked(int handle);
|
int DB_file_locked(int handle);
|
||||||
int DB_rec_locked(int handle,long nrec);
|
int DB_rec_locked(int handle,long nrec);
|
||||||
long DB_getconf();
|
long DB_getconf();
|
||||||
long DB_changed(int handle); // returns true if the index of the key is changed
|
long DB_changed(int handle); /* returns true if the index of the key is changed */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user