FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TMysql Seek not working
Posts: 34
Joined: Wed Jun 17, 2009 05:52 PM
TMysql Seek not working
Posted: Thu Dec 06, 2012 07:14 PM

I am using tmysql and trying to seek a value:

oFasmast := oServer:Query( 'Select id, Account from fasmast order by id' )
oFasmast:seek( 20 )

It doesn't return any value nor does the record is positioned to the required record. The record with this id value exists.

I also tried (but no results):
oFasmast:seek( 20, .F., 'id' )

Gagan Raj
GTalk: csplsurat@gmail.com
WhatsApp: +91 9879000301
Posts: 474
Joined: Sun Oct 30, 2005 06:37 AM
Re: TMysql Seek not working
Posted: Fri Dec 07, 2012 01:40 AM

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.c
METHOD 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)==&quot;C&quot;
        ::GoBottom()
        if left(if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames)),len(Xvalue0))==Xvalue0
             ::lfound:=.t.
             return ::lfound
         else
             ::GoTop()                    
        end
    end

   while .t.                                            
     nStart:=1                                          
     nEnd:=::lastrec()                                  
     while nEnd-nStart&gt;1                                
         ::GoTo( nStart+int( (nEnd-nStart)/2))  
       if ctype&lt;&gt;&quot;C&quot;          
         Do Case                                        
            case  if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)&lt;xValue                   
                  nend := ::nCurRow                     
            case  if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)==xValue                  
                ::lFound := .t.                         
                  exit                                  
            case  if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)&gt;xValue                   
                  nStart := ::nCurRow                   
         endcase 
         else
            Do Case                                        
            case  if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames))&lt;xValue                   
                  nend := ::nCurRow                     
            case  if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames))==xValue                  
                ::lFound := .t.                         
                  exit                                  
            case  if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames))&gt;xValue                   
                  nStart := ::nCurRow                   
         endcase 
        endif                                      
     enddo

    if ::lFound; exit; end                             
     ::GoTo(nStart)                                     
    if  if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)==xValue ; ::lfound :=.t.; exit; end
    if  ctype==&quot;C&quot;
       if left(if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames)),len(Xvalue0))==Xvalue0; ::lfound:=.t.; exit; end
    end   
     ::GoTo(nEnd)                                       
    if  if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)==xValue ; ::lfound :=.t.; exit; end
    if  ctype==&quot;C&quot;
       if left(if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames)),len(Xvalue0))==Xvalue0; ::lfound:=.t.; exit; end
    end                                                       
     exit                                               
   enddo

     if !::lFound.and.!lSoftseek; ::GoBottom(); end     
     if ::lfound.and.llast                              
         while nEnd-nStart&gt;1                            
             ::GoTo( nStart+int( (nEnd-nStart)/2)) 
             if ctype&lt;&gt;&quot;C&quot;    
                if  if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)&lt;xValue                    
                 nend := ::nCurRow                      
                else                                      
                 // if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames))==xValue                
                 nStart := ::nCurRow                    
                end       
             else
                 if  if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames))&lt;xValue                    
                 nend := ::nCurRow                      
                else                                      
                 // if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames))==xValue                
                 nStart := ::nCurRow                    
                end    
             endif                                 
         enddo                                          
         ::GoTo(nEnd)   
         if ctype&lt;&gt;&quot;C&quot;                                
            if if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)&lt;xValue; ::GoTo(nStart); end    
           else
            if if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames))&lt;xValue; ::GoTo(nStart); end    
          endif   
     end

else

    if  ctype==&quot;C&quot;
        if left(if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(cvaltochar(EVAL(cfieldnames))),UPPER(cvaltochar(&amp;cFieldNames))),len(Xvalue0))==Xvalue0
              ::lfound:=.t.
              return  ::lFound
        end      
    end

    if  if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)&gt;xValue                            
        if !lSoftseek                                   
           ::GoBottom()                                 
        end                                           
        return  ::lFound                                
    end



   while .t.                                            
     nStart:=1                                          
     nEnd:=::lastrec()                                  
     while nEnd-nStart&gt;1                                
         ::GoTo( nStart+int( (nEnd-nStart)/2))   
       if ctype&lt;&gt;&quot;C&quot;        
         Do Case                                        
            case  if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)&gt;xValue                   
                  nend := ::nCurRow                     
            case  if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)==xValue                  
                ::lFound := .t.                         
                  exit                                  
            case  if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)&lt;xValue                   
                  nStart := ::nCurRow                   
         endcase 
          else
            Do Case                                        
            case  if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames))&gt;xValue                   
                  nend := ::nCurRow                     
            case  if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames))==xValue                  
                ::lFound := .t.                         
                  exit                                  
            case  if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames))&lt;xValue                   
                  nStart := ::nCurRow                   
         endcase 
       endif                                          
     enddo

    if ::lFound; exit; end                             
     ::GoTo(nStart)                                     
    if  if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)==xValue ; ::lfound :=.t.; exit; end
    if  ctype==&quot;C&quot;
        if left(if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames)),len(Xvalue0))==Xvalue0; ::lfound:=.t.; exit; end
    end

     ::GoTo(nEnd)                                       
    if  if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)==xValue ; ::lfound :=.t.; exit; end
    if  ctype==&quot;C&quot;
       if left(if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames)),len(Xvalue0))==Xvalue0; ::lfound:=.t.; exit; end
    end                                                     
     exit                                               
   enddo

     if !::lFound.and.!lSoftseek; ::GoBottom(); end     
     if ::lfound.and.llast                              
         while nEnd-nStart&gt;1                            
             ::GoTo( nStart+int( (nEnd-nStart)/2))     
             if ctype&lt;&gt;&quot;C&quot; 
                 if  if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)&gt;xValue                    
                    nend := ::nCurRow                      
                 else                                      
                  // if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)==xValue                
                    nStart := ::nCurRow                    
                 end 
              else
                 if  if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames))&gt;xValue                    
                    nend := ::nCurRow                      
                 else                                      
                  // if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)==xValue                
                    nStart := ::nCurRow                    
                 end 
             endif                                           
         enddo                                          
         ::GoTo(nEnd)       
         if ctype&lt;&gt;&quot;C&quot;                            
            if if(VALTYPE(cfieldnames)==&quot;B&quot;,EVAL(cfieldnames),&amp;cFieldNames)&gt;xValue; ::GoTo(nStart); end    
         else
            if if(VALTYPE(cfieldnames)==&quot;B&quot;,UPPER(EVAL(cfieldnames)),UPPER(&amp;cFieldNames))&gt;xValue; ::GoTo(nStart); end

         end
     end

end

Return ::lFound

Regards!
Shuming Wang

http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651
Posts: 866
Joined: Tue Oct 16, 2007 08:57 AM
Re: TMysql Seek not working
Posted: Fri Dec 07, 2012 01:10 PM

Hi Wang

This tmysql.prg and mysql.c new version?

Best Regards,



Richard



Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 32bit

MySQL v8.0

Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 64bit
Posts: 474
Joined: Sun Oct 30, 2005 06:37 AM
Re: TMysql Seek not working
Posted: Sat Dec 08, 2012 03:10 AM

Richard,
Updated just now.

Regards!
Shuming Wang

http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651
Posts: 866
Joined: Tue Oct 16, 2007 08:57 AM
Re: TMysql Seek not working
Posted: Sun Dec 09, 2012 05:26 AM
ShumingWang wrote:Richard,
Updated just now.

Regards!
Shuming Wang

Thank you so much.
Best Regards,



Richard



Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 32bit

MySQL v8.0

Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 64bit

Continue the discussion