Exemple #1
0
        /// <summary>
        /// add an odbc parameter, and replace the placeholders
        /// </summary>
        public void AddOdbcParameters(string APrefix, string AName, string APostfix, TVariant AValue)
        {
            if (IsVariant)
            {
                this.FSQLStmt = this.FVariantValue.ToString();
            }

            int pos            = 0;
            int parampos       = 0;
            int parameterIndex = 0;

            int wherePos = this.FSQLStmt.ToUpper().IndexOf(" WHERE ");

            pos = this.FSQLStmt.IndexOf(APrefix + AName + APostfix, pos);

            if (pos == -1)
            {
                return;
            }

            if (wherePos > pos)
            {
                TLogging.Log(this.FSQLStmt);
                throw new Exception("AddOdbcParameters: do not replace table names with odbc parameters");
            }

            while ((pos = this.FSQLStmt.IndexOf(APrefix + AName + APostfix, pos)) != -1)
            {
                while ((parampos != -1) && (parampos <= pos))
                {
                    parampos = this.FSQLStmt.IndexOf("PARAMETER?", parampos + 1);

                    if ((parampos != -1) && (parampos <= pos))
                    {
                        parameterIndex++;
                    }
                }
                pos++;
                parampos = pos;

                if (APrefix == "{")
                {
                    // force a string. needed for example for cost centre codes
                    AValue = new TVariant(AValue.ToString(), true);
                }

                this.FOdbcParameters.Insert(parameterIndex, AValue.ToOdbcParameter(AName));

                // we have added now a parameter, so this needs to be counted.
                // this is important if there are multiple occurances for the same parameter
                parameterIndex++;
            }

            this.FSQLStmt = this.FSQLStmt.Replace(APrefix + AName + APostfix, "PARAMETER?");
        }