Subject Re: canOpen firing twice for DMD's query object + unexpected =/==
From Gaetano <gaetanodd@hotmail.com>
Date Fri, 18 Sep 2020 10:38:15 +1000
Newsgroups dbase.getting-started

Hi Andy,

Since the strings are exactly identical down to matching the case of the
letters (I used copy/paste), why would SET EXACT have an impact with
either of the operators?

The based CDM only instantiates the database and 2 functions, there is
no query object in that file.

** END HEADER -- do not remove this line
class BaseSO2devCDATAMODULE of DATAMODULE custom
    this.SO2ADO1 = new ADODATABASE(this)
    with (this.SO2ADO1)
       left = 19.0
       top = 135.0
       connectionstring = "my connectionstring"
       active = true
    endwith

set procedure to ADOapachefix.cc additive

//making this function available to add calculated fields for season and
// portions of eTimestamp

function calcField(cName,nLength)
        local oField
        oField = new field()
        ofield.fieldname := cName
        oField.length := nLength
        this.rowset.fields.add(oField)
        return
endclass



On 17/09/2020 20:01, Andy Taylor wrote:
> Gaetano,
>
> First Issue
>     Where "==" gives a different result to "=" I suspect that you have set Exact Off in your dBASE ini settings.
>
> Second Issue
>     I'm guessing here but as the onOpen event of a query fires whenever the active property changes I suspect that
>     the first time it fires is when the query is instantiated and the 2nd time is when the active property is set to true.
>     On other possibility is that as you base this query class on BaseSO2dev.cdm there may be code in there that
>     also calls the query onOpen event.
>
> Hope that helps,
> Andy
>
>> Hi all,
>>
>> I am trying to use a variable SQL statements depending on the value of
>> an_app-level variable in a DMD's canOpen event.
>>
>> The following code seems to do what I was aiming for, however, I
>> stumbled on some unexpected things along the way:
>>
>>
>> In the following code, if I change the "==" operator to "=" in the DO
>> CASE block, the first DO CASE clause evaluates to true (i.e. the code
>> sees _app.varSQL as being an empty string) and cSQL doesn't get updated
>> as I expected it to in the second CASE clause.
>>
>> I believe that the clause should not evaluate to true because
>> _app.cVarSQL is set to "getMissDaysDetails" and doesn't have any
>> trailing/inbetween/leading spaces. Any idea why the single "=" is not
>> working in that context?
>>
>> The second issue I found is that the message boxes I put in the code to
>> investigate the above issue fire twice while opening the DMD. They fire
>> once before the DMD window is even visible, and a second time while the
>> form is opening but before the query object and grid become visible.
>>
>> Could someone enlighten me on the reason that causes the event to fire
>> twice in this code?
>>
>> ** END HEADER -- do not remove this line
>> //
>> // Generated on 17/09/2020
>> //
>>
>> //the CDM file only sets the database object, adds a CC file and an
>> //addField function
>>
>> class SO2devDATAMODULE of BASESO2DEVCDATAMODULE from "BaseSO2dev.cdm"
>>      with (this.SO2ADO1)
>>         left = 26.0
>>         top = 43.0
>>         width = 115.0
>>         height = 112.0
>>      endwith
>>
>>      this.ENERGYDATA1 = new ADOQUERY(this)
>>      with (this.ENERGYDATA1)
>>         canOpen = class::ENERGYDATA1_CANOPEN
>>         left = 162.0
>>         top = 60.0
>>         width = 115.0
>>         height = 146.0
>>         database = form.so2ado1
>>         connected = true
>>         sql = "select * from energydata"
>>         active = true
>>      endwith
>>
>>      this.rowset = this.energydata1.rowset
>>
>>      function ENERGYDATA1_canOpen()
>>         //set app level SQL flag
>>         _app.cVarSQL="getMissDaysDetails"
>>         //msgbox("_appvar= "+len(_app.cVarSQL))
>>         
>>                 
>>        do case
>>          case _app.cVarSQL==""
>>              //leave SQL unchanged                                
>>          case _app.cVarSQL= "getMissDaysDetails"                                
>>            cSQL='SELECT count(distinct cast(eTimestamp as date)) as Days '
>>            cSQL+= 'from energydata order by Days'
>>          this.sql=cSQL
>>          endcase
>>         msgbox("cSQL = "+cSQL)
>>         return true
>>
>> endclass
>