Exemplo n.º 1
0
        /// <summary>
        /// For store procedure, auto discover IDataParameters for stored procedures at run-time.
        /// </summary>
        /// <param name="session">The current session.</param>
        private void DiscoverParameter(ISqlMapSession session)
        {
            // pull the parameters for this stored procedure from the parameter cache
            // (or discover them & populate the cache)
            IDataParameter[] commandParameters = DBHelperParameterCache.GetSpParameterSet(session, _commandText);

            _preparedStatement.DbParameters = new IDbDataParameter[commandParameters.Length];

            int start = session.DataSource.DbProvider.ParameterPrefix.Length;

            for (int i = 0; i < commandParameters.Length; i++)
            {
                IDbDataParameter dataParameter = (IDbDataParameter)commandParameters[i];

                if (session.DataSource.DbProvider.UseParameterPrefixInParameter == false)
                {
                    if (dataParameter.ParameterName.StartsWith(session.DataSource.DbProvider.ParameterPrefix))
                    {
                        dataParameter.ParameterName = dataParameter.ParameterName.Substring(start);
                    }
                }
                _preparedStatement.DbParametersName.Add(dataParameter.ParameterName);
                _preparedStatement.DbParameters[i] = dataParameter;
            }

            // Re-sort DbParameters to match order used in the parameterMap
            IDbDataParameter[] sortedDbParameters = new IDbDataParameter[commandParameters.Length];
            for (int i = 0; i < _statement.ParameterMap.Properties.Count; i++)
            {
                sortedDbParameters[i] = Search(session, _preparedStatement.DbParameters, _statement.ParameterMap.Properties[i], i);
            }
            _preparedStatement.DbParameters = sortedDbParameters;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StaticSql"/> class.
        /// </summary>
        /// <param name="dataExchangeFactory">The data exchange factory.</param>
        /// <param name="dbHelperParameterCache">The db helper parameter cache.</param>
        /// <param name="statement">The statement.</param>
        public StaticSql(
            DataExchangeFactory dataExchangeFactory,
            DBHelperParameterCache dbHelperParameterCache,
            IStatement statement)
        {
            Contract.Require.That(dataExchangeFactory, Is.Not.Null).When("retrieving argument dataExchangeFactory in StaticSql constructor");
            Contract.Require.That(dbHelperParameterCache, Is.Not.Null).When("retrieving argument dbHelperParameterCache in StaticSql constructor");
            Contract.Require.That(statement, Is.Not.Null).When("retrieving argument statement in StaticSql constructor");

            this.statement              = statement;
            this.dataExchangeFactory    = dataExchangeFactory;
            this.dbHelperParameterCache = dbHelperParameterCache;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExternalSql"/> class.
        /// </summary>
        /// <param name="modelStore">The model store.</param>
        /// <param name="statement">The statement.</param>
        /// <param name="commandText">The command text.</param>
        public ExternalSql(
            IModelStore modelStore,
            IStatement statement,
            string commandText)
        {
            Contract.Require.That(modelStore, Is.Not.Null).When("retrieving argument modelStore in ExternalSql constructor");
            Contract.Require.That(statement, Is.Not.Null).When("retrieving argument statement in ExternalSql constructor");

            this.statement         = statement;
            this.commandText       = commandText;
            dataExchangeFactory    = modelStore.DataExchangeFactory;
            dbHelperParameterCache = modelStore.DBHelperParameterCache;

            inlineParemeterMapBuilder = new InlineParemeterMapBuilder(modelStore);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DynamicSql"/> class.
        /// </summary>
        /// <param name="usePositionalParameters">if set to <c>true</c> [use positional parameters].</param>
        /// <param name="dbHelperParameterCache">The db helper parameter cache.</param>
        /// <param name="dataExchangeFactory">The data exchange factory.</param>
        /// <param name="statement">The statement.</param>
        public DynamicSql(
            bool usePositionalParameters,
            DBHelperParameterCache dbHelperParameterCache,
            DataExchangeFactory dataExchangeFactory,
            IStatement statement)
        {
            Contract.Require.That(dataExchangeFactory, Is.Not.Null).When("retrieving argument dataExchangeFactory in DynamicSql constructor");
            Contract.Require.That(dbHelperParameterCache, Is.Not.Null).When("retrieving argument dbHelperParameterCache in DynamicSql constructor");
            Contract.Require.That(statement, Is.Not.Null).When("retrieving argument statement in DynamicSql constructor");

            this.statement = statement;
            this.usePositionalParameters = usePositionalParameters;
            this.dataExchangeFactory     = dataExchangeFactory;
            this.dbHelperParameterCache  = dbHelperParameterCache;
            paramParser = new InlineParameterMapParser();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleDynamicSql"/> class.
        /// </summary>
        /// <param name="dataExchangeFactory">The data exchange factory.</param>
        /// <param name="dbHelperParameterCache">The db helper parameter cache.</param>
        /// <param name="sqlStatement">The SQL statement.</param>
        /// <param name="statement">The statement.</param>
        public SimpleDynamicSql(
            DataExchangeFactory dataExchangeFactory,
            DBHelperParameterCache dbHelperParameterCache,
            string sqlStatement,
            IStatement statement)
        {
            Contract.Require.That(dataExchangeFactory, Is.Not.Null).When("retrieving argument dataExchangeFactory in SimpleDynamicSql constructor");
            Contract.Require.That(dbHelperParameterCache, Is.Not.Null).When("retrieving argument dbHelperParameterCache in SimpleDynamicSql constructor");
            Contract.Require.That(statement, Is.Not.Null).When("retrieving argument statement in SimpleDynamicSql constructor");
            Contract.Require.That(sqlStatement, Is.Not.Null & Is.Not.Empty).When("retrieving argument sqlStatement in SimpleDynamicSql constructor");

            this.sqlStatement           = sqlStatement;
            this.statement              = statement;//sql语句 包含一些参数符号 ? $
            this.dataExchangeFactory    = dataExchangeFactory;
            this.dbHelperParameterCache = dbHelperParameterCache;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PreparedStatementFactory"/> class.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="dbHelperParameterCache">The db helper parameter cache.</param>
        /// <param name="request">The request.</param>
        /// <param name="statement">The statement.</param>
        /// <param name="commandText">The command text.</param>
        public PreparedStatementFactory(
            ISession session,
            DBHelperParameterCache dbHelperParameterCache,
            RequestScope request,
            IStatement statement,
            string commandText)
        {
            Contract.Require.That(session, Is.Not.Null).When("retrieving argument session using statement '" + statement.Id + "' in PreparedStatementFactory constructor");
            Contract.Require.That(dbHelperParameterCache, Is.Not.Null).When("retrieving argument dBHelperParameterCache using statement '" + statement.Id + "' in PreparedStatementFactory constructor");
            Contract.Require.That(request, Is.Not.Null).When("retrieving argument request using statement '" + statement.Id + "' in PreparedStatementFactory constructor");
            Contract.Require.That(statement, Is.Not.Null).When("retrieving argument statement using statement '" + statement.Id + "' in PreparedStatementFactory constructor");
            Contract.Require.That(commandText, Is.Not.Null & Is.Not.Empty).When("retrieving argument commandText using statement '" + statement.Id + "' in PreparedStatementFactory constructor");

            this.session                = session;
            this.request                = request;
            this.statement              = statement;
            this.commandText            = commandText;
            this.dbHelperParameterCache = dbHelperParameterCache;

            dbProvider      = session.SessionFactory.DataSource.DbProvider;
            parameterPrefix = dbProvider.ParameterPrefix;
        }