Page 1 of 1

MariaDb how use locate for a date SOLVED

Posted: Mon Oct 21, 2024 8:58 am
by Maurizio
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: Select all | Expand

#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

Re: MariaDb how use locate for a date

Posted: Mon Oct 21, 2024 11:04 am
by vilian
I'm not Rao, sorry :)
But oRs:Locate() must be used with a xbase expression. So, you should to do something like this:

Code: Select all | Expand

    cLocate := " HIREDATE = CTOD( ' " + Dtoc(Date())+" ' ) "
   
   ? oRs:Locate(cLocate)

Re: MariaDb how use locate for a date

Posted: Mon Oct 21, 2024 1:01 pm
by Maurizio
Thanks Vilian
it works correctly :D
Maurizio

Re: MariaDb how use locate for a date SOLVED

Posted: Mon Oct 21, 2024 2:52 pm
by nageswaragunupudi
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: Select all | Expand

? cLocate := oCn:ExprnDBF( "HIREDATE = ?", { DATE() } )
oRs:locate( cLocate )

Code: Select all | Expand

? cFilter := oCn:ExprnDBF( "STATE = ? .AND. AGE >= ?", { "NY", 45 } )

Re: MariaDb how use locate for a date SOLVED

Posted: Mon Oct 21, 2024 4:30 pm
by Maurizio
Thanks RAO ,

Code: Select all | Expand

? cLocate := oCn:ExprnDBF( "HIREDATE = ?", { DATE() } )
oRs:locate( cLocate )
This code works , where oCn is the connection and oRs is the recordset

but

Code: Select all | Expand

? cFilter := oCn:ExprnDBF( "STATE = ? .AND. AGE >= ?", { "NY", 45 } )
where is the recordset ?

Maurizio

Re: MariaDb how use locate for a date SOLVED

Posted: Mon Oct 21, 2024 7:08 pm
by nageswaragunupudi

Code: Select all | Expand

? 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 } )