MariaDb how use locate for a date SOLVED

Post Reply
User avatar
Maurizio
Posts: 826
Joined: Mon Oct 10, 2005 1:29 pm
Contact:

MariaDb how use locate for a date SOLVED

Post 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
Last edited by Maurizio on Mon Oct 21, 2024 1:01 pm, edited 1 time in total.
User avatar
vilian
Posts: 984
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil
Contact:

Re: MariaDb how use locate for a date

Post 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)
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
Maurizio
Posts: 826
Joined: Mon Oct 10, 2005 1:29 pm
Contact:

Re: MariaDb how use locate for a date

Post by Maurizio »

Thanks Vilian
it works correctly :D
Maurizio
User avatar
nageswaragunupudi
Posts: 10691
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: MariaDb how use locate for a date SOLVED

Post 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 } )
Regards

G. N. Rao.
Hyderabad, India
User avatar
Maurizio
Posts: 826
Joined: Mon Oct 10, 2005 1:29 pm
Contact:

Re: MariaDb how use locate for a date SOLVED

Post 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
User avatar
nageswaragunupudi
Posts: 10691
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: MariaDb how use locate for a date SOLVED

Post 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 } )
Regards

G. N. Rao.
Hyderabad, India
Post Reply