home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet Web Designer 86 / PIWD86.iso / pc / contents / dreamweaver / software / dwmx2004.exe / Disk1 / data1.cab / Configuration_En / Commands / ServerBeh4-AdvRS.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  36.2 KB  |  1,502 lines

  1. // Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. // *************** GLOBALS VARS *****************
  4.  
  5. var helpDoc = MM.HELP_ssAdvancedRecordset
  6.  
  7. var SP_Mode = false;  //Since we have different formatting behavior based on whether 
  8.             //the object is a stored proc or not, we use this as a switch to 
  9.             //keep track of what's the current selection.
  10.  
  11. //The following constants and vars are used to build up the SQL statement.
  12. var CONST_SELECT  = "SELECT";
  13. var CONST_FROM    = "FROM";
  14. var CONST_WHERE   = "WHERE";
  15. var CONST_EQUALS  = "=";
  16. var CONST_ORDERBY = "ORDER BY";
  17. var CONST_AND   = " AND";
  18.  
  19. var var_select = "*";
  20. var var_from = "";
  21. var var_where = "";
  22. var var_orderby = "";
  23.  
  24. var gSimpleParamName = "MMColParam"
  25.  
  26. var ERROR_MESSAGE = "";
  27.  
  28. var CONN_LIST,PARAM_LIST,SQL_BOX,RS_NAME_BOX,MINUS_BUTTON,PLUS_BUTTON,TREE,
  29.     SELECT_BUTTON,WHERE_BUTTON,ORDERBY_BUTTON;
  30.     
  31.     
  32. // ******************* API **********************
  33.  
  34. function commandButtons()
  35. {
  36.   return new Array(MM.BTN_OK,     "clickedOK()", 
  37.                    MM.BTN_Cancel, "clickedCancel()", 
  38.                    MM.BTN_Test,   "PopUpTestDialog()", 
  39.                    MM.BTN_Simple, "clickedSimple()", 
  40.                    MM.BTN_Help,   "displayHelp()") 
  41. }
  42.  
  43.  
  44. function clickedOK()
  45. {
  46.   MM.RecordsetOK = true
  47.  
  48.   if (MM.RecordsetPriorRec)
  49.   {
  50.     var errMsg = CheckData(FINAL, MM.RecordsetPriorRec)
  51.   }
  52.   else
  53.   {
  54.     var errMsg = CheckData(FINAL, "")
  55.   }
  56.  
  57.   if (errMsg != "")
  58.   {
  59.     MM.RecordsetOK = false
  60.     alert(errMsg)
  61.     return
  62.   }
  63.  
  64.   MM.RecordsetObject = GetDataFromUI()
  65.  
  66.   RememberAdvancedRecordset()
  67.  
  68.   window.close()
  69. }
  70.  
  71.  
  72. function clickedCancel()
  73. {
  74.   window.close()
  75. }
  76.  
  77.  
  78. function PopUpTestDialog()
  79. {
  80.  
  81.   var msg = CheckData(FOR_TEST, "")
  82.   if (msg != "")
  83.   {
  84.     alert(msg)
  85.     return
  86.   }
  87.  
  88.   var theSQL = SQL_BOX.value
  89.   
  90.   var noRS = false
  91.   if (theSQL.search(/^\s*insert\s+/i) > -1)
  92.     noRS = true
  93.   if (theSQL.search(/^\s*update\s+/i) > -1)
  94.     noRS = true
  95.   if (theSQL.search(/^\s*delete\s+/i) > -1)
  96.     noRS = true
  97.  
  98.   if (noRS)
  99.   {
  100.     alert(MM.MSG_CannotTestInsertUpdateDelete)
  101.     return
  102.   }
  103.  
  104.   var pa = PARAM_LIST.getContents()
  105.   var statement = SQL_BOX.value
  106.   
  107.   // remove SQL comments
  108.   statement = statement.replace(/\/\*[\S\s]*?\*\//g, " ");
  109.   
  110.   statement = ReplaceParamsWithVals(statement, pa)
  111.  
  112.   // Special case for the handling of <cfif> tag.  
  113.   // Our solution is to execute the statement up to but not including
  114.   // the first cfif tag if one exists.
  115.   if (dw.getDocumentDOM().serverModel.getServerLanguage() == "CFML")
  116.   {
  117.     statement = stripCFIF(statement)
  118.   }
  119.  
  120.   MMDB.showResultset(CONN_LIST.getValue(), statement)
  121. }
  122.  
  123.  
  124. function clickedSimple()
  125. {
  126.   var showAlert = false
  127.  
  128.   MM.RecordsetObject = GetDataFromUI()
  129.   
  130.   var simpleObj = ParseSimpleSQL(MM.RecordsetObject.sql)
  131.   
  132.   if(simpleObj == false)
  133.   {
  134.     //alert("This SQL statement cannot be viewed in simple mode.")
  135.     showAlert = true
  136.   }
  137.   else if (simpleObj.filterColumn)
  138.   {
  139.     if (MM.RecordsetObject.paramArray.length != 1)
  140.     {
  141.       //alert("There was a where clause and the number of params was not one")
  142.       showAlert = true
  143.     }
  144.     else
  145.     {
  146.       if (MM.RecordsetObject.paramArray[0].name != gSimpleParamName)
  147.       {
  148.         //alert("Close to simple, but the param name is wrong.")
  149.         showAlert = true
  150.       }
  151.       else
  152.       {
  153.         if (GetParamTypeAndName(MM.RecordsetObject.paramArray[0], Trim(RS_NAME_BOX.value)) == false)
  154.         {
  155.           //alert("Could not recognize the runtime parameter code.")
  156.           showAlert = true
  157.         }
  158.       }
  159.     }
  160.   }
  161.   else
  162.   {
  163.     if (MM.RecordsetObject.paramArray.length != 0)
  164.     {
  165.       //alert("There were parameters and there is no where clause.")
  166.       showAlert = true
  167.     }
  168.   }
  169.   
  170.   if (showAlert)
  171.   {
  172.     alert(dwscripts.sprintf(MM.MSG_SQLNotSimple, dwscripts.getRecordsetDisplayName()));
  173.     return
  174.   }
  175.  
  176.  
  177.   MM.IsSimpleRecordset = true
  178.   MM.RecordsetSwitchingUI = true
  179.   MM.RecordsetDone = false //we are switching ui's
  180.   window.close()
  181. }
  182.  
  183.  
  184. // ***************** LOCAL FUNCTIONS  ******************
  185.  
  186. function initializeUI()
  187. {
  188.   /*
  189.   This function is called in the onLoad event.  It is responsible
  190.   for initializing the UI.  If we are inserting a recordset, this
  191.   is a matter of populating the connection drop down.
  192.  
  193.   If we are modifying a recordset, this is a matter of inspecting
  194.   the recordset tag and setting all the form elements.
  195.   */
  196.  
  197.   //Create global vars for all controls
  198.   CONN_LIST = new ListControl("ConnectionList")
  199.   PARAM_LIST = new GridControl("ParamList")
  200.   SQL_BOX = findObject("theSQL")
  201.  
  202.   RS_NAME_BOX = findObject("RecordsetName")
  203.   MINUS_BUTTON = findObject("minusButton")
  204.   PLUS_BUTTON = findObject("plusButton")
  205.  
  206.   TREE = new DBTreeControl("DBTree")
  207.  
  208.   PopulateConnectionList()
  209.   RS_NAME_BOX.value = CreateNewName()
  210.   SELECT_BUTTON = findObject("SelectButton")
  211.   WHERE_BUTTON = findObject("WhereButton")
  212.   ORDERBY_BUTTON = findObject("OrderByButton")
  213.  
  214.  
  215.   if (MM.RecordsetSwitchingUI || MM.RecordsetPriorRec)
  216.   {
  217.     inspectUI()
  218.   }
  219.  
  220.   if (ERROR_MESSAGE) alert(ERROR_MESSAGE);
  221.   
  222.   elts = document.forms[0].elements;
  223.   if (elts && elts.length)
  224.   {
  225.     elts[0].focus();
  226.     elts[0].select();
  227.   }
  228. }
  229.  
  230.  
  231.  
  232. function RememberAdvancedRecordset()
  233. {
  234.  
  235.   var path = dreamweaver.getConfigurationPath() + '/ServerBehaviors/Shared/RSSeverModelSwitches.js';
  236.   var metaFile;
  237.  
  238.   metaFile = MMNotes.open(path, true); // Force create the note file.
  239.   if (metaFile) {
  240.     MMNotes.set(metaFile, 'PREF_rsType', 'ADVANCED');
  241.     MMNotes.close(metaFile);
  242.   }
  243.  
  244. }
  245.  
  246.  
  247. function GetDataFromUI()
  248. {
  249.  
  250.   var uiData = new Object()
  251.  
  252.   uiData.name = Trim(RS_NAME_BOX.value)
  253.   uiData.connectionName = CONN_LIST.getValue()
  254.   uiData.paramArray = GetParametersFromUI()
  255.   uiData.sql = SQL_BOX.value
  256.   uiData.isSimple = false
  257.     
  258.   return uiData
  259. }
  260.  
  261.  
  262. function inspectUI() 
  263. {
  264.   var ro = MM.RecordsetObject
  265.  
  266.   //We want to check if this is an exec statement or not. If it's an exec,
  267.   //update, delete, or insert statement,
  268.   //we leave it alone and don't do our fancy formatting.
  269.  
  270.   var sqlstr = ro.sql
  271.   if  (
  272.     (sqlstr.search(/exec\s*/i) > -1) || 
  273.     (sqlstr.search(/call\s*/i) > -1) ||
  274.     (sqlstr.search(/^\s*update\s+/i) > -1) ||
  275.     (sqlstr.search(/^\s*insert\s+/i) > -1) ||
  276.     (sqlstr.search(/^\s*delete\s+/i) > -1) 
  277.     )
  278.   {
  279.     //Update the SQL_Box
  280.     SQL_BOX.value = ro.sql
  281.     //Set SP_Mode to true
  282.     SP_Mode = true;
  283.   } 
  284.   else
  285.   {
  286.     //Set SP_Mode to false
  287.     SP_Mode = false;
  288.  
  289.     //Kick in fancy formatting
  290.     if (Trim(ro.sql) == "")
  291.     {
  292.       //do nothing since they may be switching from Simple and we don't
  293.       //want to put the "Select * from" in the SQL box.
  294.     }
  295.     else if( parseSQLString(ro.sql))
  296.     {
  297.       //the parser was able to successfully identify string
  298.         updateSQL_Box();
  299.     }
  300.     else
  301.     {
  302.       //parser failed, so no fancy formatting...
  303.       SQL_BOX.value = ro.sql
  304.     }
  305.  
  306.   }
  307.   
  308.   RS_NAME_BOX.value = ro.name
  309.  
  310.   if (!CONN_LIST.pickValue(ro.connectionName))
  311.   {
  312.       CONN_LIST.setIndex(0)
  313.   }
  314.   
  315.   TREE.setConnection(ro.connectionName)
  316.  
  317.   var delim = ","
  318.   if (ro.paramArray)
  319.   {
  320.     var fillArray = new Array()
  321.     for (i = 0;i < ro.paramArray.length; i++)
  322.       {
  323.       fillArray[i] = new Array()
  324.       thisParam = ro.paramArray[i]
  325.       fillArray[i][0] = thisParam.name
  326.       fillArray[i][1] = thisParam.defaultVal
  327.       fillArray[i][2] = thisParam.runtimeVal
  328.     }
  329.  
  330.     PARAM_LIST.setContents(fillArray)
  331.     PARAM_LIST.setIndex(0)
  332.   }
  333. }
  334.  
  335.  
  336. function CheckData(reason, priorName)
  337. {
  338.   /*
  339.   This function checks all of the input variables to see
  340.   if the user has filled out everything okay...if not
  341.   return an error string.  If so, return empty string
  342.   */
  343.  
  344.   
  345.   var strOut = ""
  346.  
  347.   if (reason == FINAL)
  348.   {
  349.     // we don't get here if we are just testing the SQL statement
  350.     var theName = Trim(RS_NAME_BOX.value)
  351.     if (theName == "")
  352.     {
  353.       strOut += MM.MSG_NoRecordsetName;
  354.       return strOut
  355.     }
  356.  
  357.     if (!IsValidVarName(theName))
  358.     {
  359.       strOut = MM.MSG_InvalidRecordsetName
  360.       return strOut
  361.     }
  362.  
  363.     if (IsDupeObjectName(theName, priorName))
  364.     {
  365.       return MM.MSG_DupeRecordsetName;
  366.     }
  367.  
  368.     if (IsReservedWord(theName))
  369.     {
  370.       return dwscripts.sprintf(MM.MSG_ReservedWord, theName);
  371.     }
  372.         
  373.   }
  374.  
  375.   if (CONN_LIST.getIndex() == 0)
  376.   {
  377.     strOut += MM.MSG_NoConnection;
  378.     return strOut
  379.   }
  380.   
  381.   var theSQL =  SQL_BOX.value
  382.  
  383.   if (StripChars(" \r\n\t", theSQL) == "")
  384.   {
  385.     strOut += MM.MSG_NoRecordsetSQLStatement;
  386.     return strOut
  387.   }
  388.  
  389.   switch(dw.getDocumentDOM().serverModel.getServerLanguage())
  390.   {
  391.     case "JavaScript":
  392.     case "VBScript":
  393.     case "Java":
  394.  
  395.       // we only accept Select statements
  396.       // and calls to sp's
  397.       var validSQL = false
  398.       var callRE = /\s*call\b/i
  399.       if (theSQL.search(callRE) > -1)
  400.         validSQL = true
  401.       var spRE = /^\s*exec\b/i
  402.       if (theSQL.search(spRE) > -1)
  403.         validSQL = true
  404.       var spRE = /^\s*execute\b/i
  405.       if (theSQL.search(spRE) > -1)
  406.         validSQL = true
  407.       var selectRE = /^\s*select\b/i
  408.       if (theSQL.search(selectRE) > -1)
  409.         validSQL = true
  410.       if (!validSQL)
  411.       {
  412.         strOut = MM.MSG_NoRecordsetSQLStatement;
  413.         return strOut
  414.       }
  415.  
  416.       break
  417.  
  418.     case "CFML":
  419.  
  420.       // we only accept Select statements, calls to sp's, and insert/update/delete statements
  421.       var validSQL = false
  422.       var callRE = /\s*call\b/i
  423.       if (theSQL.search(callRE) > -1)
  424.         validSQL = true
  425.       var spRE = /^\s*exec\b/i
  426.       if (theSQL.search(spRE) > -1)
  427.         validSQL = true
  428.       var spRE = /^\s*execute\b/i
  429.       if (theSQL.search(spRE) > -1)
  430.         validSQL = true
  431.       var selectRE = /^\s*select\b/i
  432.       if (theSQL.search(selectRE) > -1)
  433.         validSQL = true
  434.       if (theSQL.search(/\s*insert\s+/i) > -1)
  435.         validSQL = true
  436.       if (theSQL.search(/\s*update\s+/i) > -1)
  437.         validSQL = true
  438.       if (theSQL.search(/\s*delete\s+/i) > -1)
  439.         validSQL = true
  440.  
  441.       if (!validSQL)
  442.       {
  443.         strOut = MM.MSG_NoRecordsetSQLStatement;
  444.         return strOut
  445.       }
  446.   }
  447.   
  448.   var pa = PARAM_LIST.getContents()
  449.   //alert("the num of params is: " + pa.length)
  450.   if (pa.length > 0)
  451.   {
  452.       strOut = CheckSQLParams(pa, theSQL, reason)
  453.   }
  454.   return strOut
  455. }
  456.  
  457.  
  458. function CheckSQLParams(pa, theSQL, reason)
  459. {
  460.   var strOut = ""
  461.  
  462.   for (var i = 0; i < pa.length; i++)
  463.   {
  464.     var anOption = pa[i]
  465.  
  466.     var theName = Trim(anOption[0])
  467.     if (theName == "")
  468.     {
  469.       strOut =  strOut = MM.LABEL_ParamRow + (i + 1) + "\n\n" + MM.MSG_MissingParamName
  470.       return strOut
  471.     }
  472.     if (!IsValidVarName(theName))
  473.     {
  474.       strOut = MM.LABEL_ParamRow + (i + 1) + "\n\n" + theName + "\n\n" + MM.MSG_InvalidParamName
  475.       return strOut
  476.     }
  477.     else
  478.     {
  479.       var re = new RegExp("\\b" + theName + "\\b");
  480.       if (theSQL.search(re) == -1)
  481.       {
  482.         strOut = MM.LABEL_ParamRow + (i + 1) + "\n\n" + theName + "\n\n" + MM.MSG_InvalidParamNameNotInSQL
  483.         return strOut
  484.       }
  485.     }
  486.  
  487.  
  488.     var theDefaultVal = Trim(anOption[1])
  489.     if (theDefaultVal == "")
  490.     {
  491.       strOut = MM.LABEL_ParamRow + (i + 1) + "\n\n" + MM.MSG_DefaultValMissing + theName
  492.       return strOut
  493.     }
  494.  
  495.  
  496.     if (reason == FINAL)
  497.     {
  498.       var theRunTimeVal = Trim(anOption[2])
  499.       if (theRunTimeVal == "")
  500.       {
  501.         strOut = MM.LABEL_ParamRow + (i + 1) + "\n\n" + MM.MSG_RunTimeValMissing + theName
  502.         return strOut
  503.       }
  504.  
  505.       if (dw.getDocumentDOM().serverModel.getServerLanguage() == "CFML")
  506.       {
  507.         if (theRunTimeVal.search(/^#\S+#$/i) == -1)
  508.         {
  509.           return MM.LABEL_ParamRow + (i + 1) + "\n\n" + MM.MSG_RunTimeValNotCFFormat
  510.         }
  511.       }
  512.  
  513.     } 
  514.   }
  515.  
  516.   return ""
  517. }
  518.  
  519.  
  520. function GetParametersFromUI()
  521. {
  522.   var gridContents = PARAM_LIST.getContents()
  523.   var paramArray = new Array()
  524.  
  525.   for (var i = 0; i < gridContents.length; i++)
  526.   {
  527.     var newParam = new Object()
  528.     var oldParam = gridContents[i]
  529.     newParam.name = oldParam[0]
  530.     newParam.defaultVal = oldParam[1]
  531.     newParam.runtimeVal = oldParam[2]
  532.     paramArray.push(newParam)
  533.   }
  534.  
  535.   return paramArray
  536. }
  537.  
  538.  
  539. function DeleteParam()
  540. {
  541.   /*
  542.   This function is called when the user
  543.   clicks on the minus button above the params list box.
  544.   If there is not a selected index in the list, we do
  545.   nothing. 
  546.   */
  547.  
  548.   PARAM_LIST.del()
  549.   //UpdateMinusButton()
  550. }
  551.  
  552. function AddParam()
  553. {
  554.     if (dw.isOSX())
  555.   {
  556.     // work around a problem in OSX where the first editable
  557.     // region does not get focus.  Add a defaut name
  558.     // so the user can see that something happened
  559.     PARAM_LIST.object.options.push(new Option(MM.LABEL_Unnamed))
  560.   }
  561.   else
  562.   {
  563.     PARAM_LIST.object.options.push(new Option(""))
  564.   }
  565.  
  566.   //PARAM_LIST.append()
  567.   //UpdateMinusButton()
  568. }
  569.  
  570.  
  571. function UpdateMinusButton()
  572. {
  573.   if (PARAM_LIST.getIndex() >= 0)
  574.   {
  575.     MINUS_BUTTON.src = "../../Shared/UltraDev/Images/MinusButtonEnabled.gif"
  576.   }
  577.   else
  578.   {
  579.     MINUS_BUTTON.src = "../../Shared/UltraDev/Images/MinusButtonDisabled.gif"
  580.   }
  581. }
  582.  
  583.  
  584.  
  585. function stripCFIF(sql)
  586. {
  587.   var statement = sql.replace(/\n/g, " ")
  588.   statement = statement.replace(/\r/g, " ")
  589.   var found = statement.search(/^(.*)\s*<cfif/i)
  590.   if (found != -1)
  591.   {
  592.     statement = RegExp.$1
  593.   }
  594.   return statement
  595. }
  596.  
  597. function ConnectionChanged()
  598. {
  599.   TREE.setConnection(CONN_LIST.getValue())
  600. }
  601.  
  602.   
  603. function updateSQLWithStoredProcedure()
  604. {
  605.   //This method builds the SQL statment when a stored procedure is
  606.   //selected in the tree.
  607.  
  608.   var treeData = TREE.getData()
  609.  
  610.   //If it's not a stored procedure, don't do anything.
  611.   if (!treeData.IsProcedure())
  612.   {
  613.     return
  614.   }
  615.  
  616.   var curText = SQL_BOX.value
  617.  
  618.   var returnValue = ""
  619.   var outParams = ""
  620.  
  621.   var procName = treeData.procedure 
  622.   var paramArray = treeData.paramArray
  623.   var paramBoxContents = new Array()
  624.  
  625.   //Build the Param array
  626.   for (var i = 0; i < paramArray.length; i++)
  627.   {
  628.     //Remove all '@' chars from the param name.
  629.     var paramName = StripChars("@", paramArray[i].name)
  630.     var stype = dwscripts.getDBColumnTypeAsString(paramArray[i].type)
  631.     bString = dwscripts.isStringDBColumnType(paramArray[i].type);
  632.     bBinary = dwscripts.isBinaryDBColumnType(paramArray[i].type);
  633.   
  634.     if (paramName != "RETURN_VALUE")
  635.     {
  636.       if (outParams != "")
  637.         outParams += ","
  638.  
  639.       if (bString)
  640.         outParams = outParams + "'" + paramName + "'"
  641.       else
  642.       {
  643.         if ((stype == "REF CURSOR")||(bBinary))
  644.         {
  645.           outParams += "?";
  646.         }
  647.         else
  648.         {
  649.           outParams += paramName;
  650.         }
  651.       }
  652.  
  653.       if (stype != "REF CURSOR" && !bBinary)
  654.       {
  655.         // We don't want to list the param if it is REF CURSOR or binary
  656.         var aParam = new Array()
  657.         aParam[0] = paramName
  658.         aParam[1] = ""
  659.         aParam[2] = ""
  660.         paramBoxContents.push(aParam)
  661.       }
  662.     }
  663.   }
  664.  
  665.   PARAM_LIST.delAll();
  666.  
  667.   if (outParams == ""){
  668.     SQL_BOX.value = "{call " + procName +"}"
  669.     outParams = ""
  670.   }
  671.   else{
  672.     SQL_BOX.value = "{call " + procName + "(" + outParams + ")}"
  673.     PARAM_LIST.setContents(paramBoxContents)
  674.   }
  675. }
  676.  
  677.  
  678. //This method is called after the SQL has been 'parsed'. This updates
  679. //the SQL box with formatted SQL statment.
  680. function updateSQL_Box()
  681. {
  682.   var sqlstr = "";
  683.   
  684.   if (StripChars(" \r\n\t", var_select) == "")
  685.   {
  686.     var_select = "*";
  687.   }
  688.   sqlstr = CONST_SELECT + " " + var_select + "\n" + CONST_FROM;
  689.   if (var_from != "")
  690.   {
  691.     sqlstr += " ";
  692.     sqlstr += var_from;
  693.   }
  694.   if( var_where != "")
  695.   {
  696.     //sqlstr += " ";
  697.     sqlstr += "\n";
  698.     sqlstr += CONST_WHERE;
  699.     sqlstr += " ";  
  700.     sqlstr += var_where;
  701.   }
  702.   if( var_orderby != "")
  703.   {
  704.     //sqlstr += " ";
  705.     sqlstr += "\n";
  706.     sqlstr += CONST_ORDERBY;
  707.     sqlstr += " ";
  708.     sqlstr += var_orderby;
  709.   }
  710.  
  711.   if (sqlstr != "")
  712.   {
  713.     SQL_BOX.value = sqlstr;
  714.   }
  715. }
  716.  
  717. //Update the global vars from the RegularExpression result.
  718. function updateSQLVars(index)
  719. {
  720.   switch(index)
  721.   {
  722.   case 1: 
  723.     var_select = Trim(StripChars("\r\n\t", RegExp.$3));
  724.     var_from = Trim(StripChars("\r\n\t", RegExp.$5));
  725.     var_where = Trim(StripChars("\r\n\t", RegExp.$7));
  726.     var_orderby = Trim(StripChars("\r\n\t", RegExp.$9));
  727.     break;
  728.   case 2:
  729.     var_select = Trim(StripChars("\r\n\t", RegExp.$3));
  730.     var_from = Trim(StripChars("\r\n\t", RegExp.$5));
  731.     var_where = "";
  732.     var_orderby = Trim(StripChars("\r\n\t", RegExp.$7));
  733.     break;
  734.   case 3:
  735.     var_select = Trim(StripChars("\r\n\t", RegExp.$3));
  736.     var_from = "";
  737.     var_where = Trim(StripChars("\r\n\t", RegExp.$5));
  738.     var_orderby = Trim(StripChars("\r\n\t", RegExp.$7));
  739.     break;
  740.   case 4:
  741.     var_select = Trim(StripChars("\r\n\t", RegExp.$3));
  742.     var_from = "";
  743.     var_where = "";
  744.     var_orderby = Trim(StripChars("\r\n\t", RegExp.$5));
  745.     break;
  746.   case 5:
  747.     var_select = Trim(StripChars("\r\n\t", RegExp.$1));
  748.     var_from = Trim(StripChars("\r\n\t", RegExp.$3));
  749.     var_where = Trim(StripChars("\r\n\t", RegExp.$5));
  750.     var_orderby = Trim(StripChars("\r\n\t", RegExp.$7));
  751.     break;
  752.   case 6:
  753.     var_select = Trim(StripChars("\r\n\t", RegExp.$1));
  754.     var_from = "";
  755.     var_where = Trim(StripChars("\r\n\t", RegExp.$3));
  756.     var_orderby = Trim(StripChars("\r\n\t", RegExp.$7));
  757.     break;
  758.   case 7:
  759.     var_select = Trim(StripChars("\r\n\t", RegExp.$1));
  760.     var_from = "";
  761.     var_where = "";
  762.     var_orderby = Trim(StripChars("\r\n\t", RegExp.$3));
  763.     break;
  764.  
  765.  
  766.   }
  767. }
  768.  
  769. //Parse the sql statement in the SQL Box.
  770. function parseSQLString(SQLString)
  771. {
  772.   
  773.   var updateStyle = 1
  774.   var standardUpdate = true;
  775.  
  776.   //Check if it's in "StoredProc" mode. If it is don't do anything.
  777.   
  778.   if(!SP_Mode)
  779.   {
  780.  
  781.   SQLString = SQLString.replace(/\n/g,"");
  782.  
  783.   SQLString = SQLString.replace(/\r/g," ");
  784.  
  785.   
  786.   //Why do we need this exec check? If the user has a stored proc in the sql 
  787.   //edit, and then clicks on a table/view column, it would mean that he/she 
  788.   //wants to change the sql from a stored proc to a select statement. 
  789.   //So we first check to see the exec string is found in the sql. If it is, 
  790.   //we just set it to empty, as the updateSQLBox function will take care of it. 
  791.   //2-15-00 Made a slight modification to the reg exp params below. I removed the
  792.   //\b before the exec/ call statements. This is because the { does not count as
  793.   //as word boundry.
  794.  
  795.   var re_1 = /(exec)\b/g;
  796.   var re_2 = /(call)\b/g;
  797.   if((SQLString.search(re_1) != -1) || (SQLString.search(re_2) != -1))
  798.   {
  799.     SQLString = "";
  800.     PARAM_LIST.delAll();
  801.     return true
  802.   }
  803.  
  804.   //type = 1
  805.   var re1 = /(\s*|.*)(\bselect\b)(\s*|.*)(\bfrom\b)(\s*|.*)(\bwhere\b)(\s*|.*)(order by)(\s*|.*)$/i;
  806.   var re2 = /(\s*|.*)(\bselect\b)(\s*|.*)(\bfrom\b)(\s*|.*)(\bwhere\b)(\s*|.*)(order by)\s*$/i;
  807.   var re3 = /(\s*|.*)(\bselect\b)(\s*|.*)(\bfrom\b)(\s*|.*)(\bwhere\b)(\s*|.*)$/i;
  808.   var re4 = /(\s*|.*)(\bselect\b)(\s*|.*)(\bfrom\b)(\s*|.*)(\bwhere\b)\s*$/i;
  809.   //type = 2
  810.   var re5 = /(\s*|.*)(\bselect\b)(\s*|.*)(\bfrom\b)(\s*|.*)(\border\sby\b)(\s*|.*)$/i;
  811.   var re6 = /(\s*|.*)(\bselect\b)(\s*|.*)(\bfrom\b)(\s*|.*)(\border\sby\b)\s*$/i;
  812.   var re7 = /(\s*|.*)(\bselect\b)(\s*|.*)(\bfrom\b)(\s*|.*)$/i;
  813.   var re8 = /(\s*|.*)(\bselect\b)(\s*|.*)(\bfrom\b)\s*$/i;
  814.   //type = 3
  815.   var re9 = /(\s*|.*)(\bselect\b)(\s*|.*)(\bwhere\b)(\s*|.*)(\border by\b)(\s*|.*)$/i;
  816.   var re10= /(\s*|.*)(\bselect\b)(\s*|.*)(\bwhere\b)(\s*|.*)(\border by\b)\s*$/i;
  817.   var re11= /(\s*|.*)(\bselect\b)(\s*|.*)(\bwhere\b)(\s*|.*)$/i;
  818.   var re12= /(\s*|.*)(\bselect\b)(\s*|.*)(\bwhere\b)\s*$/i;
  819.   //type = 4
  820.   var re13= /(\s*|.*)(\bselect\b)(\s*|.*)(\border by\b)(\s*|.*)$/i;
  821.   var re14= /(\s*|.*)(\bselect\b)(\s*|.*)(\border by\b)\s*$/i;
  822.   var re15= /(\s*|.*)(\bselect\b)(\s*|.*)$/i;
  823.   var re16= /(\s*|.*)(\bselect\b)\s*$/i;
  824.   //type = 5
  825.   var re17= /(\s*|.*)(\bfrom\b)(\s*|.*)(\bwhere\b)(\s*|.*)(\border by\b)(\s*|.*)$/i;
  826.   var re18= /(\s*|.*)(\bfrom\b)(\s*|.*)(\bwhere\b)(\s*|.*)(\border by\b)\s*$/i;
  827.   var re19= /(\s*|.*)(\bfrom\b)(\s*|.*)(\bwhere\b)(\s*|.*)$/i;
  828.   var re20= /(\s*|.*)(\bfrom\b)(\s*|.*)(\bwhere\b)\s*$/i;
  829.   var re21= /(\s*|.*)(\bfrom\b)(\s*|.*)$/i;
  830.   var re22= /(\s*|.*)(\bfrom\b)\s*$/i;
  831.   //type = 6
  832.   var re23= /(\s*|.*)(\bwhere\b)(\s*|.*)(\border by\b)(\s*|.*)$/i;
  833.   var re24= /(\s*|.*)(\bwhere\b)(\s*|.*)(\border by\b)\s*$/i;
  834.   var re25= /(\s*|.*)(\bwhere\b)(\s*|.*)$/i;
  835.   var re26= /(\s*|.*)(\bwhere\b)\s*$/i;
  836.   //type = 7
  837.   var re27= /(\s*|.*)(\border by\b)(\s*|.*)$/i;
  838.   var re28= /(\s*|.*)(\border by\b)\s*$/i;
  839.  
  840.   var re_empty = /\s?/i;
  841.  
  842.   if(StripChars(" \r\n\t", SQLString) == "")
  843.   {
  844.     SQLString.search(re_empty);
  845.     updateSQLVars(1)
  846.     return true
  847.   }
  848.  
  849.   if((SQLString.search(re1) != -1) || (SQLString.search(re2) != -1) || (SQLString.search(re3) != -1) || (SQLString.search(re4) != -1))
  850.   {
  851.     updateSQLVars(1)
  852.     return true
  853.   }
  854.  
  855.   if((SQLString.search(re5) != -1) || (SQLString.search(re6) != -1) || (SQLString.search(re7) != -1) || (SQLString.search(re8) != -1))
  856.   {
  857.     updateSQLVars(2)
  858.     return true
  859.   }
  860.  
  861.   if((SQLString.search(re9) != -1) || (SQLString.search(re10) != -1) || (SQLString.search(re11) != -1) || (SQLString.search(re12) != -1))
  862.   {
  863.     updateSQLVars(3)
  864.     return true
  865.   }
  866.  
  867.   if((SQLString.search(re13) != -1) || (SQLString.search(re14) != -1) || (SQLString.search(re15) != -1) || (SQLString.search(re16) != -1))
  868.   {
  869.     updateSQLVars(4)
  870.     return true
  871.   }
  872.  
  873.   if((SQLString.search(re17) != -1) || (SQLString.search(re18) != -1) || (SQLString.search(re19) != -1) || (SQLString.search(re20) != -1) || (SQLString.search(re21) != -1) || (SQLString.search(re22) != -1))
  874.   {
  875.     updateSQLVars(5)
  876.     return true
  877.   }
  878.  
  879.   if((SQLString.search(re23) != -1) || (SQLString.search(re24) != -1) || (SQLString.search(re25) != -1) || (SQLString.search(re26) != -1))
  880.   {
  881.     updateSQLVars(6)
  882.     return true
  883.   }
  884.  
  885.   if((SQLString.search(re27) != -1) || (SQLString.search(re28) != -1))
  886.   {
  887.     updateSQLVars(7)
  888.     return true
  889.   }
  890.   
  891.   return false
  892.  
  893.  }
  894.  return true;
  895. }
  896.  
  897.  
  898. function IsSelectStatement()
  899. {
  900.   if (Trim(SQL_BOX.value) == "")
  901.   {
  902.     return true
  903.   }
  904.  
  905.   var sql = String(SQL_BOX.value)
  906.   return (sql.search(/^\s*select\s+/i) != -1)
  907. }
  908.  
  909.  
  910. //On Click handler for the Add to Select button
  911. function AddToSelect()
  912. {
  913.   if (!SP_Mode && !IsSelectStatement())
  914.   {
  915.     alert(MM.MSG_CanOnlyUseButtonsOnSelectStatements)
  916.     return
  917.   }
  918.  
  919.   var selectstr = "";
  920.   var tablename = "";
  921.  
  922.   var curText = SQL_BOX.value
  923.   var treeData = TREE.getData();
  924.  
  925.   var matchLoc;
  926.   var result;
  927.   var exactMatch = 0;
  928.  
  929.   if(!IsConnectionSelected())
  930.   {
  931.    return;
  932.   }
  933.  
  934.   //Proceed if selection is not a stored procedure
  935.   if (!treeData.IsProcedure())  
  936.   {
  937.     //Check if selection is a column.
  938.   if(treeData.IsColumn())
  939.   { 
  940.     SP_Mode = false;
  941.     if (parseSQLString(curText))
  942.       {
  943.       if( (StripChars(" \r\n\t", var_select) == "*") || (StripChars(" \r\n\t", var_select) == ""))
  944.       {
  945.         var_select = treeData.column;
  946.       } else {
  947.         theStr = treeData.column;
  948.         escStr = quoteMeta(theStr);
  949.         var re = new RegExp(escStr, "gi");
  950.         exactMatch = 0; 
  951.         while((result = re.exec(var_select)) != null) {
  952.           matchLoc = result.index;
  953.           if (( matchLoc == 0 || var_select[matchLoc-1] == ' ' || var_select[matchLoc-1] == ',' ) && ( var_select[matchLoc + theStr.length] == ',' || var_select[matchLoc + theStr.length] == null ))
  954.           {
  955.             exactMatch = 1;
  956.           }
  957.         }
  958.       
  959.         if(exactMatch == 0)
  960.         {
  961.           var tempStr = Trim(var_select)
  962.           if(tempStr.lastIndexOf(",") == (tempStr.length -1))
  963.           {
  964.             selectstr = Trim(var_select)  
  965.             selectstr += " " + treeData.column
  966.             var_select = selectstr;
  967.           } else {
  968.           selectstr = Trim(var_select) + ", ";
  969.           selectstr += treeData.column
  970.           var_select = selectstr;
  971.           }
  972.         } else {
  973.           alert(errMsg(MM.MSG_DupeColumnWarning, treeData.column));
  974.           var tempStr = Trim(var_select)
  975.           if(tempStr.lastIndexOf(",") == (tempStr.length -1))
  976.           {
  977.             selectstr = Trim(var_select)  
  978.             selectstr += " " + treeData.table + "." + treeData.column
  979.             var_select = selectstr;
  980.           } else {
  981.             selectstr = Trim(var_select) + ", ";
  982.             selectstr += treeData.table + "." + treeData.column
  983.             var_select = selectstr;
  984.           }
  985.         }
  986.       }
  987.  
  988.       tablename = treeData.table;
  989.       if (StripChars(" \r\n\t", var_from) == "")
  990.       {
  991.         var_from = tablename;
  992.       } else {
  993.         theStr = treeData.table;
  994.         escStr = quoteMeta(theStr);
  995.         var re = new RegExp(escStr, "gi");
  996.         exactMatch = 0; 
  997.         while((result = re.exec(var_from)) != null) {
  998.           matchLoc = result.index;
  999.           if (( matchLoc == 0 || var_from[matchLoc-1] == ' ' || var_from[matchLoc-1] == ',') && ( var_from[matchLoc + theStr.length] == ',' || var_from[matchLoc + theStr.length] == null ))
  1000.           {
  1001.             exactMatch = 1;
  1002.           }
  1003.         }
  1004.       
  1005.         if (exactMatch == 0)
  1006.         {
  1007.           //var_from += ", " + tablename;
  1008.           var tempStr = Trim(var_from)
  1009.           if(tempStr.lastIndexOf(",") == (tempStr.length -1))
  1010.           {
  1011.             tablename = Trim(var_from)  
  1012.             tablename += " " + treeData.table
  1013.             var_from = tablename;
  1014.           } else {
  1015.             tablename = Trim(var_from) + ", ";
  1016.             tablename += treeData.table
  1017.             var_from = tablename;
  1018.           }
  1019.         }
  1020.  
  1021.       }
  1022.       updateSQL_Box();
  1023.     } else
  1024.     {
  1025.       alert(MM.MSG_InvalidSQL);
  1026.     }
  1027.   } else {
  1028.     if((treeData.IsTable()) && (treeData.table != "undefined"))
  1029.     {
  1030.       //A table is selected.
  1031.       SP_Mode = false;
  1032.       if(parseSQLString(curText))
  1033.       {
  1034.         var tablename = treeData.table;
  1035.         if(StripChars(" \r\n\t", var_from)  == "")
  1036.         {
  1037.           var_from = tablename;
  1038.           updateSQL_Box();
  1039.         } else {
  1040.           theStr = treeData.table;
  1041.           escStr = quoteMeta(theStr);
  1042.           var re = new RegExp(escStr, "gi");
  1043.           exactMatch = 0; 
  1044.           while((result = re.exec(var_from)) != null) {
  1045.             matchLoc = result.index;
  1046.             if (( matchLoc == 0 || var_from[matchLoc-1] == ' ' || var_from[matchLoc-1] == ',') && ( var_from[matchLoc + theStr.length] == ',' || var_from[matchLoc + theStr.length] == null ))
  1047.             {
  1048.               exactMatch = 1;
  1049.             }
  1050.           }
  1051.         
  1052.           if(exactMatch == 0)
  1053.           {
  1054.             var tempStr = Trim(var_from)
  1055.             if(tempStr.lastIndexOf(",") == (tempStr.length -1))
  1056.             {
  1057.               tablename = Trim(var_from)  
  1058.               tablename += " " + treeData.table
  1059.               var_from = tablename;
  1060.             } else {
  1061.               tablename = Trim(var_from) + ", ";
  1062.               tablename += treeData.table
  1063.               var_from = tablename;
  1064.             }
  1065.             updateSQL_Box();
  1066.           }
  1067.         }
  1068.       } else
  1069.       {
  1070.         alert(MM.MSG_InvalidSQL);
  1071.       }
  1072.     } else {
  1073.       alert(MM.MSG_InvalidSelection);
  1074.     }
  1075.   }
  1076.   } else {
  1077.     //it's a stored procedure. Update accordingly.
  1078.     SP_Mode = true;
  1079.   updateSQLWithStoredProcedure();
  1080.   }
  1081.  
  1082. }
  1083.  
  1084. //onclick event handler for the "Add to where" button associated with the tree.
  1085. function ColumnAddToWhere()
  1086. {
  1087.  
  1088.   if (!IsSelectStatement())
  1089.   {
  1090.     alert(MM.MSG_CanOnlyUseButtonsOnSelectStatements)
  1091.     return
  1092.   }
  1093.  
  1094.   if(!IsConnectionSelected())
  1095.   {
  1096.   return;
  1097.   }
  1098.  
  1099.   var selectstr = "";
  1100.   var curText = SQL_BOX.value
  1101.   var treeData = TREE.getData();
  1102.  
  1103.   //Check if the selection is not a stored procedure
  1104.   if (!treeData.IsProcedure())  
  1105.   {
  1106.   //Proceed only if selection is a column
  1107.   if(treeData.IsColumn())
  1108.   {
  1109.     SP_Mode = false;
  1110.     if(parseSQLString(curText))
  1111.     {
  1112.       if(Trim(var_from) == "")
  1113.       {
  1114.         var_from = treeData.table;
  1115.       }
  1116.  
  1117.       if(Trim(var_where) == "")
  1118.       {
  1119.         var_where = treeData.column;
  1120.         updateSQL_Box();
  1121.       } else {
  1122.           //Do a check here to see if " AND" is not the last word.
  1123.         var trimWhereStr = Trim(var_where);
  1124.         if(addAndIsOkay(trimWhereStr))
  1125.           selectstr = Trim(var_where) + " AND ";
  1126.         else 
  1127.           selectstr = Trim(var_where) + " ";
  1128.  
  1129.         selectstr += treeData.column;
  1130.         var_where = selectstr;
  1131.         updateSQL_Box();
  1132.       }
  1133.     } 
  1134.   } else {
  1135.     alert(MM.MSG_SelectColumn);
  1136.   }
  1137.   } else {
  1138.     SP_Mode = true;
  1139.   updateSQLWithStoredProcedure();
  1140.   }
  1141. }
  1142.  
  1143.  
  1144. //onclick event handler for the "Add to where" button associated with the param grid.
  1145. function VarAddToWhere()
  1146. {
  1147.   if (!IsSelectStatement())
  1148.   {
  1149.     alert(MM.MSG_CanOnlyUseButtonsOnSelectStatements)
  1150.     return
  1151.   }
  1152.  
  1153.   if(!IsConnectionSelected())
  1154.   {
  1155.   return;
  1156.   }
  1157.  
  1158.   var paramlist = PARAM_LIST.getContents();
  1159.   if(paramlist.length == 0)
  1160.   {
  1161.   alert(MM.MSG_EmptyParamList);
  1162.   return;
  1163.   }
  1164.  
  1165.  
  1166.   if(!SP_Mode)
  1167.   {
  1168.     var selectstr = "";
  1169.     var selItem = PARAM_LIST.getIndex();
  1170.     var curText = SQL_BOX.value
  1171.  
  1172.     //Proceed only if a row in the grid is selected. 
  1173.   if(selItem != -1)
  1174.   {
  1175.     if(parseSQLString(curText) > -1)
  1176.     {
  1177.       var pa = PARAM_LIST.getContents();
  1178.  
  1179.       if (pa.length > 0)
  1180.       {
  1181.         var paramName = pa[selItem][0];
  1182.         var_where = Trim(var_where) + " = " + paramName;
  1183.         updateSQL_Box();
  1184.       }
  1185.     } else {
  1186.       alert(MM.MSG_InvalidSQL);
  1187.     }
  1188.   }
  1189.   } 
  1190. }
  1191.  
  1192.  
  1193. //adds the name of the selected param to the SQL statement.
  1194. function VarAddToEnd()
  1195. {
  1196.   if (!IsSelectStatement())
  1197.   {
  1198.     alert(MM.MSG_CanOnlyUseButtonsOnSelectStatements)
  1199.     return
  1200.   }
  1201.  
  1202.   if(!IsConnectionSelected())
  1203.   {
  1204.     return;
  1205.   }
  1206.  
  1207.   var paramlist = PARAM_LIST.getContents();
  1208.   if(paramlist.length == 0)
  1209.   {
  1210.   alert(MM.MSG_EmptyParamList);
  1211.   return;
  1212.   }
  1213.  
  1214.  
  1215.   //Check that the code in the SQL box is not an exec statement.  
  1216.   if (!SP_Mode)
  1217.   {
  1218.   var selItem = PARAM_LIST.getIndex();
  1219.   var curText = SQL_BOX.value
  1220.   
  1221.   if(selItem != -1)
  1222.   {
  1223.     var pa = PARAM_LIST.getContents();
  1224.     if (pa.length > 0)
  1225.     {
  1226.       var paramName = pa[selItem][0];
  1227.       curText = curText + " " + paramName;
  1228.       SQL_BOX.value = curText;
  1229.     }
  1230.   }
  1231.   }
  1232. }
  1233.  
  1234.  
  1235. //onclick event handler for the Add to Order by button.
  1236. function AddToOrderBy()
  1237. {
  1238.   if (!IsSelectStatement())
  1239.   {
  1240.     alert(MM.MSG_CanOnlyUseButtonsOnSelectStatements)
  1241.     return
  1242.   }
  1243.  
  1244.   if(!IsConnectionSelected())
  1245.   {
  1246.     return;
  1247.   }
  1248.  
  1249.   var selectstr = "";
  1250.   var curText = SQL_BOX.value
  1251.   var treeData = TREE.getData();
  1252.   
  1253.   //Proceed only if not a Stored procedure.
  1254.   if (!treeData.IsProcedure())  
  1255.   {
  1256.     //Check if selection is a column 
  1257.   if(treeData.IsColumn())
  1258.   {
  1259.     SP_Mode = false;
  1260.     if(parseSQLString(curText))
  1261.     {
  1262.       if(Trim(var_from) == "")
  1263.       {
  1264.         var_from = treeData.table;
  1265.       }
  1266.       if(Trim(var_orderby) == "")
  1267.       {
  1268.         var_orderby = treeData.column;
  1269.         updateSQL_Box();
  1270.       } else {
  1271.         var re = new RegExp("\\b" + treeData.column + "\\b", "gi");       
  1272.         if(var_orderby.search(re) == -1)
  1273.         {
  1274.           var tempStr = Trim(var_orderby)
  1275.           if(tempStr.lastIndexOf(",") == (tempStr.length -1))
  1276.         {
  1277.             selectstr = Trim(var_orderby)
  1278.             selectstr += " " + treeData.column
  1279.             var_orderby = selectstr;
  1280.           } else {
  1281.           selectstr = Trim(var_orderby) + ", ";
  1282.           selectstr += treeData.column;
  1283.           var_orderby = selectstr;
  1284.           }
  1285.           updateSQL_Box();
  1286.         }
  1287.       }
  1288.     } else {
  1289.       alert(MM.MSG_InvalidSQL);
  1290.     }
  1291.   } else {
  1292.     alert(MM.MSG_SelectColumn);
  1293.   }
  1294.   } else {
  1295.   //Update SQL with selected stored procedure syntax  
  1296.     SP_Mode = true;
  1297.   updateSQLWithStoredProcedure();
  1298.   }
  1299. }
  1300.  
  1301.  
  1302. function UpdateTreeSelection()
  1303. {
  1304.   //TREE_SEL_BOX.value = TREE.selectedItem
  1305.   var treeData = TREE.getData();
  1306.   if(treeData.IsProcedure())
  1307.   {
  1308.     //Enable/disable suitable buttons for the stored
  1309.     //proc selection
  1310.     StoredProcButtons()
  1311.   } else {
  1312.     //A table/view/column is selected. Do the needful.
  1313.     NotStoredProcButtons()
  1314.   }
  1315. }
  1316.  
  1317.  
  1318.  
  1319. function LaunchConnectionManager()
  1320. {
  1321.   var oldList = String(CONN_LIST.valueList).split(",")
  1322.   MMDB.showConnectionMgrDialog()
  1323.   PopulateConnectionList()
  1324.   var newConnectionIndex = getNewConnection(oldList, CONN_LIST.valueList)
  1325.   if (newConnectionIndex != -1)
  1326.   {
  1327.     CONN_LIST.setIndex(newConnectionIndex)
  1328.     ConnectionChanged()
  1329.   }
  1330. }
  1331.  
  1332.  
  1333. function IsConnectionSelected()
  1334. {
  1335.   
  1336.   var conn = CONN_LIST.getValue();
  1337.   if((conn == MM.LABEL_None) || (Trim(conn) == "") || (conn == MM.LABEL_EmptyOption))
  1338.   {
  1339.     alert(MM.MSG_NoConnection);
  1340.     return false;
  1341.   }
  1342.   return true;
  1343. }
  1344.  
  1345.  
  1346. function StoredProcButtons()
  1347. {
  1348.   disableTheButton(WHERE_BUTTON)
  1349.   disableTheButton(ORDERBY_BUTTON)
  1350.   SELECT_BUTTON.value = MM.LABEL_AddProc;
  1351. }
  1352.  
  1353.  
  1354. function NotStoredProcButtons()
  1355. {
  1356.   enableTheButton(WHERE_BUTTON)
  1357.   enableTheButton(ORDERBY_BUTTON)
  1358.   SELECT_BUTTON.value = MM.LABEL_AddSelect;
  1359. }
  1360.  
  1361.  
  1362. function enableTheButton(obj)
  1363. {
  1364.   var re1 = /(\s*|.*)(DISABLED="true" )(\s|.*)/
  1365.   var source = obj.outerHTML;
  1366.  
  1367.   if(source.search(re1) != -1)
  1368.   {
  1369.     source = RegExp.$1 + RegExp.$3
  1370.   }
  1371.  
  1372.   obj.outerHTML = source;
  1373. }
  1374.  
  1375.  
  1376. function disableTheButton(obj)
  1377. {
  1378.   var str = "DISABLED=\"true\" "
  1379.   var re1 = /(\s*|.*)(DISABLED="true" )(\s|.*)/i
  1380.   var re2 = /(\s*|.*)(NAME)(\s|.*)/i
  1381.   var source = obj.outerHTML;
  1382.  
  1383.   if(source.search(re1) == -1)
  1384.   {
  1385.     if(source.search(re2) != -1)
  1386.     {
  1387.       source = RegExp.$1 + str + RegExp.$2 + RegExp.$3
  1388.     }
  1389.   }
  1390.  
  1391.   obj.outerHTML = source;
  1392. }
  1393.  
  1394.  
  1395. function PopulateConnectionList()
  1396. {
  1397.   var oldConn = CONN_LIST.getValue()
  1398.  
  1399.   var connList = MMDB.getConnectionList()
  1400.  
  1401.   var wholeList = new Array()
  1402.  
  1403.   wholeList.push(MM.LABEL_None)
  1404.   for (var i = 0; i < connList.length; i++)
  1405.   {
  1406.     wholeList.push(connList[i])
  1407.   }
  1408.  
  1409.   CONN_LIST.setAll(wholeList, wholeList)
  1410.   CONN_LIST.setValue(MM.LABEL_None, 0)
  1411.  
  1412.   var index = CONN_LIST.getIndex(oldConn)
  1413.  
  1414.   if (!CONN_LIST.pickValue(oldConn)) 
  1415.   {
  1416.     if (CONN_LIST.getLen() == 2) 
  1417.     { 
  1418.       CONN_LIST.setIndex(1)
  1419.       ConnectionChanged()
  1420.     }
  1421.     else
  1422.     {
  1423.       CONN_LIST.setIndex(0)
  1424.     }
  1425.   } else { 
  1426.  
  1427.     //the database tree ctrl could be populated
  1428.     //already... so, it needs to be refreshed. The tree control will not 
  1429.     //refresh itself if the connection passed in is the same, so set it 
  1430.     //to a dummy value and then re-set the original connection. This will
  1431.     //force it to update the meta-data.
  1432.     TREE.setConnection("");
  1433.     TREE.setConnection(oldConn);
  1434.   }
  1435. }
  1436.  
  1437.  
  1438. function PlusMouseDown()
  1439. {
  1440.   PLUS_BUTTON.src = "../Shared/UltraDev/Images/PlusButtonDepressed.gif";
  1441. }
  1442.  
  1443.  
  1444. function PlusMouseUp()
  1445. {
  1446.   PLUS_BUTTON.src="../Shared/UltraDev/Images/PlusButton.gif";
  1447.   AddParam();
  1448. }
  1449.  
  1450.  
  1451. function MinusMouseDown()
  1452. {
  1453.   if(PARAM_LIST.getIndex() >= 0) {
  1454.   MINUS_BUTTON.src = "../Shared/UltraDev/Images/MinusButtonDepressed.gif";
  1455.   }
  1456. }
  1457.  
  1458.  
  1459. function MinusMouseUp()
  1460. {
  1461.   if(PARAM_LIST.getIndex() >= 0) {
  1462.   MINUS_BUTTON.src="../Shared/UltraDev/Images/MinusButtonEnabled.gif";
  1463.     DeleteParam();
  1464.   }
  1465. }
  1466.  
  1467.  
  1468. function receiveArguments(errorMsg) {
  1469.   ERROR_MESSAGE = errorMsg;
  1470. }
  1471.  
  1472.  
  1473. function addAndIsOkay(str)
  1474. {
  1475.   var tempStr = str.toUpperCase();
  1476.   var lt = str.length;
  1477.   
  1478.   var reIN = /\bis/gi;
  1479.   var reIS = /\bin/gi;
  1480.   var reNOT = /\bnot/gi;
  1481.   var reLIKE = /\blike/gi;
  1482.  
  1483.     if(tempStr.lastIndexOf(CONST_AND) == (tempStr.length - 4))
  1484.     return false;
  1485.   
  1486.   var substr2 = str.substr(str.length - 2, 2);
  1487.   var substr1 = str.substr(str.length - 1, 1);
  1488.  
  1489.     //Check for the mathematical operators <=, <> and >=
  1490.   if((substr2 == "<=") || (substr2 == ">=") || (substr2 == "<>"))
  1491.     return false;
  1492.  
  1493.   //Check for the mathematical operators =, <, and >
  1494.     if((substr1 == "=") || (substr1 == "<") || (substr1 == ">"))
  1495.     return false;
  1496.  
  1497.   if((str.search(reIS) == lt-2) || (str.search(reIN) == lt-2) || (str.search(reNOT) == lt-3) || (str.search(reLIKE) == lt-4))
  1498.     return false;  
  1499.  
  1500.   return true;
  1501. }
  1502.