Пример #1
0
 private Join(SourceCollection sourceCollection, AliasedSource source)
 {
     this.sources = sourceCollection;
     string newSourceName = source.GetSourceName();
     if (newSourceName != null)
     {
         this.sources.AddSource(newSourceName, source);
     }
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of a DeleteBuilder.
 /// </summary>
 /// <param name="table">The table being deleted from.</param>
 /// <param name="alias">The alias to use to refer to the table.</param>
 public DeleteBuilder(Table table, string alias = null)
 {
     if (table == null)
     {
         throw new ArgumentNullException("table");
     }
     _table = new AliasedSource(table, alias);
     _where = new FilterGroup();
 }
Пример #3
0
 /// <summary>
 /// Starts creating a BinaryJoin.
 /// </summary>
 /// <param name="source">The table or select statement to start the join series with.</param>
 /// <param name="alias">The alias to give the item.</param>
 /// <returns>The first join item.</returns>
 public static Join From(IRightJoinItem source, string alias = null)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     AliasedSource start = new AliasedSource(source, alias);
     return new JoinStart(start);
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of a DeleteBuilder.
 /// </summary>
 /// <param name="table">The table being deleted from.</param>
 /// <param name="alias">The alias to use to refer to the table.</param>
 public DeleteBuilder(Table table, string alias = null)
 {
     if (table == null)
     {
         throw new ArgumentNullException("table");
     }
     _table = new AliasedSource(table, alias);
     _where = new FilterGroup();
 }
Пример #5
0
        /// <summary>
        /// Starts creating a BinaryJoin.
        /// </summary>
        /// <param name="source">The table or select statement to start the join series with.</param>
        /// <param name="alias">The alias to give the item.</param>
        /// <returns>The first join item.</returns>
        public static Join From(IRightJoinItem source, string alias = null)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            AliasedSource start = new AliasedSource(source, alias);

            return(new JoinStart(start));
        }
Пример #6
0
        private Join(SourceCollection sourceCollection, AliasedSource source)
        {
            this.sources = sourceCollection;
            string newSourceName = source.GetSourceName();

            if (newSourceName != null)
            {
                this.sources.AddSource(newSourceName, source);
            }
        }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of a UpdateBuilder.
 /// </summary>
 /// <param name="table">The table being updated.</param>
 /// <param name="alias">The alias to use to refer to the table.</param>
 public UpdateBuilder(Table table, string alias = null)
 {
     if (table == null)
     {
         throw new ArgumentNullException("table");
     }
     _table            = new AliasedSource(table, alias);
     _setters          = new List <Setter>();
     _where            = new FilterGroup();
     _outputProjection = new List <AliasedProjection>();
 }
Пример #8
0
        /// <summary>
        /// Adds the given table to the FROM clause.
        /// </summary>
        /// <param name="table">The table to add.</param>
        /// <param name="alias">The optional alias to give the table within the SELECT statement.</param>
        /// <returns>An object to support aliasing the table and defining columns.</returns>
        public AliasedSource AddTable(Table table, string alias = null)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            AliasedSource source = new AliasedSource(table, alias);

            sources.AddSource(source.GetSourceName(), source);
            _from.Add(source);
            return(source);
        }
Пример #9
0
        /// <summary>
        /// Adds the given function to the FROM clause.
        /// </summary>
        /// <param name="function">The function to add.</param>
        /// <param name="alias">The optional alias to give the function within the SELECT statement.</param>
        /// <returns>An object to support aliasing the function and defining column.</returns>
        public AliasedSource AddFunction(Function function, string alias = null)
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }
            AliasedSource source = new AliasedSource(function, alias);

            sources.AddSource(source.GetSourceName(), source);
            _from.Add(source);
            return(source);
        }
Пример #10
0
        /// <summary>
        /// Adds the given SELECT statement to the FROM clause.
        /// </summary>
        /// <param name="builder">The SELECT statement to add.</param>
        /// <param name="alias">The optional alias to give the SELECT statement within the SELECT statement.</param>
        /// <returns>An object to support aliasing the SELECT statement and defining columns.</returns>
        public AliasedSource AddSelect(ISelectBuilder builder, string alias = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }
            AliasedSource source = new AliasedSource(builder, alias);

            sources.AddSource(source.GetSourceName(), source);
            _from.Add(source);
            return(source);
        }
Пример #11
0
 /// <summary>
 /// Adds the given source, associating it with the given source name.
 /// </summary>
 /// <param name="sourceName">The name to associate with the source.</param>
 /// <param name="source">The source to add.</param>
 internal void AddSource(string sourceName, AliasedSource source)
 {
     if (sourceName == null)
     {
         return;
     }
     if (sourceLookup.ContainsKey(sourceName))
     {
         string message = String.Format(CultureInfo.CurrentCulture, "Encountered a duplicate source name: {0}. Use an alias to distinguish between multiple references to the same table.", sourceName);
         throw new SQLGenerationException(message);
     }
     sourceLookup.Add(sourceName, source);
 }
Пример #12
0
 /// <summary>
 /// Adds the given source, associating it with the given source name.
 /// </summary>
 /// <param name="sourceName">The name to associate with the source.</param>
 /// <param name="source">The source to add.</param>
 internal void AddSource(string sourceName, AliasedSource source)
 {
     if (sourceName == null)
     {
         return;
     }
     if (sourceLookup.ContainsKey(sourceName))
     {
         string message = String.Format(CultureInfo.CurrentCulture, Resources.DuplicateSourceName, sourceName);
         throw new SQLGenerationException(message);
     }
     sourceLookup.Add(sourceName, source);
 }
Пример #13
0
 /// <summary>
 /// Initializes a new instance of a InsertBuilder.
 /// </summary>
 /// <param name="table">The table being inserted into.</param>
 /// <param name="values">The values to insert into the table.</param>
 /// <param name="alias">The alias to use to refer to the table.</param>
 public InsertBuilder(Table table, IValueProvider values, string alias = null)
 {
     if (table == null)
     {
         throw new ArgumentNullException("table");
     }
     if (values == null)
     {
         throw new ArgumentNullException("values");
     }
     _table   = new AliasedSource(table, alias);
     _columns = new List <Column>();
     _values  = values;
 }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of a InsertBuilder.
 /// </summary>
 /// <param name="table">The table being inserted into.</param>
 /// <param name="values">The values to insert into the table.</param>
 /// <param name="alias">The alias to use to refer to the table.</param>
 public InsertBuilder(Table table, IValueProvider values, string alias = null)
 {
     if (table == null)
     {
         throw new ArgumentNullException("table");
     }
     if (values == null)
     {
         throw new ArgumentNullException("values");
     }
     _table = new AliasedSource(table, alias);
     _columns = new List<Column>();
     _values = values;
 }
Пример #15
0
 /// <summary>
 /// Initializes a new instance of a BinaryJoin.
 /// </summary>
 /// <param name="leftHand">The left hand item or join.</param>
 /// <param name="rightHand">The right hand item in the join.</param>
 protected BinaryJoin(Join leftHand, AliasedSource rightHand)
     : base(leftHand, rightHand)
 {
     if (leftHand == null)
     {
         throw new ArgumentNullException("leftHand");
     }
     if (rightHand == null)
     {
         throw new ArgumentNullException("rightHand");
     }
     LeftHand = leftHand;
     RightHand = rightHand;
 }
Пример #16
0
 /// <summary>
 /// Initializes a new instance of a BinaryJoin.
 /// </summary>
 /// <param name="leftHand">The left hand item or join.</param>
 /// <param name="rightHand">The right hand item in the join.</param>
 protected BinaryJoin(Join leftHand, AliasedSource rightHand)
     : base(leftHand, rightHand)
 {
     if (leftHand == null)
     {
         throw new ArgumentNullException("leftHand");
     }
     if (rightHand == null)
     {
         throw new ArgumentNullException("rightHand");
     }
     LeftHand  = leftHand;
     RightHand = rightHand;
 }
Пример #17
0
        /// <summary>
        /// Removes the given table or SELECT statement from the FROM clause.
        /// </summary>
        /// <param name="source">The table or SELECT statement to remove.</param>
        /// <returns>True if the table or SELECT statement was found and removed; otherwise, false.</returns>
        public bool RemoveSource(AliasedSource source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("joinItem");
            }
            string sourceName = source.GetSourceName();

            if (sourceName == null)
            {
                return(_from.Remove(source.Source));
            }
            if (sources.Exists(sourceName) && _from.Remove(source))
            {
                sources.Remove(sourceName);
                return(true);
            }
            return(false);
        }
Пример #18
0
        public static void LogAliasedSource(AliasedSource source, StringBuilder stringBuilder, int level = 0)
        {
            var indent = GetIndent(level);
            if (source != null)
            {
                stringBuilder.AppendLine(string.Format("{0} {1}", indent, source.GetType().FullName));
                if (!string.IsNullOrEmpty(source.Alias))
                {
                    stringBuilder.AppendLine(string.Format("{0} Alias: {1}", indent, source.Alias));
                }

                if (source.Source != null)
                {
                    IRightJoinItem joinItem = source.Source;
                    var sourceName = joinItem.GetSourceName();
                    stringBuilder.AppendLine(string.Format("{0} {1}", indent, joinItem.GetType().FullName));
                    stringBuilder.AppendLine(string.Format("{0} Source Name: {1}", indent, sourceName));

                    //if (joinItem.IsTable)
                    //{
                        var table = joinItem as Table;
                        stringBuilder.AppendLine(string.Format("{0}   Table Name: {1}", indent, table.Name));
                        stringBuilder.AppendLine(string.Format("{0}   Table Qualifier: {1}", indent, table.Qualifier));
                  //  }
                   // else
                    //{
                    //    var join = joinItem as Join;
                    //    if (join != null)
                    //    {
                    //        LogJoin(join, stringBuilder, level + 1);
                    //    }
                    //    else
                    //    {
                    //        throw new NotSupportedException();
                    //    }

                    //}
                }

            }
        }
 protected override void VisitAliasedSource(AliasedSource aliasedSource)
 {
     if (_DetectingMetadataQuery)
     {
         aliasedSource.Source.Accept(this);
     }
     // base.VisitAliasedSource(aliasedSource);
 }
Пример #20
0
 /// <summary>
 /// Adds the given source, associating it with the given source name.
 /// </summary>
 /// <param name="sourceName">The name to associate with the source.</param>
 /// <param name="source">The source to add.</param>
 internal void AddSource(string sourceName, AliasedSource source)
 {
     if (sourceName == null)
     {
         return;
     }
     if (sourceLookup.ContainsKey(sourceName))
     {
         string message = String.Format(CultureInfo.CurrentCulture, Resources.DuplicateSourceName, sourceName);
         throw new SQLGenerationException(message);
     }
     sourceLookup.Add(sourceName, source);
 }
Пример #21
0
 /// <summary>
 /// Initializes a new instance of a FilteredJoin.
 /// </summary>
 /// <param name="left">The left hand item in the join.</param>
 /// <param name="right">The right hand item in the join.</param>
 protected FilteredJoin(Join left, AliasedSource right)
     : base(left, right)
 {
     on = new FilterGroup(Conjunction.And);
 }
Пример #22
0
 /// <summary>
 /// Initializes a new instance of a RightOuterJoin.
 /// </summary>
 /// <param name="leftHand">The left hand item in the join.</param>
 /// <param name="rightHand">The right hand table in the join.</param>
 internal RightOuterJoin(Join leftHand, AliasedSource rightHand)
     : base(leftHand, rightHand)
 {
 }
Пример #23
0
 /// <summary>
 /// Initializes a new instance of a FilteredJoin.
 /// </summary>
 /// <param name="left">The left hand item in the join.</param>
 /// <param name="right">The right hand item in the join.</param>
 protected FilteredJoin(Join left, AliasedSource right)
     : base(left, right)
 {
     on = new FilterGroup(Conjunction.And);
 }
Пример #24
0
 /// <summary>
 /// Initializes a new instance of a Join.
 /// </summary>
 /// <param name="other">The previous join in the sequence.</param>
 /// <param name="source">The source for the current </param>
 protected Join(Join other, AliasedSource source)
     : this(new SourceCollection(other.sources), source)
 {
 }
Пример #25
0
        /// <summary>
        /// Creates a new join where the given item is cross joined with the existing join items.
        /// </summary>
        /// <param name="item">The item to join with.</param>
        /// <param name="alias">The alias to give the item.</param>
        /// <returns>The new join.</returns>
        public Join CrossJoin(IRightJoinItem item, string alias = null)
        {
            AliasedSource source = new AliasedSource(item, alias);

            return(new CrossJoin(this, source));
        }
Пример #26
0
 /// <summary>
 /// Adds the given function to the FROM clause.
 /// </summary>
 /// <param name="function">The function to add.</param>
 /// <param name="alias">The optional alias to give the function within the SELECT statement.</param>
 /// <returns>An object to support aliasing the function and defining column.</returns>
 public AliasedSource AddFunction(Function function, string alias = null)
 {
     if (function == null)
     {
         throw new ArgumentNullException("function");
     }
     AliasedSource source = new AliasedSource(function, alias);
     sources.AddSource(source.GetSourceName(), source);
     _from.Add(source);
     return source;
 }
Пример #27
0
 /// <summary>
 /// Initializes a new instance of an AllColumns
 /// that selects all the columns from the given table or join.
 /// </summary>
 /// <param name="source">The table or join to select all the columns from.</param>
 public AllColumns(AliasedSource source)
 {
     this.source = source;
 }
Пример #28
0
 /// <summary>
 /// Creates a new join where the given item is cross joined with the existing join items.
 /// </summary>
 /// <param name="item">The item to join with.</param>
 /// <param name="alias">The alias to give the item.</param>
 /// <returns>The new join.</returns>
 public Join CrossJoin(IRightJoinItem item, string alias = null)
 {
     AliasedSource source = new AliasedSource(item, alias);
     return new CrossJoin(this, source);
 }
Пример #29
0
 /// <summary>
 /// Initializes a new instance of a JoinStart.
 /// </summary>
 /// <param name="source">The first source in a series of joins.</param>
 public JoinStart(AliasedSource source)
     : base(source)
 {
     this.source = source;
 }
Пример #30
0
 public bool HasSingleSource(out AliasedSource source)
 {
     if (stack.Count == 0)
     {
         source = null;
         return false;
     }
     SourceCollection collection = stack[stack.Count - 1];
     if (collection.Count != 1)
     {
         source = null;
         return false;
     }
     source = collection.Sources.Single();
     return true;
 }
Пример #31
0
 /// <summary>
 /// Initializes a new instance of an AllColumns
 /// that selects all the columns from the given table or join.
 /// </summary>
 /// <param name="source">The table or join to select all the columns from.</param>
 public AllColumns(AliasedSource source)
 {
     this.source = source;
 }
Пример #32
0
 /// <summary>
 /// Visits a AliasedSource.
 /// </summary>
 /// <param name="aliasedSource">The item to visit.</param>
 protected internal virtual void VisitAliasedSource(AliasedSource aliasedSource)
 {
 }
Пример #33
0
 /// <summary>
 /// Initializes a new instance of a JoinStart.
 /// </summary>
 /// <param name="source">The first source in a series of joins.</param>
 public JoinStart(AliasedSource source)
     : base(source)
 {
     this.source = source;
 }
Пример #34
0
 /// <summary>
 /// Generates the text for an AliasedSource.
 /// </summary>
 /// <param name="aliasedSource">The AliasedSource to generate the text for.</param>
 protected internal override void VisitAliasedSource(AliasedSource aliasedSource)
 {
     visitAliasedSource(aliasedSource);
 }
Пример #35
0
 /// <summary>
 /// Adds the given SELECT statement to the FROM clause.
 /// </summary>
 /// <param name="builder">The SELECT statement to add.</param>
 /// <param name="alias">The optional alias to give the SELECT statement within the SELECT statement.</param>
 /// <returns>An object to support aliasing the SELECT statement and defining columns.</returns>
 public AliasedSource AddSelect(ISelectBuilder builder, string alias = null)
 {
     if (builder == null)
     {
         throw new ArgumentNullException("builder");
     }
     AliasedSource source = new AliasedSource(builder, alias);
     sources.AddSource(source.GetSourceName(), source);
     _from.Add(source);
     return source;
 }
Пример #36
0
 /// <summary>
 /// Initializes a new instance of a Join.
 /// </summary>
 /// <param name="source">The source for the current </param>
 protected Join(AliasedSource source)
     : this(new SourceCollection(), source)
 {
 }
Пример #37
0
 /// <summary>
 /// Adds the given table to the FROM clause.
 /// </summary>
 /// <param name="table">The table to add.</param>
 /// <param name="alias">The optional alias to give the table within the SELECT statement.</param>
 /// <returns>An object to support aliasing the table and defining columns.</returns>
 public AliasedSource AddTable(Table table, string alias = null)
 {
     if (table == null)
     {
         throw new ArgumentNullException("table");
     }
     AliasedSource source = new AliasedSource(table, alias);
     sources.AddSource(source.GetSourceName(), source);
     _from.Add(source);
     return source;
 }
Пример #38
0
 /// <summary>
 /// Creates a new join where the given item is right outer joined with the existing join items.
 /// </summary>
 /// <param name="item">The item to join with.</param>
 /// <param name="alias">The alias to give the item.</param>
 /// <returns>The new join.</returns>
 public FilteredJoin RightOuterJoin(IRightJoinItem item, string alias = null)
 {
     AliasedSource source = new AliasedSource(item, alias);
     return new RightOuterJoin(this, source);
 }
Пример #39
0
 /// <summary>
 /// Removes the given table or SELECT statement from the FROM clause.
 /// </summary>
 /// <param name="source">The table or SELECT statement to remove.</param>
 /// <returns>True if the table or SELECT statement was found and removed; otherwise, false.</returns>
 public bool RemoveSource(AliasedSource source)
 {
     if (source == null)
     {
         throw new ArgumentNullException("joinItem");
     }
     string sourceName = source.GetSourceName();
     if (sourceName == null)
     {
         return _from.Remove(source.Source);
     }
     if (sources.Exists(sourceName) && _from.Remove(source.Source))
     {
         sources.Remove(sourceName);
         return true;
     }
     return false;
 }
Пример #40
0
        /// <summary>
        /// Creates a new join where the given item is inner joined with the existing join items.
        /// </summary>
        /// <param name="item">The item to join with.</param>
        /// <param name="alias">The alias to give the item.</param>
        /// <returns>The new join.</returns>
        public FilteredJoin InnerJoin(IRightJoinItem item, string alias = null)
        {
            AliasedSource source = new AliasedSource(item, alias);

            return(new InnerJoin(this, source));
        }
Пример #41
0
 /// <summary>
 /// Initializes a new instance of a Join.
 /// </summary>
 /// <param name="other">The previous join in the sequence.</param>
 /// <param name="source">The source for the current </param>
 protected Join(Join other, AliasedSource source)
     : this(new SourceCollection(other.sources), source)
 {
 }
Пример #42
0
 /// <summary>
 /// Initializes a new instance of a Column.
 /// </summary>
 /// <param name="source">The column source that the column belongs to.</param>
 /// <param name="name">The name of the column.</param>
 internal Column(AliasedSource source, string name)
 {
     Source = source;
     Name   = name;
 }
Пример #43
0
 /// <summary>
 /// Initializes a new instance of a Join.
 /// </summary>
 /// <param name="source">The source for the current </param>
 protected Join(AliasedSource source)
     : this(new SourceCollection(), source)
 {
 }
Пример #44
0
 /// <summary>
 /// Initializes a new instance of a CrossJoin.
 /// </summary>
 /// <param name="leftHand">The left hand item in the join.</param>
 /// <param name="rightHand">The right hand table in the join.</param>
 internal CrossJoin(Join leftHand, AliasedSource rightHand)
     : base(leftHand, rightHand)
 {
 }
Пример #45
0
 private void visitAliasedSource(AliasedSource source)
 {
     if (sourceReferenceType == SourceReferenceType.Declaration)
     {
         visitAliasedSourceDeclaration(source);
     }
     else if (sourceReferenceType == SourceReferenceType.Reference)
     {
         visitAliasedSourceReference(source);
     }
 }
Пример #46
0
 /// <summary>
 /// Initializes a new instance of a Column.
 /// </summary>
 /// <param name="source">The column source that the column belongs to.</param>
 /// <param name="name">The name of the column.</param>
 internal Column(AliasedSource source, string name)
 {
     Source = source;
     Name = name;
 }
Пример #47
0
 private void visitAliasedSourceDeclaration(AliasedSource source)
 {
     source.Source.Accept(forSubCommand());
     if (!String.IsNullOrWhiteSpace(source.Alias))
     {
         if (options.AliasColumnSourcesUsingAs)
         {
             writer.Write(" AS");
         }
         writer.Write(" ");
         writer.Write(source.Alias);
     }
 }
Пример #48
0
 /// <summary>
 /// Visits a AliasedSource.
 /// </summary>
 /// <param name="aliasedSource">The item to visit.</param>
 protected internal virtual void VisitAliasedSource(AliasedSource aliasedSource)
 {
 }
Пример #49
0
 private void visitAliasedSourceReference(AliasedSource source)
 {
     if (String.IsNullOrWhiteSpace(source.Alias))
     {
         if (source.Source.IsAliasRequired)
         {
             throw new SQLGenerationException(Resources.AliasRequired);
         }
         source.Source.Accept(forSubCommand());
     }
     else
     {
         writer.Write(source.Alias);
     }
 }