test your logic without using a transaction and see if that works.


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Monday, August 23, 1999 9:02 PM
To: [EMAIL PROTECTED]
Subject: Re: [ND] Transaction for Repeated's SAVE button





Thanks Darren,

I rewrote my trx code, following the online CSpTransaction code (yes, I see
the
trx.begin() isn't needed).
Below is my new code, but @#$!(* it still doesn't work.

Program flow does make it to the "succeeded" IF block, but the rows are not
saved. And no UPDATE SQL is being written to the Log.

If I remove the TRX stuff, works beautifully. The rows are updated and I can
see
the UPDATE SQL in the log.

Below are code listings showing WITH TRX, and WITHOUT.

All ideas are welcome. I'm thinking maybe I should get rid of the "full
override" DOs and instead do setValue () on them. My reasoning....none of
the
old posts that did a trx on a Repeated use the "full override" mode. Maybe
it's
broke (If it's not, *I'm* ready to break it!)

=================================
Code WITH TRX...doesn't work:
=================================
     //[[SPIDER_EVENT<BtnSave_onWebEvent>
     public int BtnSave_onWebEvent(CSpWebEvent event)
     {
          int command = PROCEED;
          CSpTransaction trx = null;

          CSpMultiSQL doMulti;

          int update = 0;
          int error = 0;
          int nNumRows;
          String sProjID, sWP;
          String  sPhs, sSeg, sStep, sTask;

          String sSQL;
          String hIndex, hStart, hFinish, hHrs, hStatus, hSubtask;
          String sStart, sFinish, sHrs, sStatus, sUserID;

          CSpDBResult result;
          CSpDBResultStatus status;

          //get session object info
          sProjID = CSpider.getUserSessionObject("soProjID").toString();
          sWP     = CSpider.getUserSessionObject("soWPName").toString();
          sUserID = CSpider.getUserSessionObject("soUserID").toString();

          // determine number of displayed rows
          doMulti = (CSpMultiSQL) CSpider.getDataObject("doWPBdgtLevel");
          doMulti.execute();
          nNumRows = doMulti.getNumOfRows();

          //get a handle to the dummy DO to use in the UPDATE transaction
          CSpMultiSQL doUpdate = (CSpMultiSQL)
CSpider.getDataObject("doClonedPreviewSave");

          //this is cheap trick we need to do to get around a ND bug.
          //must do a dummy setValue on one of the fields to get the insert
to
work
          doUpdate.setValue ("informix_iproj_wp_bdgt_iproj_id", new
CSpInteger(0));


doUpdate.setSqlTextOverrideUpdate(CSpSQLObject.FULL_TEXT_OVERRIDE);

          trx = new CSpTransaction ();

          for(int i = 0; i < nNumRows; i++){


          CSpHtml.sendMessage("top of the FOR loop NumRow i = " + i + "
<BR>");


            //get the hidden fields to compare
            hStart = convertInformixDate(getHiddenValue("*HfStart",i));
            hFinish = convertInformixDate(getHiddenValue("*HfFinish",i));
            hHrs = getHiddenValue("*HfHrs",i);
            hStatus = getHiddenValue("*HfStatus",i);
            hSubtask = getHiddenValue("*HfSubtask",i);

            //get row Index (used in error message)
            hIndex = getHiddenValue("*HfIndex", i);

            //extract the Phs, seg, step, task and subtask from the Index
            StringTokenizer st = new StringTokenizer (hIndex, ".");

            sPhs = st.nextToken(); //Phase will always be in the token
            sSeg = st.nextToken(); //Segment will always be in the token

            if (st.hasMoreTokens()){     //Step may not be in the token
               sStep = st.nextToken();
            }
            else
            {
               sStep="0";
            }
            if (st.hasMoreTokens()){     //Task may not be in the token
               sTask = st.nextToken();
            }
            else
            {
               sTask="0";
            }

            CSpHtml.sendMessage("seg = " + sSeg + "task =" + sTask + "
<BR>");

            //get the values in the display fields
            sStart = getTextBoxValue("*TbStartDate", i);
            sFinish = getTextBoxValue("*TbFinishDate",i);


             CSpHtml.sendMessage("ready to call checkDate on Start<BR>");

            // validate entered dates
            error = checkDate(sStart);
            if(error == 1){
              CSpString sErrMsg = new CSpString("The Start date for row " +
                hIndex +" is not valid. Date must be in mm/dd/yyyy
format.");
              CSpider.putUserSessionObject("soErrMsg",sErrMsg);

               command = load("PgErrorPage");
              return(command);
            }

            CSpHtml.sendMessage("ready to call checkDate on Finish<BR>");

            error = checkDate(sFinish);
            if(error == 1){
              CSpString sErrMsg = new CSpString("The Finish date for row " +
                hIndex +" is not valid. Date must be in mm/dd/yyyy
format.");
              CSpider.putUserSessionObject("soErrMsg",sErrMsg);

               command = load("PgErrorPage");
              return(command);
            }

            sHrs = getTextBoxValue("*TbBdgtHours",i);
            sStatus = getComboBoxValue("*CboTaskStatus",i);

            update = isUpdate(hStart, sStart, hFinish, sFinish,
                                   hHrs, sHrs, hStatus, sStatus);
            // if row is being updated
            if (update > 0){

              CSpHtml.sendMessage("yes, this row needs to be updated<BR>");

              error = compareDates(sStart, sFinish);

               // if sql error
              if(error == 1){

                CSpString sErrMsg = new CSpString(
                  "A Start date you have entered is after the Finish date
for a
" +
                  "row.  Please check the dates you have entered for " +
                  hIndex + ".");
                CSpider.putUserSessionObject("soErrMsg",sErrMsg);

                 command = load("PgErrorPage");
                return(command);
              }


              CSpHtml.sendMessage("date chk1 passed<BR>");

              if (update == 2){//dates have been changed,so compare them
                error = compareDateToCurrent(sStart);
                // if sql error
                if(error == 2){
                  CSpString sErrMsg = new CSpString(
                  "Start date must be today or a future date. " +
                  " Please check the dates you have entered for " +
                  hIndex + ".");
                  CSpider.putUserSessionObject("soErrMsg",sErrMsg);

                  command = load("PgErrorPage");
                  return(command);
                }

                CSpHtml.sendMessage("date chk2 passed<BR>");
              }

               doUpdate.clearAllValues();

               //Build the SQL for the update of the current table
               sSQL = new String("UPDATE iproj_wp_bdgt SET " +
               "plnd_bgn_dt = '" + sStart + "', plnd_end_dt = '" + sFinish +
               "', iproj_wp_stat_cd = " + sStatus + ", wp_task_bdgt_hrs = "
+
               sHrs + ", last_upd_user_id = '" + sUserID + "' " +
               "WHERE iproj_id = '" + sProjID + "' AND iproj_wp_nm = '" +
sWP +
               "' AND wp_phs_cd = " + sPhs + " AND wp_seg_cd = " + sSeg +
               " AND wp_step_cd = " + sStep + " AND wp_task_cd = " + sTask +
               " AND wp_sub_task_id = '" + hSubtask + "'");

               CSpHtml.sendMessage("SQL = " + sSQL + " <BR>");

               doUpdate.setSqlTextFullUpdate(sSQL);
//             doUpdate.executeUpdate();

               trx.addDataObject (doUpdate);

/*   for non-trx mode
               // Execute the SQL and check for errors
               result = CSpDataObject.executeImmediate("dsProjMgmtDB",
sSQL);
               status = result.getResultStatus();
               error = status.getVendorErrorCode1();
               if(error != 0){
                 CSpString sErrMsg = new CSpString(
                  "An error occurred while updating (history) the info for "
+
hIndex);
                CSpider.putUserSessionObject("soErrMsg",sErrMsg);

                 command = load("PgErrorPage");
                  return(command);
               }
*/

               CSpHtml.sendMessage("just added the Do to the TRX <BR>");

            }//if row is being updated.

          }//for loop end.

          CSpHtml.sendMessage ("b4 the execute <BR>");

          //execute the transaction
          command = trx.execute ();

          CSpHtml.sendMessage ("after the execute <BR>");

        if (trx.succeeded () && (command != STOP))
        {

          CSpHtml.sendMessage ("success <BR>");

               //NOTE: I shouldn't need this commit because ND takes are of
it
               //but I added it jus to see what happens, and sure enough it
gives
               //this error:
               //spider.database.CSpTransaction.commit: Called when database
               //transaction is NOT 'active'. Call has been ignored
//             trx.commit();

           // Everything is OK. All the updates succeeded and
           // transaction has been committed.
           command = load("PgBudgetLevel");
        }
        else
        { //JT later do you need this?
          //trx.rollback();
          CSpHtml.sendMessage ("failure <BR>");

           // Transaction has failed or one event, the developer chose to
           // STOP_PROCESSING. The transaction has been rolled-back by now.
           CSpDataObject failingDataObject =
                             trx.getFirstFailingDataObject ();
           if (failingDataObject != null)
           {
                    CSpHtml.sendMessage ("inside failing DO b4 error pag
load
<BR>");

              // It really failed in the database, and not due to an event
              // stopping the process
              CSpString sErrMsg = new CSpString(
                  "An error occurred while saving budgeting info");
                CSpider.putUserSessionObject("soErrMsg",sErrMsg);

                 command = load("PgErrorPage");
           }
        }

               //load the same page
//             command = load("PgBudgetLevel");

     return(command);

     }
     //]]SPIDER_EVENT<BtnSave_onWebEvent>

=================================
Code WITHOUT TRX...works great:
=================================

     //[[SPIDER_EVENT<BtnSave_onWebEvent>
     public int BtnSave_onWebEvent(CSpWebEvent event)
     {
          int command = PROCEED;

          CSpMultiSQL doMulti;

          int update = 0;
          int error = 0;
          int nNumRows;
          String sProjID, sWP;
          String  sPhs, sSeg, sStep, sTask;

          String sSQL;
          String hIndex, hStart, hFinish, hHrs, hStatus, hSubtask;
          String sStart, sFinish, sHrs, sStatus, sUserID;

          CSpDBResult result;
          CSpDBResultStatus status;

          //get session object info
          sProjID = CSpider.getUserSessionObject("soProjID").toString();
          sWP     = CSpider.getUserSessionObject("soWPName").toString();
          sUserID = CSpider.getUserSessionObject("soUserID").toString();

          // determine number of displayed rows
          doMulti = (CSpMultiSQL) CSpider.getDataObject("doWPBdgtLevel");
          doMulti.execute();
          nNumRows = doMulti.getNumOfRows();

          //get a handle to the dummy DO to use in the UPDATE transaction
          CSpMultiSQL doUpdate = (CSpMultiSQL)
CSpider.getDataObject("doClonedPreviewSave");

          //this is cheap trick we need to do to get around a ND bug.
          //must do a dummy setValue on one of the fields to get the insert
to
work
          doUpdate.setValue ("informix_iproj_wp_bdgt_iproj_id", new
CSpInteger(0));


doUpdate.setSqlTextOverrideUpdate(CSpSQLObject.FULL_TEXT_OVERRIDE);

          for(int i = 0; i < nNumRows; i++){

            //get the hidden fields to compare
            hStart = convertInformixDate(getHiddenValue("*HfStart",i));
            hFinish = convertInformixDate(getHiddenValue("*HfFinish",i));
            hHrs = getHiddenValue("*HfHrs",i);
            hStatus = getHiddenValue("*HfStatus",i);
            hSubtask = getHiddenValue("*HfSubtask",i);

            //get row Index (used in error message)
            hIndex = getHiddenValue("*HfIndex", i);

            //extract the Phs, seg, step, task and subtask from the Index
            StringTokenizer st = new StringTokenizer (hIndex, ".");

            sPhs = st.nextToken(); //Phase will always be in the token
            sSeg = st.nextToken(); //Segment will always be in the token

            if (st.hasMoreTokens()){     //Step may not be in the token
               sStep = st.nextToken();
            }
            else
            {
               sStep="0";
            }
            if (st.hasMoreTokens()){     //Task may not be in the token
               sTask = st.nextToken();
            }
            else
            {
               sTask="0";
            }


            //get the values in the display fields
            sStart = getTextBoxValue("*TbStartDate", i);
            sFinish = getTextBoxValue("*TbFinishDate",i);

            // validate entered dates
            error = checkDate(sStart);
            if(error == 1){
              CSpString sErrMsg = new CSpString("The Start date for row " +
                hIndex +" is not valid. Date must be in mm/dd/yyyy
format.");
              CSpider.putUserSessionObject("soErrMsg",sErrMsg);

              command = load("PgErrorPage");
              return(command);
            }

            error = checkDate(sFinish);
            if(error == 1){
              CSpString sErrMsg = new CSpString("The Finish date for row " +
                hIndex +" is not valid. Date must be in mm/dd/yyyy
format.");
              CSpider.putUserSessionObject("soErrMsg",sErrMsg);

               command = load("PgErrorPage");
              return(command);
            }

            sHrs = getTextBoxValue("*TbBdgtHours",i);
            sStatus = getComboBoxValue("*CboTaskStatus",i);

            update = isUpdate(hStart, sStart, hFinish, sFinish,
                                   hHrs, sHrs, hStatus, sStatus);
            // if row is being updated
            if (update > 0){

              error = compareDates(sStart, sFinish);

            // if sql error
              if(error == 1){

                CSpString sErrMsg = new CSpString(
                  "A Start date you have entered is after the Finish date
for a
" +
                  "row.  Please check the dates you have entered for " +
                  hIndex + ".");
                CSpider.putUserSessionObject("soErrMsg",sErrMsg);

                 command = load("PgErrorPage");
                return(command);
              }

              if (update == 2){//dates have been changed,so compare them
                error = compareDateToCurrent(sStart);
                // if sql error
                if(error == 2){
                  CSpString sErrMsg = new CSpString(
                  "Start date must be today or a future date. " +
                  " Please check the dates you have entered for " +
                  hIndex + ".");
                  CSpider.putUserSessionObject("soErrMsg",sErrMsg);

                  command = load("PgErrorPage");
                  return(command);
                }

              }

               //Build the SQL for the update of the current table
               sSQL = new String("UPDATE iproj_wp_bdgt SET " +
               "plnd_bgn_dt = '" + sStart + "', plnd_end_dt = '" + sFinish +
               "', iproj_wp_stat_cd = " + sStatus + ", wp_task_bdgt_hrs = "
+
               sHrs + ", last_upd_user_id = '" + sUserID + "'" +
               "WHERE iproj_id = '" + sProjID + "' AND iproj_wp_nm = '" +
sWP +
               "' AND wp_phs_cd = " + sPhs + " AND wp_seg_cd = " + sSeg +
               " AND wp_step_cd = " + sStep + " AND wp_task_cd = " + sTask +
               " AND wp_sub_task_id = '" + hSubtask + "'");

               CSpHtml.sendMessage("SQL = " + sSQL + " <BR>");

               // Execute the SQL and check for errors
               result = CSpDataObject.executeImmediate("dsProjMgmtDB",
sSQL);
               status = result.getResultStatus();
               error = status.getVendorErrorCode1();
               if(error != 0){
                 CSpString sErrMsg = new CSpString(
                  "An error occurred while updating (history) the info for "
+
hIndex);
                CSpider.putUserSessionObject("soErrMsg",sErrMsg);

                 command = load("PgErrorPage");
                  return(command);
               }


            }//if row is being updated.
            else
            {//nothing to update

               //JT later remove this:
               CSpHtml.sendMessage ("nothing to update <BR>");

            }//end of if (update > 0)

          }//for loop end.


          //load the same page
          command = load("PgBudgetLevel");
               return(command);

     }
     //]]SPIDER_EVENT<BtnSave_onWebEvent>

=================================
Thanks!
Janet


_________________________________________________________________________

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]

_________________________________________________________________________

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