コード例 #1
0
        void ISqlStringVisitor.Parameter(Parameter parameter)
        {
            if (hasReturnParameter && !foundReturnParameter)
            {
                result.Append(parameter);
                foundReturnParameter = true;
                return;
            }

            string name;

            if (queryIndexToNumberOfPreceedingParameters.Count == 0)
            {
                // there's only one query... no need to worry about indexes of parameters of previous queries
                name = formatter.GetParameterName(parameter.OriginalPositionInQuery ?? parameterIndex);
            }
            else
            {
                // multiple queries... in case the parameters were switched around (for SQL paging for instance) we need
                // to keep the number of preceeding parameters (in previous queries of the batch) into account
                if (parameter.OriginalPositionInQuery != null)
                {
                    name = formatter.GetParameterName(GetNumberOfPreceedingParameters() + parameter.OriginalPositionInQuery.Value);
                }
                else
                {
                    name = formatter.GetParameterName(parameterIndex);
                }
            }

            parameterIndex++;
            result.Append(name);
        }
コード例 #2
0
        void ISqlStringVisitor.Parameter(Parameter parameter)
        {
            if (hasReturnParameter && !foundReturnParameter)
            {
                result.Append(parameter);
                foundReturnParameter = true;
                return;
            }

            string name = formatter.GetParameterName(parameter.ParameterPosition ?? parameterIndex);

            parameterIndex++;
            result.Append(name);
        }
コード例 #3
0
        void ISqlStringVisitor.Parameter(Parameter parameter)
        {
            if (hasReturnParameter && !foundReturnParameter)
            {
                result.Append(parameter);
                assignedParameterNames.Add(String.Empty);
                foundReturnParameter = true;
                return;
            }

            // NH: even if using SqlType[] the final commad may have X parameters, with this line we will use Y parameters in the IDbCommand
            // for example the ParameterCollection may contains two parameters called @p0 and @p1 but the command contains just @p0.
            // In this way the same parameter can be used in different places in the query without create a problem to the dear SQL-server (see NH1981)
            // TODO: find a way to have exactly the same amount of parameters between the final IDbCommand and its IDataParameterCollection
            // A candidateplace is making DriverBase.SetCommandParameters a little bit more intelligent... perhaps SqlString aware (see also DriverBase.SetCommandText, DriverBase.GenerateCommand)
            string name = formatter.GetParameterName(parameter.ParameterPosition ?? parameterIndex);

            assignedParameterNames.Add(name);
            parameterIndex++;
            result.Append(name);
        }