xsharp.eu • Is record in index ??
Page 1 of 1

Is record in index ??

Posted: Wed Feb 14, 2024 6:26 pm
by DanielFliff
How can I efficiently determine if a specific record exists in an index using XSharp? Are there any built-in functions or methods available for this purpose?

Re: Is record in index ??

Posted: Thu Feb 15, 2024 9:13 am
by Chris
Hi Daniel,

What do you mean by "index"?

Re: Is record in index ??

Posted: Thu Feb 15, 2024 10:04 am
by ecos
Hi Daniel, Chris,

see my post
https://www.xsharp.eu/forum/topic/3603

Karl

Re: Is record in index ??

Posted: Thu Feb 15, 2024 10:08 am
by ecos
BTW,

here is my solution which seems to work

METHOD IsRecordInOrder(nRecno,nOrder) // class MyDBServer inherit DBServer
LOCAL lOk AS LOGIC
LOCAL uTop AS USUAL
LOCAL uBottom AS USUAL
LOCAL uValue AS USUAL
LOCAL nOldRec AS DWORD
LOCAL nOldOrder AS DWORD

Default(@nRecno,0)
Default(@nOrder,0)

IF nRecno > 0
nOldRec := SELF:Recno
SELF:goto(nRecno)
ENDIF
IF nOrder > 0
nOldOrder := SELF:orderinfo(DBOI_NUMBER)
SELF:setorder(nOrder)
ENDIF

BEGIN SEQUENCE

// Index-Bedingung
IF SELF:orderinfo(DBOI_ISCOND)
IF !Evaluate(SELF:orderinfo(DBOI_CONDITION))
BREAK
ENDIF
ENDIF

// Scope
uTop := SELF:orderinfo(DBOI_SCOPETOP)
uBottom := SELF:orderinfo(DBOI_SCOPEBOTTOM)

IF !Empty(uTop) .OR. !Empty(uBottom)
uValue := SELF:Orderkeyval
IF SELF:Orderdescend()
IF !Empty(uTop)
IF uValue > uTop
BREAK
ENDIF
ENDIF
IF !Empty(uBottom)
IF uValue < uBottom
BREAK
ENDIF
ENDIF
ELSE
IF !Empty(uTop)
IF uValue < uTop
BREAK
ENDIF
ENDIF
IF !Empty(uBottom)
IF uValue > uBottom
BREAK
ENDIF
ENDIF
ENDIF
ENDIF

lOk := TRUE

END SEQUENCE

IF nOrder > 0
SELF:setorder(nOldOrder)
ENDIF
IF nRecno > 0
SELF:goto(nOldRec)
ENDIF

RETURN lOk

Re: Is record in index ??

Posted: Thu Feb 15, 2024 10:53 am
by FFF
Probably i miss the obvious - but why not doing a "Seek" in the order?

Re: Is record in index ??

Posted: Thu Feb 15, 2024 12:16 pm
by ecos
Karl,

because the indexkey might not be unique

Karl

Re: Is record in index ??

Posted: Thu Feb 15, 2024 4:31 pm
by Chris
Ah, I was missing the obvious, was working on some help advanced topics and was thinking about the record type in c# and index in an array :)