Ejemplo n.º 1
0
        private bool InitializeCommand(CommandBehavior behavior, bool throwifnotsupported)
        {
            Debug.Assert(null != _connection, "InitializeCommand: null OleDbConnection");

            int changeid = _changeID;

            if ((0 != (CommandBehavior.KeyInfo & (this.commandBehavior ^ behavior))) || (_lastChangeID != changeid))
            {
                CloseInternalParameters(); // could optimize out
                CloseInternalCommand();
            }
            this.commandBehavior = behavior;
            changeid             = _changeID;

            if (!PropertiesOnCommand(false))
            {
                return(false);
            }

            if ((null != _dbBindings) && _dbBindings.AreParameterBindingsInvalid(_parameters))
            {
                CloseInternalParameters();
            }

            // if we already having bindings - don't create the accessor
            // if _parameters is null - no parameters exist - don't create the collection
            // do we actually have parameters since the collection exists
            if ((null == _dbBindings) && HasParameters())
            {
                // if we setup the parameters before setting cmdtxt then named parameters can happen
                CreateAccessor();
            }

            if (_lastChangeID != changeid)
            {
                OleDbHResult hr;

                string commandText = ExpandCommandText();

                hr = _icommandText.SetCommandText(ref ODB.DBGUID_DEFAULT, commandText);

                if (hr < 0)
                {
                    ProcessResults(hr);
                }
            }

            _lastChangeID = changeid;

            return(true);
        }