Adordd uses seek in the following way (also with relations).
It works just like dbfs any changes needed in app code. See the code
We will have another function adoseek(cKey) to build a recordset with the ckey expresssion as where clause
and adoseek() to revert to the previous recordset.
Its faster than the ado_seek() but you will need to insert these changes into your app code.
Code: Select all
STATIC FUNCTION ADO_SEEK( nWA, lSoftSeek, cKey, lFindLast )
LOCAL oRecordSet := USRRDD_AREADATA( nWA )[ WA_RECORDSET ]
LOCAL aWAData := USRRDD_AREADATA( nWA )
LOCAL aSeek,cSql,nRecno,oRs := TempRecordSet()
HB_SYMBOL_UNUSED( nWA )
HB_SYMBOL_UNUSED( lSoftSeek )
HB_SYMBOL_UNUSED( cKey )
HB_SYMBOL_UNUSED( lFindLast )
DEFAULT lFindLast TO .F.
DEFAULT lSoftSeek TO .F.
IF ADOEMPTYSET(oRecordSet)
aWAData[ WA_FOUND ] := ! oRecordSet:EOF
aWAData[ WA_EOF ] := oRecordSet:EOF
RETURN HB_SUCCESS
ENDIF
IF aWAData[WA_INDEXACTIVE] = 0
MSGALERT("No Index active seek not allowed!") //SHOULD RAISE ERROR
RETURN HB_FAILURE
ENDIF
aSeek := ADOPseudoSeek(nWA,cKey,aWAData,lSoftSeek)
//this tell us if we are in a subset of records from previous seek we need to reset to defaut to have another seek
IF aWAData[WA_ISITSUBSET] .AND. aSeek[3] //ONLY IF ITS FIND IF SEEK NEW RECORDSET WILL BE ALWAYS CREATED
oRecordSet:Close()
cSql := IndexBuildExp(nWA,aWAData[WA_INDEXACTIVE],aWAData)
oRecordSet:Open( cSql,aWAData[ WA_CONNECTION ] )
ENDIF
IF aSeek[3] //no more than one field in the expression we can use find
//eof control doesnt matter in seek that are really selects THATS WHY ITS HERE
//for finds lets place in row 1
IF oRecordSet:EOF .OR. oRecordSet:BOF .OR. aWAData[ WA_EOF ] .OR. aWAData[ WA_BOF ]
oRecordSet:MoveFirst()
aWAData[ WA_EOF ] := oRecordSet:EOF
aWAData[ WA_BOF ] := oRecordSet:BOF
ENDIF
IF lSoftSeek
oRecordSet:Find( aSeek[1]) //SEE PSEUDOSEEK
ELSE
IF lFindLast
oRecordSet:MoveLast()
oRecordSet:Find( aSeek[1],,adSearchBackward)
ELSE
oRecordSet:MoveFirst()
oRecordSet:Find( aSeek[1])
ENDIF
ENDIF
ELSE
//attention multiple fields in cseek expression cannot emulate behaviour of lSoftSeek
//more than one field in the seek expression has to be select
//MSGINFO(aSeek[2])
cSql := IndexBuildExp(nWA,aWAData[WA_INDEXACTIVE],aWAData,.F.,aSeek[2])
//MSGINFO(CSQL)
oRs:Open(cSql,aWAData[ WA_CONNECTION ] ) //new temp recordset
IF !ADOEMPTYSET(oRs) //FOUNDED!
IF lFindLast
oRS:MoveLast()
ENDIF
IF !EMPTY(aWAData[WA_FIELDRECNO]) // 100% SUPPORTED AND SAFE
nRecno := oRS:Fields(aWAData[WA_FIELDRECNO]):Value //field autoinc
ELSE
IF oRS:Supports(adBookmark)
/* Although the Supports method may return True for a given functionality, it does not guarantee that
the provider can make the feature available under all circumstances.
The Supports method simply returns whether the provider can support the specified functionality,
assuming certain conditions are met. For example, the Supports method may indicate that a
Recordset object supports updates even though the cursor is based on a multiple table join,
some columns of which are not updatable*/
IF oRS:Eof() .or. oRS:Bof()
nRecno := 0
ELSE
nRecno := oRS:BookMark
ENDIF
ELSE
//ATTENTION NOT WORKING CORRECTLY WITH DELETED ROWS!2
nRecno := IF( oRS:AbsolutePosition == adPosEOF, oRS:RecordCount() + 1, oRS:AbsolutePosition )
//MUST TAKE OUT THE DELETED ROWS! OTHERWISE WRONG NRECNO
//TODO nRecno := nRecno-nDeletedRows
ENDIF
ENDIF
ADO_GOTO(nWA,nRecno)
ELSE //NOT FOUND!
// lSoftSeek DONT KNOW HOWTO!
ENDIF
//TO CHECK NEXT CALLS IF WE ARE IN A SUBSSET TO REVERT TO DEFAULT SET
aWAData[WA_ISITSUBSET] := .F.
oRs:close()
ENDIF
aWAData[ WA_FOUND ] := ! oRecordSet:EOF
aWAData[ WA_EOF ] := oRecordSet:EOF
RETURN HB_SUCCESS