Пример #1
0
        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <returns></returns>
        public override int Execute()
        {
            int           result;
            ISqlGenerator generator = GetGenerator();
            string        sql       = generator.BuildUpdateStatement();
            QueryCommand  cmd;

            if (Provider != null)
            {
                cmd = new QueryCommand(sql, Provider.Name);
            }
            else
            {
                cmd = new QueryCommand(sql); //EK: Yuk! :P
            }
            //add in the commands
            foreach (Setting s in SetStatements)
            {
                cmd.Parameters.Add(s.ParameterName, s.Value, s.DataType);
            }

            //set the contstraints
            SetConstraintParams(cmd);

            try
            {
                result = DataService.ExecuteQuery(cmd);
            }
            catch (Exception x)
            {
                SqlQueryException ex = new SqlQueryException(x.Message);
                throw ex;
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <returns></returns>
        public int Execute()
        {
            int          result;
            string       sql = BuildSqlStatement();
            QueryCommand cmd = provider != null ? new QueryCommand(sql, provider.Name) : new QueryCommand(sql, DataService.Provider.Name);

            //add in the commands
            foreach (InsertSetting s in Inserts)
            {
                cmd.Parameters.Add(s.ParameterName, s.Value, s.DataType);
            }

            //set the contstraints, if we're using a Select statement
            if (Inserts.Count == 0 && SelectValues != null)
            {
                SqlQuery.SetConstraintParams(SelectValues, cmd);
            }

            try
            {
                result = DataService.ExecuteQuery(cmd);
            }
            catch (Exception x)
            {
                SqlQueryException ex = new SqlQueryException(x.Message);
                throw ex;
            }
            return(result);
        }
Пример #3
0
        /// <summary>
        /// Executes as collection.
        /// </summary>
        /// <typeparam name="ListType">The type of the ist type.</typeparam>
        /// <param name="sql">The SQL.</param>
        /// <param name="values">The values.</param>
        /// <returns></returns>
        public virtual ListType ExecuteAsCollection <ListType>(string sql, params object[] values)
            where ListType : IAbstractList, new()
        {
            QueryCommand cmd = GetCommand(sql, values);

            ListType list = new ListType();

            try
            {
                IDataReader rdr = DataService.GetReader(cmd);
                list.LoadAndCloseReader(rdr);
            }
            catch (Exception x)
            {
                SqlQueryException ex = new SqlQueryException(x.Message);
                throw ex;
            }

            return(list);
        }
Пример #4
0
        /// <summary>
        /// Executes the typed list.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql">The SQL.</param>
        /// <param name="values">The values.</param>
        /// <returns></returns>
        public List <T> ExecuteTypedList <T>(string sql, params object[] values) where T : new()
        {
            QueryCommand cmd = GetCommand(sql, values);

            List <T>    result = new List <T>();
            IDataReader rdr;
            Type        iType = typeof(T);

            try
            {
                rdr = DataService.GetReader(cmd);
            }
            catch (Exception x)
            {
                SqlQueryException ex = new SqlQueryException(x.Message);
                throw ex;
            }

            if (rdr != null)
            {
                using (rdr)
                {
                    if (iType is IActiveRecord)
                    {
                        //load it
                        while (rdr.Read())
                        {
                            T item = new T();
                            //set to ActiveRecord
                            IActiveRecord arItem = (IActiveRecord)item;

                            arItem.Load(rdr);
                            result.Add(item);
                        }
                    }
                    else
                    {
                        //coerce the values, using some light reflection
                        iType.GetProperties();

                        //set the values
                        PropertyInfo prop;
                        while (rdr.Read())
                        {
                            T item = new T();

                            for (int i = 0; i < rdr.FieldCount; i++)
                            {
                                prop = iType.GetProperty(rdr.GetName(i));
                                if (prop != null && !DBNull.Value.Equals(rdr.GetValue(i)))
                                {
                                    prop.SetValue(item, rdr.GetValue(i), null);
                                }
                            }
                            result.Add(item);
                        }
                    }
                    rdr.Close();
                }
            }
            return(result);
        }
Пример #5
0
        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <returns></returns>
        public override int Execute()
        {
            int result;
            ISqlGenerator generator = GetGenerator();
            string sql = generator.BuildUpdateStatement();
            QueryCommand cmd = Provider != null ? new QueryCommand(sql, Provider.Name) : new QueryCommand(sql);

            //add in the commands
            foreach (Setting s in SetStatements)
            {
              if (!s.IsExpression) cmd.Parameters.Add(s.ParameterName, s.Value, s.DataType);
            }

            //set the contstraints
            SetConstraintParams(cmd);

            try
            {
                result = DataService.ExecuteQuery(cmd);
            }
            catch(Exception x)
            {
                SqlQueryException ex = new SqlQueryException(x.Message);
                throw ex;
            }
            return result;
        }