EFIngresProvider/SqlGen/SqlSelectStatement.cs
/// <summary>
/// Write out a SQL select statement as a string.
/// We have to
/// <list type="number">
/// <item>Check whether the aliases extents we use in this statement have
/// to be renamed.
/// We first create a list of all the aliases used by the outer extents.
/// For each of the FromExtents( or AllJoinExtents if it is non-null),
/// rename it if it collides with the previous list.
/// </item>
/// <item>Write each of the clauses (if it exists) as a string</item>
/// </list>
/// </summary>
/// <param name="writer"></param>
/// <param name="sqlGenerator"></param>
Write out a SQL select statement as a string.
We have to
Check whether the aliases extents we use in this statement have
to be renamed.
We first create a list of all the aliases used by the outer extents.
For each of the FromExtents( or AllJoinExtents if it is non-null),
rename it if it collides with the previous list.
Write each of the clauses (if it exists) as a string
Write out a SQL select statement as a string . We have to Check whether the aliases extents we use in this statement have to be renamed . We first create a list of all the aliases used by the outer extents . For each of the FromExtents ( or AllJoinExtents if it is non - null ) rename it if it collides with the previous list . Write each of the clauses ( if it exists ) as a string
public void WriteSql(SqlWriter writer, SqlGenerator sqlGenerator)
        {
            #region Check if FROM aliases need to be renamed
            var outerExtentAliases = GetOuterExtentAliases().ToList();
            var extentList = AllJoinExtents ?? FromExtents;
            foreach (Symbol extent in extentList)
            {
                if (outerExtentAliases.Contains(extent.Name))
                {
                    int i = sqlGenerator.AllExtentNames[extent.Name];
                    string newName;
                    do
                    {
                        ++i;
                        newName = SqlGenerator.Format("{0}{1}", extent.Name, i);
                    }
                    while (sqlGenerator.AllExtentNames.ContainsKey(newName));
                    sqlGenerator.AllExtentNames[extent.Name] = i;
                    extent.NewName = newName;
                    sqlGenerator.AllExtentNames[newName] = 0;
                }
                outerExtentAliases.Add(extent.NewName);
            }
            #endregion
            using (writer.Indent())
            {
                writer.Write("select ");
                if (IsDistinct)
                {
                    writer.Write("distinct ");
                }
                Select.WriteSql(writer, sqlGenerator);
                writer.WriteLine();
                writer.Write("from ");
                From.WriteSql(writer, sqlGenerator);
                if (!this.Where.IsEmpty)
                {
                    writer.WriteLine();
                    writer.Write("where ");
                    Where.WriteSql(writer, sqlGenerator);
                }
                if (!this.GroupBy.IsEmpty)
                {
                    writer.WriteLine();
                    writer.Write("group by ");
                    GroupBy.WriteSql(writer, sqlGenerator);
                }
                if (!this.OrderBy.IsEmpty && (IsTopMost || Top != null))
                {
                    writer.WriteLine();
                    writer.Write("order by ");
                    OrderBy.WriteSql(writer, sqlGenerator);
                }
                if (!Top.IsEmpty)
                {
                    Top.WriteSql(writer, sqlGenerator);
                }
            }
        }
public void WriteSql ( SqlWriter writer , SqlGenerator sqlGenerator ) { region  Check if FROM aliases need to be renamed var outerExtentAliases = GetOuterExtentAliases ( ) . ToList ( ) ; var extentList = AllJoinExtents ?? FromExtents ; foreach ( Symbol extent in extentList ) { if ( outerExtentAliases . Contains ( extent . Name ) ) { int i = sqlGenerator . AllExtentNames [ extent . Name ] ; string newName ; do { ++ i ; newName = SqlGenerator . Format ( " " , extent . Name , i ) ; } while ( sqlGenerator . AllExtentNames . ContainsKey ( newName ) ) ; sqlGenerator . AllExtentNames [ extent . Name ] = i ; extent . NewName = newName ; sqlGenerator . AllExtentNames [ newName ] = 0 ; } outerExtentAliases . Add ( extent . NewName ) ; } endregion using ( writer . Indent ( ) ) { writer . Write ( " " ) ; if ( IsDistinct ) { writer . Write ( " " ) ; } Select . WriteSql ( writer , sqlGenerator ) ; writer . WriteLine ( ) ; writer . Write ( " " ) ; From . WriteSql ( writer , sqlGenerator ) ; if ( ! this . Where . IsEmpty ) { writer . WriteLine ( ) ; writer . Write ( " " ) ; Where . WriteSql ( writer , sqlGenerator ) ; } if ( ! this . GroupBy . IsEmpty ) { writer . WriteLine ( ) ; writer . Write ( " " ) ; GroupBy . WriteSql ( writer , sqlGenerator ) ; } if ( ! this . OrderBy . IsEmpty && ( IsTopMost || Top != null ) ) { writer . WriteLine ( ) ; writer . Write ( " " ) ; OrderBy . WriteSql ( writer , sqlGenerator ) ; } if ( ! Top . IsEmpty ) { Top . WriteSql ( writer , sqlGenerator ) ; } } }
Write out a SQL select statement as a string.
Write out a SQL select statement as a string .
// Create a list of the aliases used by the outer extents // JoinSymbols have to be treated specially. // An then rename each of the FromExtents we have // If AllJoinExtents is non-null - it has precedence. // The new name is derived from the old name - we append an increasing int. // Add extent to list of known names (although i is always incrementing, "prefix11" can // eventually collide with "prefix1" when it is extended) // Add the current alias to the list, so that the extents // that follow do not collide with me. // Increase the indent
writer
SqlWriter
None
sqlGenerator
SqlGenerator
None