Riscritta la DB_add.
git-svn-id: svn://10.65.10.50/trunk@1585 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
7f7af8474e
commit
3fca3f4587
@ -414,6 +414,7 @@ int DB_delkey(int handle, char* key, long recno)
|
|||||||
#endif
|
#endif
|
||||||
if (rt == 0)
|
if (rt == 0)
|
||||||
rt=t4remove_calc(t,recno);
|
rt=t4remove_calc(t,recno);
|
||||||
|
d4flush(dbdata[handle]);
|
||||||
i4unlock(i);
|
i4unlock(i);
|
||||||
return(rt);
|
return(rt);
|
||||||
}
|
}
|
||||||
@ -431,11 +432,12 @@ int DB_rewrite(int handle)
|
|||||||
#else
|
#else
|
||||||
u4delay_sec();
|
u4delay_sec();
|
||||||
#endif
|
#endif
|
||||||
|
d4flush(dbdata[handle]);
|
||||||
rt=DB_unlock(handle);
|
rt=DB_unlock(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 : chiave duplicata nell' indice ");
|
||||||
}
|
}
|
||||||
return (rt);
|
return (rt);
|
||||||
}
|
}
|
||||||
@ -446,35 +448,87 @@ int DB_rewrite(int handle)
|
|||||||
--------------------------------------------------------------------------*/
|
--------------------------------------------------------------------------*/
|
||||||
int DB_add(int handle)
|
int DB_add(int handle)
|
||||||
{
|
{
|
||||||
int rt;
|
int rt,ntag=1;
|
||||||
DATA4 * data = dbdata[handle];
|
DATA4 * data = dbdata[handle];
|
||||||
|
TAG4* tag_on;
|
||||||
if(data==0) return(-1);
|
if(data==0) return(-1);
|
||||||
while ((rt = d4append_start(data,0)) == r4locked)
|
/*
|
||||||
|
while ((rt = d4append_start(data,0)) == r4locked)
|
||||||
|
#ifdef DBG
|
||||||
|
message_box("Sono in attesa nella DB_add (d4append_start)");
|
||||||
|
#else
|
||||||
|
u4delay_sec();
|
||||||
|
#endif
|
||||||
|
if (rt == 0)
|
||||||
|
{
|
||||||
|
d4recall(data);
|
||||||
|
while ((rt = d4append(data)) == r4locked)
|
||||||
|
#ifdef DBG
|
||||||
|
message_box("Sono in attesa nella DB_add (d4append)");
|
||||||
|
#else
|
||||||
|
u4delay_sec();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (rt == e4unique)
|
||||||
|
{
|
||||||
|
DB_get_error();
|
||||||
|
if (data->rec_num > 0)
|
||||||
|
fatal_box("Errore : chiave duplicata nell' indice %d", data->rec_num + 1);
|
||||||
|
else
|
||||||
|
rt = _isreinsert;
|
||||||
|
}
|
||||||
|
d4flush(data);
|
||||||
|
DB_unlock(handle);
|
||||||
|
*/
|
||||||
|
while ((rt = d4lock_append(data)) == r4locked)
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
message_box("Sono in attesa nella DB_add (d4append_start)");
|
message_box("Sono in attesa nella DB_add (d4lock_append)");
|
||||||
#else
|
#else
|
||||||
u4delay_sec();
|
u4delay_sec();
|
||||||
#endif
|
#endif
|
||||||
if (rt == 0)
|
if ((rt=d4append_data(data)) == 0)
|
||||||
{
|
{
|
||||||
d4recall(data);
|
while ((rt = d4lock_index(data)) == r4locked)
|
||||||
while ((rt = d4append(data)) == r4locked)
|
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
message_box("Sono in attesa nella DB_add (d4append)");
|
message_box("Sono in attesa nella DB_add (d4lock_index)");
|
||||||
#else
|
#else
|
||||||
u4delay_sec();
|
u4delay_sec();
|
||||||
#endif
|
#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 == e4unique)
|
if (!rt ) d4update_header(data, 1, 1);
|
||||||
{
|
d4unlock(data);
|
||||||
DB_get_error();
|
|
||||||
if (data->rec_num > 0)
|
|
||||||
fatal_box("Errore : chiave duplicata nell' indice %d", data->rec_num + 1);
|
|
||||||
else
|
|
||||||
rt = _isreinsert;
|
|
||||||
}
|
|
||||||
DB_unlock(handle);
|
|
||||||
return(rt);
|
return(rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user