Corretto errore in rete
git-svn-id: svn://10.65.10.50/trunk@1608 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
c0c868a2ae
commit
8f48962566
105
include/codeb.c
105
include/codeb.c
@ -87,6 +87,7 @@ void DB_init(void)
|
||||
code_base.default_unique_error=e4unique;
|
||||
code_base.safety=0;
|
||||
code_base.lock_attempts=1;
|
||||
// code_base.optimize_write = 0;
|
||||
u4ncpy(code_base.date_format,"CCYYMMDD",sizeof(code_base.date_format));
|
||||
|
||||
}
|
||||
@ -414,11 +415,26 @@ int DB_delkey(int handle, char* key, long recno)
|
||||
#endif
|
||||
if (rt == 0)
|
||||
rt=t4remove_calc(t,recno);
|
||||
d4flush(dbdata[handle]);
|
||||
i4unlock(i);
|
||||
return(rt);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
cancella dall'indice corrente la chiave specificata
|
||||
--------------------------------------------------------------------------*/
|
||||
int DB_flush(int handle)
|
||||
{
|
||||
int rt;
|
||||
|
||||
while ((rt = d4flush(dbdata[handle])) == r4locked)
|
||||
#ifdef DBG
|
||||
message_box("Sono in attesa nella DB_add (d4append)");
|
||||
#else
|
||||
u4delay_sec();
|
||||
#endif
|
||||
return rt;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
riscrive il record attuale
|
||||
--------------------------------------------------------------------------*/
|
||||
@ -432,13 +448,21 @@ int DB_rewrite(int handle)
|
||||
#else
|
||||
u4delay_sec();
|
||||
#endif
|
||||
d4flush(dbdata[handle]);
|
||||
rt=DB_unlock(handle);
|
||||
if (rt == 0)
|
||||
{
|
||||
while ((rt = d4flush(dbdata[handle])) == r4locked)
|
||||
#ifdef DBG
|
||||
message_box("Sono in attesa nella DB_add (d4append)");
|
||||
#else
|
||||
u4delay_sec();
|
||||
#endif
|
||||
}
|
||||
if (rt == e4unique)
|
||||
{
|
||||
DB_get_error();
|
||||
fatal_box("Errore : chiave duplicata nell' indice ");
|
||||
fatal_box("Errore : chiave duplicata nell' indice %d", dbdata[handle]->rec_num + 1);
|
||||
}
|
||||
rt=DB_unlock(handle);
|
||||
return (rt);
|
||||
}
|
||||
|
||||
@ -448,11 +472,16 @@ int DB_rewrite(int handle)
|
||||
--------------------------------------------------------------------------*/
|
||||
int DB_add(int handle)
|
||||
{
|
||||
int rt,ntag=1;
|
||||
int rt;
|
||||
DATA4 * data = dbdata[handle];
|
||||
TAG4* tag_on;
|
||||
|
||||
if (data==0) return(-1);
|
||||
/*
|
||||
while (file4lock(&data->file, L4LOCK_POS_OLD, 1L) == r4locked)
|
||||
#ifdef DBG
|
||||
message_box("Sono in attesa nella DB_add");
|
||||
#else
|
||||
u4delay_sec();
|
||||
#endif
|
||||
while ((rt = d4append_start(data,0)) == r4locked)
|
||||
#ifdef DBG
|
||||
message_box("Sono in attesa nella DB_add (d4append_start)");
|
||||
@ -468,7 +497,6 @@ int DB_add(int handle)
|
||||
#else
|
||||
u4delay_sec();
|
||||
#endif
|
||||
}
|
||||
if (rt == e4unique)
|
||||
{
|
||||
DB_get_error();
|
||||
@ -477,58 +505,19 @@ int DB_add(int handle)
|
||||
else
|
||||
rt = _isreinsert;
|
||||
}
|
||||
d4flush(data);
|
||||
DB_unlock(handle);
|
||||
*/
|
||||
while ((rt = d4lock_append(data)) == r4locked)
|
||||
#ifdef DBG
|
||||
message_box("Sono in attesa nella DB_add (d4lock_append)");
|
||||
#else
|
||||
u4delay_sec();
|
||||
#endif
|
||||
if ((rt=d4append_data(data)) == 0)
|
||||
{
|
||||
while ((rt = d4lock_index(data)) == r4locked)
|
||||
#ifdef DBG
|
||||
message_box("Sono in attesa nella DB_add (d4lock_index)");
|
||||
#else
|
||||
u4delay_sec();
|
||||
#endif
|
||||
/* Ora aggiunge le chiavi */
|
||||
for( tag_on = 0;rt == 0;ntag++ )
|
||||
{
|
||||
tag_on = d4tag_next( data, tag_on ) ;
|
||||
if ( !tag_on )
|
||||
break ;
|
||||
|
||||
rt = t4add_calc( tag_on, data->rec_num ) ;
|
||||
if ( rt < 0 || rt == r4unique )
|
||||
{
|
||||
/* Remove the keys which were just added */
|
||||
for(;;)
|
||||
{
|
||||
tag_on = d4tag_prev( data, tag_on ) ;
|
||||
if ( !tag_on )
|
||||
break ;
|
||||
t4remove_calc( tag_on, data->rec_num ) ;
|
||||
}
|
||||
d4blank(data);
|
||||
d4delete(data);
|
||||
d4write_data(data,d4recno(data));
|
||||
data->rec_num = 0;
|
||||
if (rt == r4unique || rt == e4unique)
|
||||
{
|
||||
code_base.error_code = 0;
|
||||
if (ntag == 1)
|
||||
rt = _isreinsert;
|
||||
else
|
||||
fatal_box("Errore : chiave duplicata nell' indice %d", ntag);
|
||||
if (rt == 0)
|
||||
{
|
||||
while ((rt = d4flush(data)) == r4locked)
|
||||
#ifdef DBG
|
||||
message_box("Sono in attesa nella DB_add (d4append)");
|
||||
#else
|
||||
u4delay_sec();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!rt ) d4update_header(data, 1, 1);
|
||||
d4unlock(data);
|
||||
DB_unlock(handle);
|
||||
file4unlock(&data->file, L4LOCK_POS_OLD, 1L);
|
||||
return(rt);
|
||||
}
|
||||
|
||||
@ -541,7 +530,7 @@ int DB_lockfile(int handle)
|
||||
|
||||
if(dbdata[handle]==0) return(-1);
|
||||
rt = d4lock_file(dbdata[handle]);
|
||||
if (rt==0) rt=d4lock_index(dbdata[handle]);
|
||||
if (rt>=0) rt=d4lock_index(dbdata[handle]);
|
||||
return(rt);
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,7 @@ extern "C" {
|
||||
int DB_delete(int handle);
|
||||
int DB_recall(int handle);
|
||||
int DB_delkey(int handle, char* key, long recno);
|
||||
int DB_flush(int handle);
|
||||
int DB_rewrite(int handle);
|
||||
int DB_add(int handle);
|
||||
int DB_lockfile(int handle); // Per sbloccare il file basta la DB_unlock()
|
||||
|
Loading…
x
Reference in New Issue
Block a user