Ejemplo n.º 1
0
        /// <summary>
        /// Build inline paremeterMap
        /// </summary>
        /// <param name="statement">The statement.</param>
        /// <param name="sqlCommandText">The SQL command text.</param>
        /// <param name="newSqlCommandText">The newsql command text.</param>
        /// <returns></returns>
        public ParameterMap BuildInlineParemeterMap(IStatement statement, string sqlCommandText, out string newSqlCommandText)
        {
            newSqlCommandText = sqlCommandText;
            ParameterMap map = null;

            // 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 = InlineParameterMapParser.ParseInlineParameterMap(modelStore.DataExchangeFactory, statement.Id, statement, newSqlCommandText);

                if (sqlText.Parameters.Length > 0)
                {
                    string        id           = statement.Id + "-InLineParameterMap";
                    string        className    = string.Empty;
                    Type          classType    = null;
                    IDataExchange dataExchange = null;

                    if (statement.ParameterClass != null)
                    {
                        className = statement.ParameterClass.Name;
                        classType = statement.ParameterClass;
                        //dataExchange = modelStore.DataExchangeFactory.GetDataExchangeForClass(classType);
                    }

                    if (statement.ParameterClass == null &&
                        sqlText.Parameters.Length == 1 && sqlText.Parameters[0].PropertyName == "value")    //#value# parameter with no parameterClass attribut
                    {
                        dataExchange = modelStore.DataExchangeFactory.GetDataExchangeForClass(typeof(int)); //Get the primitiveDataExchange
                    }
                    else
                    {
                        dataExchange = modelStore.DataExchangeFactory.GetDataExchangeForClass(statement.ParameterClass);
                    }

                    map = new ParameterMap(
                        id,
                        className,
                        string.Empty,
                        classType,
                        dataExchange,
                        modelStore.SessionFactory.DataSource.DbProvider.UsePositionalParameters
                        )
                    ;
                    int lenght = sqlText.Parameters.Length;
                    for (int index = 0; index < lenght; index++)
                    {
                        map.AddParameterProperty(sqlText.Parameters[index]);
                    }
                }
                newSqlCommandText = sqlText.Text;
            }

            if (statement is Procedure)
            {
                newSqlCommandText = newSqlCommandText.Replace(MARK_TOKEN, string.Empty).Replace(COMMA_TOKEN, string.Empty);
            }
            // newSqlCommandText = newSqlCommandText.Trim();

            return(map);
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Builds a new <see cref="RequestScope"/> and the <see cref="IDbCommand"/> text to execute.
		/// </summary>
		/// <param name="parameterObject">The parameter object (used in DynamicSql)</param>
		/// <param name="session">The current session</param>
		/// <param name="mappedStatement">The <see cref="IMappedStatement"/>.</param>
		/// <returns>A new <see cref="RequestScope"/>.</returns>
		public RequestScope GetRequestScope(IMappedStatement mappedStatement, 
			object parameterObject, ISqlMapSession session)
		{ 
			RequestScope request = new RequestScope( _dataExchangeFactory, session, _statement);

			_paramParser = new InlineParameterMapParser();

			string sqlStatement = Process(request, parameterObject);
			request.PreparedStatement = BuildPreparedStatement(session, request, sqlStatement);
			request.MappedStatement = mappedStatement;

			return request;
		}