コード例 #1
0
        /// <summary>
        /// Map to an existing instance
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connection"></param>
        /// <param name="query"></param>
        /// <param name="ignoreExtraRows"></param>
        /// <param name="target"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        protected bool TryGetSingle <T>(
            object query,
            T target,
            bool ignoreExtraRows,
            params object[] parameters)
        {
            var wrapper = new SqlQueryParser <T>(QueryType.Select, query, parameters);

            wrapper.ExpectSelectQuery();

            bool looped = false;

            using (IDataReader reader = wrapper.RunQuery(StorageController))
            {
                while (reader.Read())
                {
                    if (looped)
                    {
                        throw new IQException("More than one record was returned by the Single<T> query");
                    }
                    reader.Map(target);
                    looped = true;
                    if (ignoreExtraRows)
                    {
                        break;
                    }
                }
            }
            return(looped);
        }
コード例 #2
0
        protected bool TryGetSingle <T>(
            object query,
            out T target,
            bool ignoreExtraRows,
            params object[] parameters)
        {
            var wrapper = new SqlQueryParser <T>(QueryType.Select, query, parameters);

            wrapper.ExpectSelectQuery();

            T    output = default(T);
            bool looped = false;

            using (IDataReader reader = wrapper.RunQuery(StorageController))
            {
                while (reader.Read())
                {
                    if (looped)
                    {
                        throw new IQException("More than one record was returned by the Single<T> query");
                    }
                    output = reader.Map <T>();
                    looped = true;
                    if (ignoreExtraRows)
                    {
                        break;
                    }
                }
            }
            if (!looped)
            {
                target = (T)Utils.DefaultValue(typeof(T));
                return(false);
            }
            else
            {
                target = output;
                return(true);
            }
        }
コード例 #3
0
        public int QueryScalar(string query, params object[] parameters)
        {
            var wrapper = new SqlQueryParser <object>(0, query, parameters);

            return(wrapper.RunQueryScalar(StorageController));
        }
コード例 #4
0
        public IDataReader Query(string query, params object[] parameters)
        {
            var wrapper = new SqlQueryParser <object>(0, query, parameters);

            return(wrapper.RunQuery(StorageController));
        }
コード例 #5
0
        public int Count <T>(object query, params object[] parameters)
        {
            var wrapper = new SqlQueryParser <T>(QueryType.Select, query, parameters);

            return(StorageController.Count(wrapper.Connection, wrapper.Query.GetQuery(), wrapper.Query.Parameters));
        }
コード例 #6
0
        public IEnumerable <T> Select <T>(object query, params object[] parameters)
        {
            var wrapper = new SqlQueryParser <T>(QueryType.Select, query, parameters);

            return(wrapper.RunQuery(StorageController).MapAll <T>(wrapper.Buffered));
        }
コード例 #7
0
        public int Delete <T>(object query, params object[] parameters)
        {
            var wrapper = new SqlQueryParser <T>(QueryType.Delete, query, parameters);

            return(wrapper.RunQueryScalar(StorageController));
        }