Thanks a lot, everyone!
I'm sure I tested it in the past. I also believe I have unit tests somewhere that test this specific case.
I just had an issue pop up that I couldn't logically draw a conclusion from.
I have a file that has 2 keys, none of them unique.
The only way it can delete entries is something like this:
Code: Select all
def library FnRemoveQueuedIncreases(RawObject$*64; ___, OldRec, QueueFile)
let FnEstablishLinkage
let QueueFile = FnOpen(`queue`, mat Queue$, mat Queue, mat Forms$)
do until ~(OldRec:=FnNextQueuedIncrease(RawObject$))
delete #QueueFile, rec=OldRec, release :
loop
let FnCloseFile(QueueFile, `queue`)
fnend
! returns the record number of the next queued increase for the current raw material
def library FnNextQueuedIncrease(Self$*64; ___, QueueFile, Key$*64)
let FnEstablishLinkage
let QueueFile = FnOpen(`queue`, mat Queue$, mat Queue, mat Forms$, 1, 2)
let Key$ = `M{{rpad$(FnGetAttr$(Self$, 'Raw Code'), 32)}}0`
read #QueueFile, using Forms$(QueueFile), key=Key$, release : mat Queue$, mat Queue nokey ignore
if ~file(QueueFile) then
let FnNextQueuedIncrease = rec(QueueFile)
else
let FnNextQueuedIncrease = 0
end if
close #QueueFile, release :
fnend
This all works fine.
And although this may look a little complex on the surface, all it's really doing is finding the next record number that matches a key(that may contain duplicates) and deleting that record number.
When I view it in the fileio datacrawler or just spit out record numbers manually, it all looks fine.
But when I start modifying the keys in this step:
Code: Select all
def library FnFinalizeDueRawIncreases(; ___, Now, rc, QueueFile)
let FnEstablishLinkage
let Now = days(date$)
mat UpdatedEntries(0)
let QueueFile = FnOpen(`queue`, mat Queue$, mat Queue, mat Forms$)
restore #QueueFile, search=>`M0` : nokey ignore
do until file(QueueFile)
read #QueueFile, using Forms$(QueueFile) : mat Queue$, mat Queue eof ignore
if ~file(QueueFile) then
if Queue$(qu_type) == `M` and ~Queue(qu_posted) and Queue(qu_date) <= Now then
! an unrelated function call where the raw price is updated
mat UpdatedEntries(udim(UpdatedEntries) + 1)
let UpdatedEntries(udim(UpdatedEntries)) = rec(QueueFile)
end if
end if
loop while Queue$(qu_type) == `M`
for rc = 1 to udim(UpdatedEntries)
read #QueueFile, using Forms$(QueueFile), rec=UpdatedEntries(rc) : mat Queue$, mat Queue
let Queue(qu_posted) = 1
rewrite #QueueFile, using Forms$(QueueFile) : mat Queue$, mat Queue
next rc
let FnCloseFile(QueueFile, `queue`)
fnend
Duplicate record numbers start popping up.
This is obviously a case of an invalid key file since duplicate record numbers just don't exist.
All that's getting modified on the file is qu_posted which is part of both keys.
Reindexing removes the duplicate entries so it's definitely a key issue.
I just thought I'd throw it out there in case I missed something obvious.