diff --git a/include/codeb.c b/include/codeb.c index 3bedc638b..beb01b7ee 100755 --- a/include/codeb.c +++ b/include/codeb.c @@ -314,9 +314,23 @@ int DB_unlock(int handle) successivo, se torna r4eof e' su eof --------------------------------------------------------------------------*/ int DB_seek(int handle,char *key) -{ +{ + int rc; + TAG4 * tt; + if(dbdata[handle]==0) return(-1); - return(x4seek(&xdb[handle],key)); + rc = x4seek(&xdb[handle],key); + if (rc) + return rc; + tt = d4tag_selected(dbdata[handle]); + rc = strncmp(key, t4key(tt), expr4key_len(tt->expr)); + if (rc == 0) + return 0; + else + if (rc < 0) + return r4after; + else + return r4eof; } /*------------------------------------------------------------------------- @@ -400,8 +414,12 @@ int DB_delkey(int handle, char* key, long recno) --------------------------------------------------------------------------*/ int DB_rewrite(int handle) { + int rt; if(dbdata[handle]==0) return(-1); - return(d4write(dbdata[handle],d4recno(dbdata[handle]))); + rt=d4write(dbdata[handle],d4recno(dbdata[handle])); + if (rt!=r4success) + rt=DB_unlock(handle); + return (rt); }