Ejemplo n.º 1
0
        private void BuildDbParameters(AbstractRequestContext reqConetxt)
        {
            var dbParameterNames = _sqlParamAnalyzer.Analyse(reqConetxt.RealSql);

            if (reqConetxt.CommandType == CommandType.StoredProcedure)
            {
                foreach (var sqlParameter in reqConetxt.Parameters.Values)
                {
                    var sourceParam = _dbProviderFactory.CreateParameter();
                    sourceParam.ParameterName    = sqlParameter.Name;
                    sourceParam.Value            = sqlParameter.Value;
                    sqlParameter.SourceParameter = sourceParam;
                    InitSourceDbParameter(sourceParam, sqlParameter);
                }
            }
            else
            {
                foreach (var paramName in dbParameterNames)
                {
                    var          parameter    = reqConetxt.ParameterMap?.GetParameter(paramName);
                    var          propertyName = paramName;
                    ITypeHandler typeHandler  = null;
                    if (parameter != null)
                    {
                        propertyName = parameter.Property;
                        typeHandler  = parameter.Handler;
                    }

                    if (!reqConetxt.Parameters.TryGetValue(propertyName, out var sqlParameter))
                    {
                        continue;
                    }

                    var sourceParam = _dbProviderFactory.CreateParameter();
                    sourceParam.ParameterName = paramName;

                    if (typeHandler == null)
                    {
                        typeHandler = sqlParameter.TypeHandler ??
                                      _typeHandlerFactory.GetTypeHandler(sqlParameter.ParameterType);
                    }

                    typeHandler.SetParameter(sourceParam, sqlParameter.Value);
                    sqlParameter.SourceParameter = sourceParam;
                    InitSourceDbParameter(sourceParam, sqlParameter);
                }
            }
        }
Ejemplo n.º 2
0
        public void Analyse_NonParam()
        {
            var result = _sqlParamAnalyzer.Analyse("Sp_QueryByPage");

            Assert.Empty(result);
        }
Ejemplo n.º 3
0
 public void Analyse()
 {
     var paramStrs = _sqlParamAnalyzer.Analyse("@Good,@Yes.Good").ToArray();
 }