Web Connection
wwBusinessObject::Find() option to not override oData
Gravatar is a globally recognized avatar based on your email address. wwBusinessObject::Find() option to not override oData
  Mike McDonald
  All
  Feb 1, 2019 @ 10:52am

Rick -

The wwBusinessObject class contains a Find function, which always overrides the oData object. It would be good to have a parameter for Find which will cause it to not override oData, but still return the True or False result.

For example, when a new user is signing up, I want to validate that the email address they entered is not already in the system (which is easily determined using Find(), whether you have FoxPro or SQL data). However, during the validation process, this.oData could already contain information about the proposed new signup, so I don't want to override that data when looking for an existing email address.

- Mike McDonald

Gravatar is a globally recognized avatar based on your email address. re: wwBusinessObject::Find() option to not override oData
  Rick Strahl
  Mike McDonald
  Feb 1, 2019 @ 01:01pm

I don't think there's a big use case for this but I suppose it's easy enough to add without introducing more features.

So here's this:

************************************************************************
*  Find
****************************************
***  Function: Tries to find a record based on a filter string 
***            and sets the oData member. Only the first item found is
***            returned so you probably want to reserve this for known 
***            lookups of unique items.
***    Assume:
***      Pass: lcFilter       -  SQL Filter string (WHERE)
***            llNoDataMember -  if .T. doesn't set the .oData member
***    Return: .T. or .F. with oData set
************************************************************************
FUNCTION Find(lcFilter, llNoDataMember)
LOCAL lcCmd, lnResult

IF !THIS.OPEN()
    RETURN .F.
ENDIF

DO CASE
CASE THIS.ndatamode = 0
    lcCmd = "LOCATE FOR " + lcFilter
    &lcCmd

    IF FOUND()
        IF !llNoDataMember
	        SCATTER NAME THIS.odata MEMO
	        IF THIS.lcompareupdates
	            SCATTER NAME THIS.oorigdata MEMO
	        ENDIF
        ENDIF
        RETURN .T.
    ELSE
        IF !llNoDataMember
	        SCATTER NAME THIS.odata BLANK MEMO
	    ENDIF
    ENDIF
CASE THIS.ndatamode = 2
    THIS.osql.csqlcursor = "TSQLQuery"
    THIS.osql.csql = "select * from " + THIS.cfilename + " WHERE " + lcFilter
    *_cliptext = THIS.oSQL.cSQL
    lnResult = THIS.osql.execute()

    IF lnResult # 1
        THIS.SetError(THIS.osql.cerrormsg)
        RETURN .F.
    ENDIF
    IF RECCOUNT() > 0
        IF !llNoDataMember
	        SCATTER NAME THIS.odata MEMO
	        IF THIS.lcompareupdates
	            SCATTER NAME THIS.oorigdata MEMO
	        ENDIF
	    ENDIF
        RETURN .T.
    ELSE
		IF !llNoDataMember
	        SCATTER NAME THIS.odata BLANK MEMO
	    ENDIF
    ENDIF
ENDCASE

RETURN .F.
ENDFUNC
*   Find

+++ Rick ---

© 1996-2019