/// <summary>
        /// replace parameters with ? and collect non-unique parameter names in paramMap
        /// </summary>
        /// <param name="sSQL">the SQL string to parse, it can be any part of SQL</param>
        /// <param name="paramList">for validation. parameter names must be in this list</param>
        /// <param name="paramMap">this list is filled with the non-unique parameter names</param>
        /// <returns>the SQL string with parameters replaced with ?</returns>
        public static string MapParameters(string sSQL, EnumParameterStyle paramStyle, string sepStart, string sepEnd, FieldList paramList, FieldList paramMap, ParameterList psOld)
        {
            if (sSQL == null)
            {
                sSQL = "";
            }
            string S = sSQL;

            if (S.Length > 0)
            {
                string  name;
                EPField fld;
                int     n = SQLParser.FindParameterIndex(S, 0, sepStart, sepEnd, out ParseError);
                while (n >= 0)
                {
                    int i = SQLParser.FindNameEnd(S, n);
                    name = S.Substring(n, i - n);
                    name = name.Trim();
                    if (paramStyle == EnumParameterStyle.QuestionMark)
                    {
                        S = string.Format(CultureInfo.InvariantCulture, "{0}? {1}", S.Substring(0, n), S.Substring(i));
                        n++;
                    }
                    else if (paramStyle == EnumParameterStyle.LeadingQuestionMark)
                    {
                        string pname = ParameterList.GetParameterName(paramStyle, name);
                        S  = string.Format(CultureInfo.InvariantCulture, "{0}{1} {2}", S.Substring(0, n), pname, S.Substring(i));
                        n += pname.Length + 1;
                    }
                    else
                    {
                        n += name.Length + 1;
                    }
                    fld = paramList[name];
                    if (fld == null)
                    {
                        EPField f0 = null;
                        if (psOld != null && psOld.Count > 0)
                        {
                            f0 = psOld[name];
                        }
                        if (f0 == null)
                        {
                            fld = new EPField(paramList.Count, name);
                        }
                        else
                        {
                            fld       = f0.Clone() as EPField;
                            fld.Index = paramList.Count;
                        }
                        paramList.Add(fld);
                    }
                    if (paramStyle == EnumParameterStyle.QuestionMark)
                    {
                        //non-unique name is added
                        paramMap.AddFieldDup(fld);
                    }
                    n = SQLParser.FindParameterIndex(S, n, sepStart, sepEnd, out ParseError);
                }
            }
            return(S);
        }