コード例 #1
0
 private InsertSelectStmt(WithClause with
                          , bool isReplaceStmt
                          , ConflictType onConflict
                          , bool hasIntoKeyword
                          , Table table
                          , UnqualifiedColumnNames columns
                          , IQuery query
                          , UnqualifiedColumnNames conflictColumns
                          , string constraintName
                          , Assignments updateaAsignments
                          , Predicate updateWhere
                          , Comments comments)
 {
     this.Comments          = comments;
     this.With              = with;
     this.IsReplaceStmt     = isReplaceStmt;
     this.OnConflict        = onConflict;
     this.HasIntoKeyword    = hasIntoKeyword;
     this.Table             = table;
     this.Columns           = columns;
     this.Query             = query;
     this.ConflictColumns   = conflictColumns;
     this.ConstraintName    = constraintName;
     this.UpdateAssignments = updateaAsignments;
     this.UpdateWhere       = updateWhere;
     if (updateaAsignments == null && updateWhere != null)
     {
         throw new System.ArgumentException(
                   "UpdateaAsignments must be not null, if updateWhere is not null. ");
     }
 }
コード例 #2
0
 public SelectStmt(WithClause with, IQuery query, ForUpdateClause forUpdate)
 {
     this.With      = with;
     this.Query     = query;
     this.ForUpdate = forUpdate;
     this.Comments  = new Comments();
 }
コード例 #3
0
 internal InsertSelectStmt(WithClause with
                           , bool isReplaceStmt
                           , ConflictType onConflict
                           , bool hasIntoKeyword
                           , Table table
                           , UnqualifiedColumnNames columns
                           , IQuery query
                           , string constraintName
                           , Assignments updateaAsignments
                           , Predicate updateWhere
                           , Comments comments)
     : this(with
            , isReplaceStmt
            , onConflict
            , hasIntoKeyword
            , table
            , columns
            , query
            , null
            , constraintName
            , updateaAsignments
            , updateWhere
            , comments)
 {
 }
コード例 #4
0
        /// <summary>
        ///     Renders the select statement, including the with clause.
        /// </summary>
        /// <param name="sb">The SQL text formatter.</param>
        public void RenderSqlStatement(SqlBuilderContext sb)
        {
            if (WithClause != null)
            {
                WithClause.RenderSql(sb);
            }

            RootQuery.RenderSql(sb);
        }
コード例 #5
0
 protected void HandleWithClauseUsingNaturalJoin(WithClause withClause, Dictionary <ObjectReference, RelationType> relationTypeDict)
 {
     relationTypeDict[withClause.ObjectReference] = WithTypeToRelationType(withClause.Type, RelationType.None);
     _columns =
         _columns.Concat(
             _schema.FindTable(withClause.ObjectReference.GetName()).Columns.Select(
                 c => new ObjectReference(c.ActualName, withClause.ObjectReference)))
         .ToArray();
 }
コード例 #6
0
ファイル: DeleteStmt.cs プロジェクト: ruo2012/miniSqlParser
 internal DeleteStmt(WithClause with
                     , bool hasFromKeyword
                     , Table table
                     , Table table2
                     , Predicate where
                     , Comments comments)
 {
     this.Comments       = comments;
     this.With           = with;
     this.HasFromKeyword = hasFromKeyword;
     this.Table          = table;
     this.Table2         = table2;
     _where = where;
     this.SetParent(where);
 }
コード例 #7
0
        protected void InferWithType(WithClause withClause)
        {
            var objectReference = withClause.ObjectReference;

            while (!ReferenceEquals(objectReference.GetOwner(), null))
            {
                var toTable   = _schema.FindTable(objectReference.GetName());
                var fromTable = _schema.FindTable(objectReference.GetOwner().GetName());
                if (_schema.GetRelationType(fromTable.ActualName, toTable.ActualName) == RelationType.OneToMany)
                {
                    withClause.Type = WithType.Many;
                    return;
                }
                objectReference = objectReference.GetOwner();
            }
        }
コード例 #8
0
ファイル: UpdateStmt.cs プロジェクト: ruo2012/miniSqlParser
 internal UpdateStmt(WithClause with
                     , ConflictType onConflict
                     , Table table
                     , Assignments assignments
                     , Table table2
                     , Predicate where
                     , Comments comments)
 {
     this.Comments    = comments;
     this.With        = with;
     this.OnConflict  = onConflict;
     this.Table       = table;
     this.Assignments = assignments;
     this.Table2      = table2;
     _where           = where;
     this.SetParent(where);
 }
コード例 #9
0
 internal InsertSelectStmt(WithClause with
                           , bool isReplaceStmt
                           , ConflictType onConflict
                           , bool hasIntoKeyword
                           , Table table
                           , UnqualifiedColumnNames columns
                           , IQuery query
                           , Comments comments)
 {
     this.Comments       = comments;
     this.With           = with;
     this.IsReplaceStmt  = isReplaceStmt;
     this.OnConflict     = onConflict;
     this.HasIntoKeyword = hasIntoKeyword;
     this.Table          = table;
     this.Columns        = columns;
     this.Query          = query;
 }
コード例 #10
0
ファイル: MergeStmt.cs プロジェクト: rguryanov/miniSqlParser
 internal MergeStmt(WithClause with
                    , Table table
                    , Table usingTable
                    , AliasedQuery usingQuery
                    , Predicate constraint
                    , MergeUpdateClause updateClause
                    , MergeInsertClause insertClause
                    , bool updateBeforeInsert
                    , Comments comments)
 {
     this.Comments           = comments;
     this.With               = with;
     this.Table              = table;
     this.UsingTable         = usingTable;
     this.UsingQuery         = usingQuery;
     this.Constraint         = constraint;
     this.UpdateClause       = updateClause;
     this.InsertClause       = insertClause;
     this.UpdateBeforeInsert = updateBeforeInsert;
 }
コード例 #11
0
 internal InsertSelectStmt(WithClause with
                           , bool isReplaceStmt
                           , ConflictType onConflict
                           , bool hasIntoKeyword
                           , Table table
                           , UnqualifiedColumnNames columns
                           , IQuery query
                           , Comments comments)
     : this(with
            , isReplaceStmt
            , onConflict
            , hasIntoKeyword
            , table
            , columns
            , query
            , null
            , null
            , null
            , null
            , comments)
 {
 }
コード例 #12
0
 void IVisitor.VisitBefore(WithClause withClause)
 {
     this.ParentExists(withClause);
 }
コード例 #13
0
 void IVisitor.VisitAfter(WithClause withClause)
 {
     this.ParentExists(withClause);
 }
コード例 #14
0
ファイル: QueryBuilder.cs プロジェクト: hlach/Simple.Data
 private void HandleWithClauseUsingNaturalJoin(WithClause withClause, Dictionary<ObjectReference, RelationType> relationTypeDict)
 {
     relationTypeDict[withClause.ObjectReference] = WithTypeToRelationType(withClause.Type, RelationType.None);
     _columns =
         _columns.Concat(
             _schema.FindTable(withClause.ObjectReference.GetName()).Columns.Select(
                 c => new ObjectReference(c.ActualName, withClause.ObjectReference)))
             .ToArray();
 }
コード例 #15
0
ファイル: QueryBuilder.cs プロジェクト: hlach/Simple.Data
 private void HandleWithClauseUsingAssociatedJoinClause(Dictionary<ObjectReference, RelationType> relationTypeDict, WithClause withClause)
 {
     var joinClause =
         _query.Clauses.OfType<JoinClause>().FirstOrDefault(
             j => j.Table.GetAliasOrName() == withClause.ObjectReference.GetAliasOrName());
     if (joinClause != null)
     {
         _columns =
             _columns.Concat(
                 _schema.FindTable(joinClause.Table.GetName()).Columns.Select(
                     c => new ObjectReference(c.ActualName, joinClause.Table)))
                 .ToArray();
         relationTypeDict[joinClause.Table] = WithTypeToRelationType(withClause.Type, RelationType.OneToMany);
     }
 }
コード例 #16
0
ファイル: QueryBuilder.cs プロジェクト: hlach/Simple.Data
 private void InferWithType(WithClause withClause)
 {
     var objectReference = withClause.ObjectReference;
     while (!ReferenceEquals(objectReference.GetOwner(), null))
     {
         var toTable = _schema.FindTable(objectReference.GetName());
         var fromTable = _schema.FindTable(objectReference.GetOwner().GetName());
         if (_schema.GetRelationType(fromTable.ActualName, toTable.ActualName) == RelationType.OneToMany)
         {
             withClause.Type = WithType.Many;
             return;
         }
         objectReference = objectReference.GetOwner();
     }
 }
コード例 #17
0
ファイル: CommandBuilder.cs プロジェクト: xuzhg/Simple.OData
 private bool TryApplyWithClause(WithClause clause, QueryCommand cmd)
 {
     cmd.Expand.Add(clause.ObjectReference.GetName());
     return true;
 }
コード例 #18
0
        /// <summary>
        ///     Renders a temp table or table variable, and inserts the query into it.
        /// </summary>
        /// <param name="sb">The SQL text formatter.</param>
        public void RenderTempTable(SqlBuilderContext sb)
        {
            if (string.IsNullOrEmpty(Name))
            {
                throw new Exception("SqlSelectStatement.Name must be set when rendering as a temp table.");
            }

            bool tableVariable = Name.StartsWith("@");
            bool tempTable     = Name.StartsWith("#");

            if (!tableVariable && !tempTable)
            {
                throw new Exception("Table name must start with @ or # for a table variable, or temp table, respectively.");
            }

            // Table declaration
            if (tableVariable)
            {
                sb.AppendOnNewLine("declare " + Name + " as table");
            }
            else
            {
                sb.AppendOnNewLine("create table " + Name);
            }

            // Column declarations
            sb.AppendOnNewLine("(");
            sb.Indent( );
            var first = new First( );
            int col   = 0;

            foreach (SqlSelectItem item in RootQuery.SelectClause.Items)
            {
                string alias = item.Alias;
                if (string.IsNullOrEmpty(item.Alias))
                {
                    alias = "col" + (col++).ToString(CultureInfo.InvariantCulture);
                }
                //    throw new Exception("Queries rendered in temp tables must have an alias for every column.");

                if (!first)
                {
                    sb.Append(",");
                }

                const string colType = "bigint";                 // for now
                const string options = " primary key";           // for now
                sb.AppendOnNewLine(alias + " " + colType + options);
            }
            sb.EndIndent( );
            sb.AppendOnNewLine(")");

            // Insert query contents into temp table
            if (WithClause != null)
            {
                WithClause.RenderSql(sb);
            }
            sb.AppendOnNewLine("insert into " + Name);
            sb.Indent( );
            RootQuery.RenderSql(sb);
            sb.EndIndent( );
        }
コード例 #19
0
        protected void HandleWithClauseUsingAssociatedJoinClause(Dictionary <ObjectReference, RelationType> relationTypeDict, WithClause withClause)
        {
            var joinClause =
                _query.Clauses.OfType <JoinClause>().FirstOrDefault(
                    j => j.Table.GetAliasOrName() == withClause.ObjectReference.GetAliasOrName());

            if (joinClause != null)
            {
                _columns =
                    _columns.Concat(
                        _schema.FindTable(joinClause.Table.GetName()).Columns.Select(
                            c => new ObjectReference(c.ActualName, joinClause.Table)))
                    .ToArray();
                relationTypeDict[joinClause.Table] = WithTypeToRelationType(withClause.Type, RelationType.OneToMany);
            }
        }
コード例 #20
0
 private bool TryApplyWithClause(WithClause clause, QueryCommand cmd)
 {
     cmd.Expand.Add(clause.ObjectReference.GetName());
     return(true);
 }