Skip to content

Commit

Permalink
Merge SVN 5286
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeclerck committed Feb 16, 2025
1 parent cf69dfd commit ff2962a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
13 changes: 13 additions & 0 deletions libcob/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@
* fileio.c (apply_file_paths): extracted from cob_chk_file_mapping
to factor out duplicated code

2024-05-30 Chuck Haatvedt <[email protected]>

fix errors in fileio.c when building with VISAM 2.2. This issue
occurred when using a partial key with a sequential read previous.

* fileio.c (indexed_start_internal, indexed_start, indexed_read_next)->fisam.c:
added a new field, partial_key_length,
to the indexfile structure for use in these functions.
This will allow the saved partial key to be used in the
positioning logic.
Also the BDB logic was changed to return a status code of "35"
when encountering a missing directory for OUTPUT on INDEXED file.

2024-05-23 Simon Sobisch <[email protected]>

* fisam.c (isam_read_next): use ISSTAT only for COB_WITH_STATUS_02,
Expand Down
3 changes: 2 additions & 1 deletion libcob/fbdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1463,13 +1463,14 @@ ix_bdb_open (cob_file_api *a, cob_file *f, char *filename, const enum cob_open_m
case DB_LOCK_NOTGRANTED:
return COB_STATUS_61_FILE_SHARING;
case ENOENT:
case ENOTDIR:
if (mode == COB_OPEN_EXTEND
|| mode == COB_OPEN_OUTPUT) {
return COB_STATUS_35_NOT_EXISTS;
}
if (f->flag_optional) {
if (mode == COB_OPEN_I_O) {
return COB_STATUS_30_PERMANENT_ERROR;
return COB_STATUS_35_NOT_EXISTS;
}
f->open_mode = (enum cob_open_mode)mode;
f->flag_nonexistent = 1;
Expand Down
37 changes: 28 additions & 9 deletions libcob/fisam.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ struct indexfile {
int readdone; /* A 'read' has been successfully done */
int startiscur; /* The 'start' record is current */
int wrkhasrec; /* 'recwrk' holds the next|prev record */
int partial_key_length; /* new field for partial key on START verb */
unsigned char idxmap[MAXNUMKEYS];
struct keydesc key[1]; /* Table of key information */
/* keydesc is defined in (d|c|vb)isam.h */
Expand Down Expand Up @@ -1318,6 +1319,24 @@ isam_start (cob_file_api *a, cob_file *f, const int cond, cob_field *key)
return COB_STATUS_23_KEY_NOT_EXISTS;
}
k = cob_findkey_attr (f, key, &fullkeylen, &partlen);

/************************************************************/
/* */
/* here we are storing the partial key length in the */
/* indexfile structure so that the indexed read next */
/* functions can position the file based on the partial */
/* key length. */
/* */
/* note the indexed_cmpkey function expects a partial key */
/* length of zero if it is to use the full key length. */
/* */
/************************************************************/

if (fullkeylen == partlen)
fh->partial_key_length = 0;
else
fh->partial_key_length = partlen;

if (k < 0) {
fh->startfail = 1;
return COB_STATUS_23_KEY_NOT_EXISTS;
Expand Down Expand Up @@ -1572,7 +1591,7 @@ isam_read_next (cob_file_api *a, cob_file *f, const int read_opts)
case COB_GE:
domoveback = 0;
while (ISERRNO == 0
&& indexed_cmpkey (fh, f->record->data, f->curkey, 0) == 0) {
&& indexed_cmpkey (fh, f->record->data, f->curkey, fh->partial_key_length) == 0) {
isread (fh->isfd, (void *)f->record->data, ISPREV);
domoveback = 1;
}
Expand All @@ -1583,7 +1602,7 @@ isam_read_next (cob_file_api *a, cob_file *f, const int read_opts)
case COB_LE:
domoveback = 0;
while (ISERRNO == 0
&& indexed_cmpkey (fh, f->record->data, f->curkey, 0) == 0) {
&& indexed_cmpkey (fh, f->record->data, f->curkey, fh->partial_key_length) == 0) {
isread (fh->isfd, (void *)f->record->data, ISNEXT);
domoveback = 1;
}
Expand All @@ -1593,13 +1612,13 @@ isam_read_next (cob_file_api *a, cob_file *f, const int read_opts)
break;
case COB_LT:
while (ISERRNO == 0
&& indexed_cmpkey (fh, f->record->data, f->curkey, 0) >= 0) {
&& indexed_cmpkey (fh, f->record->data, f->curkey, fh->partial_key_length) >= 0) {
isread (fh->isfd, (void *)f->record->data, ISPREV);
}
break;
case COB_GT:
while (ISERRNO == 0
&& indexed_cmpkey (fh, f->record->data, f->curkey, 0) <= 0) {
&& indexed_cmpkey (fh, f->record->data, f->curkey, fh->partial_key_length) <= 0) {
isread (fh->isfd, (void *)f->record->data, ISNEXT);
}
break;
Expand Down Expand Up @@ -1657,12 +1676,12 @@ isam_read_next (cob_file_api *a, cob_file *f, const int read_opts)
} else {
switch (fh->startcond) {
case COB_LE:
if (indexed_cmpkey (fh, f->record->data, f->curkey, 0) > 0)
if (indexed_cmpkey (fh, f->record->data, f->curkey, fh->partial_key_length) > 0)
domoveback = 1;
else
domoveback = 0;
while (ISERRNO == 0
&& indexed_cmpkey (fh, f->record->data, f->curkey, 0) == 0) {
&& indexed_cmpkey (fh, f->record->data, f->curkey, fh->partial_key_length) == 0) {
isread (fh->isfd, (void *)f->record->data, ISNEXT);
domoveback = 1;
}
Expand All @@ -1679,20 +1698,20 @@ isam_read_next (cob_file_api *a, cob_file *f, const int read_opts)
break;
}
while (ISERRNO == 0
&& indexed_cmpkey (fh, f->record->data, f->curkey, 0) >= 0) {
&& indexed_cmpkey (fh, f->record->data, f->curkey, fh->partial_key_length) >= 0) {
isread (fh->isfd, (void *)f->record->data, ISPREV);
skip_read = ISPREV;
}
break;
case COB_GT:
while (ISERRNO == 0
&& indexed_cmpkey (fh, f->record->data, f->curkey, 0) <= 0) {
&& indexed_cmpkey (fh, f->record->data, f->curkey, fh->partial_key_length) <= 0) {
isread (fh->isfd, (void *)f->record->data, ISNEXT);
}
break;
case COB_GE:
while (ISERRNO == 0
&& indexed_cmpkey (fh, f->record->data, f->curkey, 0) < 0) {
&& indexed_cmpkey (fh, f->record->data, f->curkey, fh->partial_key_length) < 0) {
isread (fh->isfd, (void *)f->record->data, ISNEXT);
}
break;
Expand Down

0 comments on commit ff2962a

Please sign in to comment.