Exemplo n.º 1
0
        public IDList QueryFast([NotNull] Database database, [NotNull] Opcode opcode)
        {
            Assert.ArgumentNotNull(database, nameof(database));
            Assert.ArgumentNotNull(opcode, nameof(opcode));

            var parameters = new ParametersList();

            var sql = TranslateQuery(opcode, database, parameters);

            if (sql == null)
            {
                return(null);
            }

            using (var reader = _api.CreateReader(sql, parameters.ToArray()))
            {
                var list = new IDList();
                while (reader.Read())
                {
                    list.Add(_api.GetId(0, reader));
                }

                return(list);
            }
        }
Exemplo n.º 2
0
        public object QueryFast([NotNull] Database database, [NotNull] Opcode opcode)
        {
            Assert.ArgumentNotNull(database, nameof(database));
            Assert.ArgumentNotNull(opcode, nameof(opcode));

            var parameters = new ParametersList();

            var sql = TranslateQuery(opcode, database, parameters);

            if (sql == null)
            {
                return(null);
            }


            using (var reader = _api.CreateReader(sql, parameters.ToArray()))
            {
                var idList = new IDList();

                while (reader.Read())
                {
                    idList.Add(_api.GetId(0, reader));
                }

                if (idList.Count == 1)
                {
                    return(new QueryContext(database.DataManager, idList[0]));
                }

                return(idList.Cast <ID>().Select(id => new QueryContext(database.DataManager, id)).ToArray());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Formats the SQL query by replacing the parameters with the actual values.
        /// </summary>
        /// <param name="sql">The SQL.</param>
        /// <param name="parameterList">The parameter list.</param>
        /// <returns>The formatted query.</returns>
        private string FormatSqlQuery(string sql, ParametersList parameterList)
        {
            var parameters = parameterList.ToArray();

            for (var i = 0; i < parameters.Length; i = i + 2)
            {
                var parameterName  = string.Format("@{0}", parameters[i]);
                var parameterValue = string.Format("'{0}'", parameters[i + 1]);

                sql = sql.Replace(parameterName, parameterValue);
            }

            return(sql);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Basically call the standard data provider.
        /// Queries the fast.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="context">The context.</param>
        /// <returns>A list of IDs.</returns>
        protected override IDList QueryFast(string query, CallContext context)
        {
            var baseIdList = this.SelectIDs(query, context);

            if (baseIdList != null && baseIdList.Count > 0)
            {
                return(baseIdList);
            }

            if (!this.IsTraceEnabled(query))
            {
                return(base.QueryFast(query, context));
            }

            var parameters = new ParametersList();
            var sql        = this.Translator.TranslateQuery(query, context, parameters);

            Log.Debug(string.Format("FastQuery: {0}", query), this);
            Log.Debug(string.Format("SQL Query: {0}", this.FormatSqlQuery(sql, parameters)), this);

            if (sql == null)
            {
                return(null);
            }

            var stopwatch = Stopwatch.StartNew();

            using (var reader = this.Api.CreateReader(sql, parameters.ToArray()))
            {
                var idList = new IDList();
                while (reader.Read())
                {
                    idList.Add(this.Api.GetId(0, reader));
                }

                context.CurrentResult = idList;
            }

            Log.Debug(string.Format("Query Time: {0}ms", stopwatch.ElapsedMilliseconds), this);
            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Basically call the standard data provider.
        /// Queries the fast.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="context">The context.</param>
        /// <returns>A list of IDs.</returns>
        protected override IDList QueryFast(string query, CallContext context)
        {
            var baseIdList = this.SelectIDs(query, context);
            if (baseIdList != null && baseIdList.Count > 0) return baseIdList;

            if (!this.IsTraceEnabled(query)) return base.QueryFast(query, context);

            var parameters = new ParametersList();
            var sql = this.Translator.TranslateQuery(query, context, parameters);

            Log.Debug(string.Format("FastQuery: {0}", query), this);
            Log.Debug(string.Format("SQL Query: {0}", this.FormatSqlQuery(sql, parameters)), this);

            if (sql == null) return null;

            var stopwatch = Stopwatch.StartNew();
            using (var reader = this.Api.CreateReader(sql, parameters.ToArray()))
            {
                var idList = new IDList();
                while (reader.Read())
                {
                    idList.Add(this.Api.GetId(0, reader));
                }

                context.CurrentResult = idList;
            }

            Log.Debug(string.Format("Query Time: {0}ms", stopwatch.ElapsedMilliseconds), this);
            return null;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Formats the SQL query by replacing the parameters with the actual values.
        /// </summary>
        /// <param name="sql">The SQL.</param>
        /// <param name="parameterList">The parameter list.</param>
        /// <returns>The formatted query.</returns>
        private string FormatSqlQuery(string sql, ParametersList parameterList)
        {
            var parameters = parameterList.ToArray();
            for (var i = 0; i < parameters.Length; i = i + 2)
            {
                var parameterName = string.Format("@{0}", parameters[i]);
                var parameterValue = string.Format("'{0}'", parameters[i + 1]);

                sql = sql.Replace(parameterName, parameterValue);
            }

            return sql;
        }