Esempio n. 1
0
 public IDbCommand Convert(Command commonCommand)
 {
     if (commonCommand != null)
     {
         IDbCommand dbCommand = this.connection.CreateCommand();
         dbCommand.CommandType = commonCommand.CommandType;
         string commandText = commonCommand.CommandText;
         foreach (Parameter commonParameter in commonCommand.Parameters)
         {
             string parameterName = ReplaceParameterName(ref commandText, commonParameter.ParameterName, commonCommand.ParameterPrefix, commonCommand.UseParameterPrefixInParameter, commonCommand.UseParameterPrefixInSql);
             System.Data.IDbDataParameter parameter = dbCommand.CreateParameter();
             if (commonParameter.Direction != this.direction)
             {
                 parameter.Direction = commonParameter.Direction;
             }
             if (commonParameter.DbType != this.dbType)
             {
                 parameter.DbType = commonParameter.DbType;
                 parameter.Size = commonParameter.Size;
                 parameter.Scale = commonParameter.Scale;
                 parameter.Precision = commonParameter.Precision;
             }
             if (commonParameter.SourceVersion != this.sourceVersion)
             {
                 parameter.SourceVersion = commonParameter.SourceVersion;
             }
             parameter.ParameterName = parameterName;
             object value = commonParameter.Value;
             if (value == null)
             {
                 parameter.Value = System.DBNull.Value;
             }
             else
             {
                 parameter.Value = value;
             }
             dbCommand.Parameters.Add(parameter);
         }
         dbCommand.CommandText = commandText;
         return dbCommand;
     }
     return null;
 }
Esempio n. 2
0
 public object ExecuteScalar(Command command)
 {
     IDbCommand dbCommand = this.commandConverter.Convert(command);
     var result = this.ExecuteScalar(dbCommand);
     this.commandConverter.FeedbackParameters(ref command, dbCommand);
     return result;
 }
Esempio n. 3
0
 public IDataReader ExecuteReader(Command command)
 {
     IDbCommand dbCommand = this.commandConverter.Convert(command);
     var result = this.ExecuteReader(dbCommand);
     this.commandConverter.FeedbackParameters(ref command, dbCommand);
     return result;
 }
Esempio n. 4
0
 public int ExecuteNonQuery(Command command)
 {
     IDbCommand dbCommand = this.commandConverter.Convert(command);
     var result = this.ExecuteNonQuery(dbCommand);
     this.commandConverter.FeedbackParameters(ref command, dbCommand);
     return result;
 }
Esempio n. 5
0
 public static Command GetCommand(string name)
 {
     CommandElement commandElement = Default.CommandElements[name];
     if (commandElement != null)
     {
         Command command = new Command
         {
             CommandText = commandElement.CommandText.Value != null ? commandElement.CommandText.Value.Trim() : null,
             CommandType = commandElement.CommandType,
             CommandTimeout = commandElement.CommandTimeout,
             ParameterPrefix = commandElement.ParameterPrefix,
             UseParameterPrefixInSql = commandElement.UseParameterPrefixInSql,
             UseParameterPrefixInParameter = commandElement.UseParameterPrefixInParameter,
             UseBrackets = commandElement.UseBrackets
         };
         foreach (ParameterElement parameterElement in commandElement.Parameters)
         {
             Parameter parameter = new Parameter
             {
                 ParameterName = parameterElement.ParameterName,
                 DbType = parameterElement.DbType,
                 Value = parameterElement.Value,
                 IsNullable = parameterElement.IsNullable,
                 SourceVersion = parameterElement.SourceVersion,
                 SourceColumn = parameterElement.SourceColumn,
                 SourceColumnNullMapping = parameterElement.SourceColumnNullMapping,
                 Precision = parameterElement.Precision,
                 Scale = parameterElement.Scale,
                 Size = parameterElement.Size
             };
             command.Parameters.Add(parameter);
         }
         return command;
     }
     return null;
 }
Esempio n. 6
0
 public CommandSegment(Command command, CommandSegmentType segmentType)
 {
     this.Command = command;
     this.SegmentType = segmentType;
 }
Esempio n. 7
0
 public void FeedbackParameters(ref Command commonCommand, System.Data.IDbCommand command)
 {
     if (command.Parameters != null)
     {
         for (int i = 0; i < command.Parameters.Count; i++)
         {
             System.Data.IDbDataParameter parameter = command.Parameters[i] as System.Data.IDbDataParameter;
             if (parameter.Direction != System.Data.ParameterDirection.Input)
             {
                 commonCommand.Parameters[i].Value = parameter.Value;
             }
         }
     }
 }