Although it seems logical, this code won't really test for success or
failure of a immediate query.  The "SUCCESS" variable is equal to 0 and an
error code returned from getResultStatus().getErrorCode() is not always
equal to 0 when it is successful.  We mostly use executeImmediate to perform
table-lookup's using keys that should be on the database and flag an error
only if no results are returned.  For example:

            CSpValue valCustomer =
CSpider.getUserSessionObject("sesCUSTID");
            CSpValue valCustName = new CSpString("");
            try
            {
                CSpDBResult getCustName = CSpDataObject.executeImmediate
("dsSC2K",
                    "select customer_name"+
                    "  from customer"+
                    " where customer_id = '"+valCustomer.stringValue()+"'");
                CSpDBResultTable custTable = getCustName.getResultTable();
                if (custTable.getNumOfRows() > 0)
                    valCustName = custTable.getRowData(0, 0);
                else
                    valCustName = new CSpString("Customer Name not Found");
            }
            catch(Exception ex)
            {
                valCustName = new CSpString("Customer Name not Found");
            }

Jim Ierardi
OLC Software, Inc.

<[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
>
>
> Is the code snippet below the preferred way of chking for success of
> executeImmediate? Any tips for making it better?
>
> Also, out of curiosity, I tried to find CSpDataObject.SUCCESS mentioned in
the
> API to see if maybe there was a CSpDataObject.FAILURE in case I wanted to
> directly chk for failure instead. But I couldn't find any mention of a
variable
> called "SUCCESS" in the CSpDataObject class or its ancestors. Did I miss
it
> somehow? Where is it defined?
>
> Thanks,
> Janet
>
> try
> {
>      CSpDBResult result = CSpDataObject.executeImmediate(sDataSource,
sSelect);
>      int errorCode = result.getResultStatus().getErrorCode();
>      if( (errorCode == CSpDataObject.SUCCESS)  )
>      {    // good
>      }
>      else
>      {    // bad
>      }
> }
> catch(Exception ex)
> {
> }
>
>


_________________________________________________________________________

For help in using, subscribing, and unsubscribing to the discussion
forums, please go to: http://www.netdynamics.com/support/visitdevfor.html

For dire need help, email: [EMAIL PROTECTED]

Reply via email to