MariaDb how use locate for a date SOLVED

MariaDb how use locate for a date SOLVED

Postby Maurizio » Mon Oct 21, 2024 8: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: Select all  Expand view
#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
Maurizio
 
Posts: 824
Joined: Mon Oct 10, 2005 1:29 pm

Re: MariaDb how use locate for a date

Postby vilian » 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: Select all  Expand view
   cLocate := " HIREDATE = CTOD( ' " + Dtoc(Date())+" ' ) "
   
   ? oRs:Locate(cLocate)
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 977
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: MariaDb how use locate for a date

Postby Maurizio » Mon Oct 21, 2024 1:01 pm

Thanks Vilian
it works correctly :D
Maurizio
User avatar
Maurizio
 
Posts: 824
Joined: Mon Oct 10, 2005 1:29 pm

Re: MariaDb how use locate for a date SOLVED

Postby nageswaragunupudi » Mon Oct 21, 2024 2: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: Select all  Expand view
? cLocate := oCn:ExprnDBF( "HIREDATE = ?", { DATE() } )
oRs:locate( cLocate )


Code: Select all  Expand view
? cFilter := oCn:ExprnDBF( "STATE = ? .AND. AGE >= ?", { "NY", 45 } )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: MariaDb how use locate for a date SOLVED

Postby Maurizio » Mon Oct 21, 2024 4:30 pm

Thanks RAO ,

Code: Select all  Expand view
? 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 view
? cFilter := oCn:ExprnDBF( "STATE = ? .AND. AGE >= ?", { "NY", 45 } )


where is the recordset ?

Maurizio
User avatar
Maurizio
 
Posts: 824
Joined: Mon Oct 10, 2005 1:29 pm

Re: MariaDb how use locate for a date SOLVED

Postby nageswaragunupudi » Mon Oct 21, 2024 7:08 pm

Code: Select all  Expand view
? 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
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 58 guests