Beispiel #1
0
        private static IDbDataParameter CreateSingleParameter(IDbParameterFactory parameterFactory, object value, ParameterTemplate template)
        {
            if (template.Column != null)
            {
                return(CreateSingleParameter(parameterFactory, value, template.Name, template.Column));
            }

            var parameter = default(IDbDataParameter);

            if (template.Type == ParameterType.NameOnly)
            {
                parameter = parameterFactory.CreateParameter(template.Name);
            }
            else
            {
                parameter = parameterFactory.CreateParameter(template.Name, template.DbType, template.MaxLength);
            }
            parameter.Value = CommandHelper.FixObjectType(value);
            return(parameter);
        }
Beispiel #2
0
        private static void SetParameters(IDbParameterFactory parameterFactory, IDbCommand command, IEnumerable <KeyValuePair <ParameterTemplate, object> > parameters)
        {
            var parameterList = parameters.ToList();

            if (parameterList.Any(kvp => kvp.Value is IRange) ||
                parameterList.Any(kvp => kvp.Value is IEnumerable && !(kvp.Value is string)))
            {
                foreach (var pair in parameterList)
                {
                    foreach (var parameter in CreateParameterComplex(parameterFactory, pair.Key, pair.Value, command))
                    {
                        command.Parameters.Add(parameter);
                    }
                }
            }
            else
            {
                foreach (var pair in parameterList)
                {
                    command.Parameters.Add(CreateSingleParameter(parameterFactory, pair.Value, pair.Key));
                }
            }
        }
Beispiel #3
0
 public Users_DeleteAll(IDbCommandExecuter executer, IDbParameterFactory parameterFactory)
     : base(executer, parameterFactory)
 {
 }
 internal static IDbCommand CreateCommand(IDbParameterFactory parameterFactory, ICommandBuilder[] commandBuilders, IDbConnection connection)
 {
     var command = connection.CreateCommand();
     parameterFactory = parameterFactory ?? new GenericDbParameterFactory(command);
     for (int i = 0; i < commandBuilders.Length; i++)
     {
         if (!string.IsNullOrWhiteSpace(command.CommandText)) command.CommandText += "; ";
         command.CommandText += commandBuilders[i].Text;
         SetParameters(parameterFactory, command, commandBuilders[i].Parameters);
     }
     return command;
 }
 private static IDbDataParameter CreateSingleParameter(IDbParameterFactory parameterFactory, object value, string name, Column column)
 {
     var parameter = parameterFactory.CreateParameter(name, column);
     parameter.Value = CommandHelper.FixObjectType(value);
     return parameter;
 }
        private static IDbDataParameter CreateSingleParameter(IDbParameterFactory parameterFactory, object value, ParameterTemplate template)    
        {
            if (template.Column != null) return CreateSingleParameter(parameterFactory, value, template.Name, template.Column);

            var parameter = parameterFactory.CreateParameter(template.Name, template.DbType, template.MaxLength);
            parameter.Value = CommandHelper.FixObjectType(value);
            return parameter;
        }
 private static IEnumerable<IDbDataParameter> CreateParameterComplex(IDbParameterFactory parameterFactory, ParameterTemplate template, object value, IDbCommand command)
 {
     if (template.Column != null && template.Column.IsBinary)
     {
         yield return CreateSingleParameter(parameterFactory, value, template.Name, template.Column);
     }
     else
     {
         var str = value as string;
         if (str != null)
         {
             yield return CreateSingleParameter(parameterFactory, value, template.Name, template.Column);
         }
         else
         {
             var range = value as IRange;
             if (range != null)
             {
                 yield return
                     CreateSingleParameter(parameterFactory, range.Start, template.Name + "_start", template.Column);
                 yield return CreateSingleParameter(parameterFactory, range.End, template.Name + "_end", template.Column);
                 SetBetweenInCommandText(command, template.Name);
             }
             else
             {
                 var list = value as IEnumerable;
                 if (list != null)
                 {
                     var builder = new StringBuilder();
                     var array = list.Cast<object>().ToArray();
                     for (int i = 0; i < array.Length; i++)
                     {
                         builder.AppendFormat(",{0}_{1}", template.Name, i);
                         yield return
                             CreateSingleParameter(parameterFactory, array[i], template.Name + "_" + i, template.Column);
                     }
                     if (command.CommandText.Contains("!= " + template.Name))
                     {
                         command.CommandText = command.CommandText.Replace("!= " + template.Name,
                                                                           "NOT IN (" +
                                                                           builder.ToString().Substring(1) + ")");
                     }
                     else
                     {
                         command.CommandText = command.CommandText.Replace("= " + template.Name,
                                                                           "IN (" +
                                                                           builder.ToString().Substring(1) +
                                                                           ")");
                     }
                 }
                 else
                 {
                     yield return CreateSingleParameter(parameterFactory, value, template);
                 }
             }
         }
     }
 }
Beispiel #8
0
 public User_IsActive(IDbCommandExecuter executer, IDbParameterFactory parameterFactory)
     : base(executer, parameterFactory)
 {
 }
        private static IDbDataParameter CreateSingleParameter(IDbParameterFactory parameterFactory, object value, ParameterTemplate template)    
        {
            if (template.Column != null)
            {
                return CreateSingleParameter(parameterFactory, value, template.Name, template.Column);
            }

            var parameter = default(IDbDataParameter);
            if (template.Type == ParameterType.NameOnly)
            {
                parameter = parameterFactory.CreateParameter(template.Name);
            }
            else
            {
                parameter = parameterFactory.CreateParameter(template.Name, template.DbType, template.MaxLength);
            }
            parameter.Value = CommandHelper.FixObjectType(value);
            return parameter;
        }
Beispiel #10
0
        public ParameterBuilder(IDbParameterFactory factory)
        {
            Check.IsNull(factory, nameof(factory));

            this.factory = factory;
        }
Beispiel #11
0
 public Benchmark_Insert(IDbCommandExecuter executer, IDbParameterFactory parameterFactory)
     : base(executer, parameterFactory)
 {
 }
Beispiel #12
0
 public User_Temp_Insert(IDbCommandExecuter executer, IDbParameterFactory parameterFactory)
     : base(executer, parameterFactory)
 {
 }
Beispiel #13
0
 public User_Temp_Token_Select(IDbCommandExecuter executer, IDbParameterFactory parameterFactory)
     : base(executer, parameterFactory)
 {
 }
Beispiel #14
0
 public void InjectAchivementRepository([ApplicationScope] IDbConnectionFactory connectionFactory,
                                        [ApplicationScope] IDbParameterFactory parameterFactory)
 {
     repository = new Repository(this, connectionFactory, parameterFactory, new AchivementMapper());
 }
Beispiel #15
0
 public void InjectGameVictoryRepository([ApplicationScope] IDbConnectionFactory connectionFactory,
                                         [ApplicationScope] IDbParameterFactory parameterFactory)
 {
     repository = new Repository(this, connectionFactory, parameterFactory, new GameVictoryMapper());
 }
Beispiel #16
0
 public User_SelectPassword(IDbCommandExecuter executer, IDbParameterFactory parameterFactory)
     : base(executer, parameterFactory)
 {
 }
Beispiel #17
0
 public void InjectPlayerKillRepository([ApplicationScope] IDbConnectionFactory connectionFactory,
                                        [ApplicationScope] IDbParameterFactory parameterFactory)
 {
     repository = new Repository(this, connectionFactory, parameterFactory, new PlayerKillMapper());
 }
 private static void SetParameters(IDbParameterFactory parameterFactory, IDbCommand command, IEnumerable<KeyValuePair<ParameterTemplate, object>> parameters)
 {
     var parameterList = parameters.ToList();
     if (parameterList.Any(kvp => kvp.Value is IRange) ||
         parameterList.Any(kvp => kvp.Value is IEnumerable && !(kvp.Value is string)))
     {
         foreach (var pair in parameterList)
         {
             foreach (var parameter in CreateParameterComplex(parameterFactory, pair.Key, pair.Value, command))
             {
                 command.Parameters.Add(parameter);
             }
         }
     }
     else
     {
         foreach (var pair in parameterList)
         {
             command.Parameters.Add(CreateSingleParameter(parameterFactory, pair.Value, pair.Key));
         }
     }
 }
Beispiel #19
0
 public Person_Update(IDbCommandExecuter executer, IDbParameterFactory parameterFactory)
     : base(executer, parameterFactory)
 {
 }