Exemple #1
0
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>The created object</returns>
        object ICloneable.Clone()
        {
            JetCommand clone = new JetCommand();

            clone._Connection = this._Connection;

            clone._WrappedCommand = (DbCommand)((ICloneable)this._WrappedCommand).Clone();

            return(clone);
        }
Exemple #2
0
        public DbCommand CreateCommand(string commandText, int?commandTimeout = null)
        {
            if (string.IsNullOrEmpty(commandText))
            {
                // SqlCommand will complain if the command text is empty
                commandText = Environment.NewLine;
            }

            var command = new JetCommand(commandText, this);

            if (commandTimeout.HasValue)
            {
                command.CommandTimeout = commandTimeout.Value;
            }

            return(command);
        }
        /// <summary>
        /// Create a DbCommand object, given the provider manifest and command tree
        /// </summary>
        private DbCommand CreateCommand(DbProviderManifest manifest, DbCommandTree commandTree)
        {
            if (manifest == null)
            {
                throw new ArgumentNullException("manifest");
            }

            if (commandTree == null)
            {
                throw new ArgumentNullException("commandTree");
            }

            JetProviderManifest jetManifest = (manifest as JetProviderManifest);

            if (jetManifest == null)
            {
                throw new ArgumentException("The provider manifest given is not of type 'JetProviderManifest'.");
            }

            JetCommand command = new JetCommand();

            List <DbParameter> parameters;
            CommandType        commandType;

            command.CommandText = SqlGenerator.GenerateSql(commandTree, out parameters, out commandType);
            command.CommandType = commandType;

            //if (command.CommandType == CommandType.Text)
            //    command.CommandText += Environment.NewLine + Environment.NewLine + "-- provider: " + this.GetType().Assembly.FullName;

            // Get the function (if any) implemented by the command tree since this influences our interpretation of parameters
            EdmFunction function = null;

            if (commandTree is DbFunctionCommandTree)
            {
                function = ((DbFunctionCommandTree)commandTree).EdmFunction;
            }

            // Now make sure we populate the command's parameters from the CQT's parameters:
            foreach (KeyValuePair <string, TypeUsage> queryParameter in commandTree.Parameters)
            {
                OleDbParameter parameter;

                // Use the corresponding function parameter TypeUsage where available (currently, the SSDL facets and
                // type trump user-defined facets and type in the EntityCommand).
                FunctionParameter functionParameter;
                if (function != null && function.Parameters.TryGetValue(queryParameter.Key, false, out functionParameter))
                {
                    parameter = CreateJetParameter(functionParameter.Name, functionParameter.TypeUsage, functionParameter.Mode, DBNull.Value);
                }
                else
                {
                    parameter = CreateJetParameter(queryParameter.Key, queryParameter.Value, ParameterMode.In, DBNull.Value);
                }

                command.Parameters.Add(parameter);
            }

            // Now add parameters added as part of SQL gen (note: this feature is only safe for DML SQL gen which
            // does not support user parameters, where there is no risk of name collision)
            if (parameters != null && parameters.Count > 0)
            {
                if (!(commandTree is DbInsertCommandTree) &&
                    !(commandTree is DbUpdateCommandTree) &&
                    !(commandTree is DbDeleteCommandTree))
                {
                    throw new InvalidOperationException("SqlGenParametersNotPermitted");
                }

                foreach (DbParameter parameter in parameters)
                {
                    command.Parameters.Add(parameter);
                }
            }

            return(command);
        }