Example #1
0
        public SqlOffset Mark()
        {
            SqlOffset current = this.GetCurrentOffset();

            this.offsets.Add(current);

            return(current);
        }
Example #2
0
        public IEnumerable <ISqlContent> Read(ISqlOptions options)
        {
            if (options == null || (options.MaxParameters <= 0 && options.MaxSql <= 0) || (options.MaxParameters >= this.parameters.Count && options.MaxSql >= this.text.Length))
            {
                yield return(this.ReadToEnd());

                yield break;
            }

            int yieldedParams   = 0;
            int yieldedBindings = 0;
            int yieldedText     = 0;

            int maxSql    = options.MaxSql <= 0 ? int.MaxValue : options.MaxSql;
            int maxParams = options.MaxParameters <= 0 ? int.MaxValue : options.MaxParameters;

            SqlOffset[] offsets = this.offsets.Concat(new[] { this.GetCurrentOffset() }).ToArray();

            for (int i = 0; i < offsets.Length - 1; i++)
            {
                SqlOffset offset     = offsets[i];
                SqlOffset nextOffset = offsets[i + 1];

                if (nextOffset.NumberOfParams - yieldedParams > maxParams || nextOffset.Text - yieldedText > maxSql)
                {
                    yield return(new SqlContent()
                    {
                        Bindings = this.bindings.Skip(yieldedBindings).Take(offset.NumberOfBindings - yieldedBindings),
                        Parameters = this.parameters.Skip(yieldedParams).Take(offset.NumberOfParams - yieldedParams),
                        Text = this.text.ToString(yieldedText, offset.Text - yieldedText),
                    });

                    yieldedParams   += offset.NumberOfParams - yieldedParams;
                    yieldedText     += offset.Text - yieldedText;
                    yieldedBindings += offset.NumberOfBindings - yieldedBindings;
                }
            }

            if (yieldedParams < this.parameters.Count || yieldedText < this.text.Length || yieldedBindings < this.bindings.Count)
            {
                string newText = this.text.ToString(yieldedText, this.text.Length - yieldedText);

                if (!string.IsNullOrWhiteSpace(newText))
                {
                    yield return(new SqlContent()
                    {
                        Bindings = this.bindings.Skip(yieldedBindings),
                        Parameters = this.parameters.Skip(yieldedParams),
                        Text = newText,
                    });
                }
            }
        }
Example #3
0
        public void Mark()
        {
            SqlOffset current = this.GetCurrentOffset();

            this.Offsets.Add(current);
        }