/// <summary>
		/// Parse Inline ParameterMap
		/// </summary>
		/// <param name="statement"></param>
		/// <param name="sqlStatement"></param>
		/// <returns>A new sql command text.</returns>
		/// <param name="scope"></param>
		public SqlText ParseInlineParameterMap(IScope scope, IStatement statement, string sqlStatement)
		{
			string newSql = sqlStatement;
			ArrayList mappingList = new ArrayList();
			Type parameterClassType = null;

			if (statement != null)
			{
				parameterClassType = statement.ParameterClass;
			}

			StringTokenizer parser = new StringTokenizer(sqlStatement, PARAMETER_TOKEN, true);
			StringBuilder newSqlBuffer = new StringBuilder();

			string token = null;
			string lastToken = null;

			IEnumerator enumerator = parser.GetEnumerator();

			while (enumerator.MoveNext()) 
			{
				token = (string)enumerator.Current;

				if (PARAMETER_TOKEN.Equals(lastToken)) 
				{
					if (PARAMETER_TOKEN.Equals(token)) 
					{
						newSqlBuffer.Append(PARAMETER_TOKEN);
						token = null;
					} 
					else 
					{
						ParameterProperty mapping = null; 
						if (token.IndexOf(PARAM_DELIM) > -1) 
						{
							mapping =  OldParseMapping(token, parameterClassType, scope);
						} 
						else 
						{
							mapping = NewParseMapping(token, parameterClassType, scope);
						}															 

						mappingList.Add(mapping);
						newSqlBuffer.Append("? ");

						enumerator.MoveNext();
						token = (string)enumerator.Current;
						if (!PARAMETER_TOKEN.Equals(token)) 
						{
							throw new DataMapperException("Unterminated inline parameter in mapped statement (" + statement.Id + ").");
						}
						token = null;
					}
				} 
				else 
				{
					if (!PARAMETER_TOKEN.Equals(token)) 
					{
						newSqlBuffer.Append(token);
					}
				}

				lastToken = token;
			}

			newSql = newSqlBuffer.ToString();

			ParameterProperty[] mappingArray = (ParameterProperty[]) mappingList.ToArray(typeof(ParameterProperty));

			SqlText sqlText = new SqlText();
			sqlText.Text = newSql;
			sqlText.Parameters = mappingArray;

			return sqlText;
		}
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <param name="ctx"></param>
        /// <param name="parameterObject"></param>
        /// <param name="localChildren"></param>
        /// <param name="buffer"></param>
        private void ProcessBodyChildren(RequestScope request, SqlTagContext ctx,
                                         object parameterObject, IEnumerator localChildren, StringBuilder buffer)
        {
            while (localChildren.MoveNext())
            {
                ISqlChild child = (ISqlChild)localChildren.Current;

                if (child is SqlText)
                {
                    SqlText sqlText      = (SqlText)child;
                    string  sqlStatement = sqlText.Text;
                    if (sqlText.IsWhiteSpace)
                    {
                        buffer.Append(sqlStatement);
                    }
                    else
                    {
//						if (SimpleDynamicSql.IsSimpleDynamicSql(sqlStatement))
//						{
//							sqlStatement = new SimpleDynamicSql(sqlStatement, _statement).GetSql(parameterObject);
//							SqlText newSqlText = _paramParser.ParseInlineParameterMap( null, sqlStatement );
//							sqlStatement = newSqlText.Text;
//							ParameterProperty[] mappings = newSqlText.Parameters;
//							if (mappings != null)
//							{
//								for (int i = 0; i < mappings.Length; i++)
//								{
//									ctx.AddParameterMapping(mappings[i]);
//								}
//							}
//						}
                        // BODY OUT
                        buffer.Append(" ");
                        buffer.Append(sqlStatement);

                        ParameterProperty[] parameters = sqlText.Parameters;
                        if (parameters != null)
                        {
                            int length = parameters.Length;
                            for (int i = 0; i < length; i++)
                            {
                                ctx.AddParameterMapping(parameters[i]);
                            }
                        }
                    }
                }
                else if (child is SqlTag)
                {
                    SqlTag         tag      = (SqlTag)child;
                    ISqlTagHandler handler  = tag.Handler;
                    int            response = BaseTagHandler.INCLUDE_BODY;

                    do
                    {
                        StringBuilder body = new StringBuilder();

                        response = handler.DoStartFragment(ctx, tag, parameterObject);
                        if (response != BaseTagHandler.SKIP_BODY)
                        {
                            if (ctx.IsOverridePrepend &&
                                ctx.FirstNonDynamicTagWithPrepend == null &&
                                tag.IsPrependAvailable &&
                                !(tag.Handler is DynamicTagHandler))
                            {
                                ctx.FirstNonDynamicTagWithPrepend = tag;
                            }

                            ProcessBodyChildren(request, ctx, parameterObject, tag.GetChildrenEnumerator(), body);

                            response = handler.DoEndFragment(ctx, tag, parameterObject, body);
                            handler.DoPrepend(ctx, tag, parameterObject, body);
                            if (response != BaseTagHandler.SKIP_BODY)
                            {
                                if (body.Length > 0)
                                {
                                    // BODY OUT

                                    if (handler.IsPostParseRequired)
                                    {
                                        SqlText sqlText = _paramParser.ParseInlineParameterMap(request, null, body.ToString());
                                        buffer.Append(sqlText.Text);
                                        ParameterProperty[] mappings = sqlText.Parameters;
                                        if (mappings != null)
                                        {
                                            int length = mappings.Length;
                                            for (int i = 0; i < length; i++)
                                            {
                                                ctx.AddParameterMapping(mappings[i]);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        buffer.Append(" ");
                                        buffer.Append(body.ToString());
                                    }
                                    if (tag.IsPrependAvailable && tag == ctx.FirstNonDynamicTagWithPrepend)
                                    {
                                        ctx.IsOverridePrepend = false;
                                    }
                                }
                            }
                        }
                    }while (response == BaseTagHandler.REPEAT_BODY);
                }
            }
        }