示例#1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="request"></param>
        /// <param name="parameterObject"></param>
        /// <returns></returns>
        private string Process(RequestScope request, object parameterObject)
        {
            SqlTagContext ctx = new SqlTagContext();
            IList localChildren = _children;

            ProcessBodyChildren(request, ctx, parameterObject, localChildren);

            // Builds a 'dynamic' ParameterMap
            ParameterMap map = new ParameterMap(request.DataExchangeFactory);
            map.Id = _statement.Id + "-InlineParameterMap";
            map.Initialize(_usePositionalParameters, request);
            map.Class = _statement.ParameterClass;

            // Adds 'dynamic' ParameterProperty
            IList parameters = ctx.GetParameterMappings();
            int count = parameters.Count;
            for(int i=0;i<count;i++)
            {
                map.AddParameterProperty( (ParameterProperty)parameters[i] );
            }
            request.ParameterMap = map;

            string dynSql = ctx.BodyText;

            // Processes $substitutions$ after DynamicSql
            if ( SimpleDynamicSql.IsSimpleDynamicSql(dynSql) )
            {
                dynSql = new SimpleDynamicSql(request, dynSql, _statement).GetSql(parameterObject);
            }
            return dynSql;
        }
        /// <summary>
        /// Apply inline paremeterMap
        /// </summary>
        /// <param name="statement"></param>
        /// <param name="sqlStatement"></param>
        private void ApplyInlineParemeterMap( IStatement statement, string sqlStatement)
        {
            string newSql = sqlStatement;

            _configScope.ErrorContext.MoreInfo = "apply inline parameterMap";

            // Check the inline parameter
            if (statement.ParameterMap == null)
            {
                // Build a Parametermap with the inline parameters.
                // if they exist. Then delete inline infos from sqltext.

                SqlText sqlText = _paramParser.ParseInlineParameterMap(_configScope,  statement, newSql );

                if (sqlText.Parameters.Length > 0)
                {
                    ParameterMap map = new ParameterMap(_configScope.DataExchangeFactory);
                    map.Id = statement.Id + "-InLineParameterMap";
                    if (statement.ParameterClass!=null)
                    {
                        map.Class = statement.ParameterClass;
                    }
                    map.Initialize(_configScope.DataSource.DbProvider.UsePositionalParameters,_configScope);
                    if (statement.ParameterClass==null &&
                        sqlText.Parameters.Length==1 && sqlText.Parameters[0].PropertyName=="value")//#value# parameter with no parameterClass attribut
                    {
                        map.DataExchange = _configScope.DataExchangeFactory.GetDataExchangeForClass( typeof(int) );//Get the primitiveDataExchange
                    }
                    statement.ParameterMap = map;

                    int lenght = sqlText.Parameters.Length;
                    for(int index=0;index<lenght;index++)
                    {
                        map.AddParameterProperty( sqlText.Parameters[index] );
                    }
                }
                newSql = sqlText.Text;
            }

            ISql sql = null;

            newSql = newSql.Trim();

            if (SimpleDynamicSql.IsSimpleDynamicSql(newSql))
            {
                sql = new SimpleDynamicSql(_configScope, newSql, statement);
            }
            else
            {
                if (statement is Procedure)
                {
                    sql = new ProcedureSql(_configScope, newSql, statement);
                    // Could not call BuildPreparedStatement for procedure because when NUnit Test
                    // the database is not here (but in theory procedure must be prepared like statement)
                    // It's even better as we can then switch DataSource.
                }
                else if (statement is Statement)
                {
                    sql = new StaticSql(_configScope, statement);
                    ISqlMapSession session = new SqlMapSession(_configScope.SqlMapper);

                    ((StaticSql)sql).BuildPreparedStatement( session, newSql );
                }
            }
            statement.Sql = sql;
        }