oquery:seek(20,.f.,{||oquery:id})
?id // 20
This is my tmysql.prg
www.xtech.com.cn/down/tmysql.prg,
www.xtech.com.cn/down/mysql.cMETHOD Seek( xValue,lSoftSeek,cFieldNames,llast) CLASS TMySQLQuery
local nstart,nend,nretry:=0,Xvalue0:=Xvalue,ctype:=VALTYPE(xValue)
default lSoftSeek to .t.
DEFAULT llast TO .f.
if ctype=="C"
if len(xValue)<LEN(cvaltochar(if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)))
xValue:=PADR(xValue,len(cvaltochar(if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)))," ")
end
xValue:=UPPER(xValue)
xValue0:=UPPER(xValue0)
end
::lFound := .f.
::GoTop()
if RIGHT(UPPER(RIGHT(::cquery,8)),4)=="DESC"
if if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)<xValue
if !lSoftseek
::GoBottom()
end
return ::lFound
end
if valtype(xValue)=="C"
::GoBottom()
if left(if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames)),len(Xvalue0))==Xvalue0
::lfound:=.t.
return ::lfound
else
::GoTop()
end
end
while .t.
nStart:=1
nEnd:=::lastrec()
while nEnd-nStart>1
::GoTo( nStart+int( (nEnd-nStart)/2))
if ctype<>"C"
Do Case
case if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)<xValue
nend := ::nCurRow
case if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)==xValue
::lFound := .t.
exit
case if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)>xValue
nStart := ::nCurRow
endcase
else
Do Case
case if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames))<xValue
nend := ::nCurRow
case if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames))==xValue
::lFound := .t.
exit
case if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames))>xValue
nStart := ::nCurRow
endcase
endif
enddo
if ::lFound; exit; end
::GoTo(nStart)
if if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)==xValue ; ::lfound :=.t.; exit; end
if ctype=="C"
if left(if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames)),len(Xvalue0))==Xvalue0; ::lfound:=.t.; exit; end
end
::GoTo(nEnd)
if if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)==xValue ; ::lfound :=.t.; exit; end
if ctype=="C"
if left(if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames)),len(Xvalue0))==Xvalue0; ::lfound:=.t.; exit; end
end
exit
enddo
if !::lFound.and.!lSoftseek; ::GoBottom(); end
if ::lfound.and.llast
while nEnd-nStart>1
::GoTo( nStart+int( (nEnd-nStart)/2))
if ctype<>"C"
if if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)<xValue
nend := ::nCurRow
else
// if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames))==xValue
nStart := ::nCurRow
end
else
if if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames))<xValue
nend := ::nCurRow
else
// if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames))==xValue
nStart := ::nCurRow
end
endif
enddo
::GoTo(nEnd)
if ctype<>"C"
if if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)<xValue; ::GoTo(nStart); end
else
if if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames))<xValue; ::GoTo(nStart); end
endif
end
else
if ctype=="C"
if left(if(VALTYPE(cfieldnames)=="B",UPPER(cvaltochar(EVAL(cfieldnames))),UPPER(cvaltochar(&cFieldNames))),len(Xvalue0))==Xvalue0
::lfound:=.t.
return ::lFound
end
end
if if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)>xValue
if !lSoftseek
::GoBottom()
end
return ::lFound
end
while .t.
nStart:=1
nEnd:=::lastrec()
while nEnd-nStart>1
::GoTo( nStart+int( (nEnd-nStart)/2))
if ctype<>"C"
Do Case
case if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)>xValue
nend := ::nCurRow
case if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)==xValue
::lFound := .t.
exit
case if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)<xValue
nStart := ::nCurRow
endcase
else
Do Case
case if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames))>xValue
nend := ::nCurRow
case if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames))==xValue
::lFound := .t.
exit
case if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames))<xValue
nStart := ::nCurRow
endcase
endif
enddo
if ::lFound; exit; end
::GoTo(nStart)
if if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)==xValue ; ::lfound :=.t.; exit; end
if ctype=="C"
if left(if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames)),len(Xvalue0))==Xvalue0; ::lfound:=.t.; exit; end
end
::GoTo(nEnd)
if if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)==xValue ; ::lfound :=.t.; exit; end
if ctype=="C"
if left(if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames)),len(Xvalue0))==Xvalue0; ::lfound:=.t.; exit; end
end
exit
enddo
if !::lFound.and.!lSoftseek; ::GoBottom(); end
if ::lfound.and.llast
while nEnd-nStart>1
::GoTo( nStart+int( (nEnd-nStart)/2))
if ctype<>"C"
if if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)>xValue
nend := ::nCurRow
else
// if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)==xValue
nStart := ::nCurRow
end
else
if if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames))>xValue
nend := ::nCurRow
else
// if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)==xValue
nStart := ::nCurRow
end
endif
enddo
::GoTo(nEnd)
if ctype<>"C"
if if(VALTYPE(cfieldnames)=="B",EVAL(cfieldnames),&cFieldNames)>xValue; ::GoTo(nStart); end
else
if if(VALTYPE(cfieldnames)=="B",UPPER(EVAL(cfieldnames)),UPPER(&cFieldNames))>xValue; ::GoTo(nStart); end
end
end
end
Return ::lFound
Regards!
Shuming Wang