private static SampleCommand CreateCommand(SampleConnection connection, string commandText, int?commandTimeout) { Debug.Assert(connection != null); if (string.IsNullOrEmpty(commandText)) { // SqlCommand will complain if the command text is empty commandText = Environment.NewLine; } var command = new SampleCommand(commandText, connection); if (commandTimeout.HasValue) { command.CommandTimeout = commandTimeout.Value; } return(command); }
object ICloneable.Clone() { SampleCommand clone = new SampleCommand(); clone._Connection = this._Connection; //Defer to the Clone method on the wrapped SqlCommand clone._WrappedCommand = (DbCommand)((ICloneable)this._WrappedCommand).Clone(); ////An alternate approach is to create a new instance of the Command and ////set values of the properties of the new Command to the corresponding ////properties of the original command, using code like: //clone.Connection = this.Connection; //clone.CommandText = this.CommandText; //clone.CommandType = this.CommandType; //clone.CommandTimeout = this.CommandTimeout; //clone.DesignTimeVisible = this.DesignTimeVisible; //clone.Transaction = this.Transaction; //clone.UpdatedRowSource = this.UpdatedRowSource; //foreach (DbParameter p in this.Parameters) // clone.Parameters.Add((DbParameter) ((ICloneable)p).Clone()); return clone; }
object ICloneable.Clone() { SampleCommand clone = new SampleCommand(); clone._Connection = this._Connection; //Defer to the Clone method on the wrapped SqlCommand clone._WrappedCommand = (DbCommand)((ICloneable)this._WrappedCommand).Clone(); ////An alternate approach is to create a new instance of the Command and ////set values of the properties of the new Command to the corresponding ////properties of the original command, using code like: //clone.Connection = this.Connection; //clone.CommandText = this.CommandText; //clone.CommandType = this.CommandType; //clone.CommandTimeout = this.CommandTimeout; //clone.DesignTimeVisible = this.DesignTimeVisible; //clone.Transaction = this.Transaction; //clone.UpdatedRowSource = this.UpdatedRowSource; //foreach (DbParameter p in this.Parameters) // clone.Parameters.Add((DbParameter) ((ICloneable)p).Clone()); return(clone); }
private static SampleCommand CreateCommand(SampleConnection connection, string commandText, int? commandTimeout) { Debug.Assert(connection != null); if (string.IsNullOrEmpty(commandText)) { // SqlCommand will complain if the command text is empty commandText = Environment.NewLine; } var command = new SampleCommand(commandText, connection); if (commandTimeout.HasValue) { command.CommandTimeout = commandTimeout.Value; } return command; }
/// <summary> /// Create a SampleCommand 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"); SampleProviderManifest sampleManifest = (manifest as SampleProviderManifest); if (sampleManifest == null) { throw new ArgumentException("The provider manifest given is not of type 'SampleProviderManifest'."); } StoreVersion version = sampleManifest.Version; SampleCommand command = new SampleCommand(); List<DbParameter> parameters; CommandType commandType; command.CommandText = SqlGenerator.GenerateSql(commandTree, version, 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) { SqlParameter 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 (null != function && function.Parameters.TryGetValue(queryParameter.Key, false, out functionParameter)) { parameter = CreateSqlParameter(functionParameter.Name, functionParameter.TypeUsage, functionParameter.Mode, DBNull.Value); } else { parameter = CreateSqlParameter(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 (null != parameters && 0 < parameters.Count) { 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; }
/// <summary> /// Create a SampleCommand 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"); } SampleProviderManifest sampleManifest = (manifest as SampleProviderManifest); if (sampleManifest == null) { throw new ArgumentException("The provider manifest given is not of type 'SampleProviderManifest'."); } StoreVersion version = sampleManifest.Version; SampleCommand command = new SampleCommand(); List <DbParameter> parameters; CommandType commandType; command.CommandText = SqlGenerator.GenerateSql(commandTree, version, 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) { SqlParameter 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 (null != function && function.Parameters.TryGetValue(queryParameter.Key, false, out functionParameter)) { parameter = CreateSqlParameter(functionParameter.Name, functionParameter.TypeUsage, functionParameter.Mode, DBNull.Value); } else { parameter = CreateSqlParameter(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 (null != parameters && 0 < parameters.Count) { 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); }