FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour MariaDb how use locate for a date SOLVED
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM

MariaDb how use locate for a date SOLVED

Posted: Mon Oct 21, 2024 08:58 AM
Hello Rao ,
in a select when I search for a date I use
SELECT * FROM customer WHERE HIREDATE= " +DTOS(DATE())

How do I use the date search with locate?
I tried
cLocate := " HIREDATE = '" + DTOS(DATE()) + "'"

But I have this error

Error occurred at: 10/21/24, 10:57:32
Error description: Error BASE/1071 Argument error: =
Args:
[ 1] = D 09/18/92
[ 2] = C 20241021


Code (fw): Select all Collapse
#include "fivewin.ch"
#include "dbcombo.ch"

 

//----------------------------------------------------------------------------//

function Main()

   local oCn, oRs
   local oDlg, oBrw, cLocate := ''

   //FWNumFormat( "A", .t. )

   oCn   := FW_DemoDB()

   oCn:LockTimeOut   := 1
   oCn:lShowErrors   := .t.
    
   //oRs      := oCn:RowSet( "SELECT ID,FIRST,CITY,SALARY FROM customer" )
   oRs      := oCn:RowSet( "SELECT * FROM customer ")
   
   xbrowse(oRs)
   
   cLocate := " HIREDATE ='" + DTOS(DATE()) + "'"
   
   ? oRs:Locate(cLocate)
   
   xbrowse(oRs)
   

  
return nil
Maurizio
Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM

Re: MariaDb how use locate for a date

Posted: Mon Oct 21, 2024 11:04 AM
I'm not Rao, sorry :)
But oRs:Locate() must be used with a xbase expression. So, you should to do something like this:
Code (fw): Select all Collapse
    cLocate := " HIREDATE = CTOD( ' " + Dtoc(Date())+" ' ) "
   
   ? oRs:Locate(cLocate)
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM

Re: MariaDb how use locate for a date

Posted: Mon Oct 21, 2024 01:01 PM
Thanks Vilian
it works correctly :D
Maurizio
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: MariaDb how use locate for a date SOLVED

Posted: Mon Oct 21, 2024 02:52 PM
As Mr. Vilian said, the expressions used for oRs.SetFilter and oRs:Locate should use DBF syntax.
Very same expressions you use for setting filters or locate for statements in DBF.

There is another method which helps you to make these expression easily for you.
Code (fw): Select all Collapse
? cLocate := oCn:ExprnDBF( "HIREDATE = ?", { DATE() } )
oRs:locate( cLocate )
Code (fw): Select all Collapse
? cFilter := oCn:ExprnDBF( "STATE = ? .AND. AGE >= ?", { "NY", 45 } )
Regards



G. N. Rao.

Hyderabad, India
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM

Re: MariaDb how use locate for a date SOLVED

Posted: Mon Oct 21, 2024 04:30 PM
Thanks RAO ,
Code (fw): Select all Collapse
? cLocate := oCn:ExprnDBF( "HIREDATE = ?", { DATE() } )
oRs:locate( cLocate )
This code works , where oCn is the connection and oRs is the recordset

but
Code (fw): Select all Collapse
? cFilter := oCn:ExprnDBF( "STATE = ? .AND. AGE >= ?", { "NY", 45 } )
where is the recordset ?

Maurizio
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: MariaDb how use locate for a date SOLVED

Posted: Mon Oct 21, 2024 07:08 PM
Code (fw): Select all Collapse
? cFilter := oCn:ExprnDBF( "STATE = ? .AND. AGE >= ?", { "NY", 45 } )
oRs:SetFilter( cFilter )
// OR
oRs:SetFilter( "STATE = ? .AND. AGE >= ?", { "NY", 45 } )
// and later
oRs:ReFilter( { "WA", 35 } )
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion