Beispiel #1
0
        public async Task <IEnumerable <PDependentTable> > GetDependentTables(string tableName, CancellationToken cancellationToken)
        {
            var sql = sqlFKs;

            if (!string.IsNullOrEmpty(tableName))
            {
                sql = string.Format("{0} where OBJECT_NAME(fk.parent_object_id) = '{1}' or OBJECT_NAME(fk.referenced_object_id) = '{1}'", sql, tableName);
            }

            var result = new List <PDependentTable>();

            using (var uof = _uowFactory.GetUnitOfWork())
                using (var dr = await uof.ExecuteReaderAsync(sql, cancellationToken))
                {
                    var dt = new DataTable();
                    dt.Load(dr);

                    foreach (DataRow r in dt.Rows)
                    {
                        var item = new PDependentTable
                        {
                            Name             = r["Name"].ToString(),
                            ParentColumn     = r["ParentColumn"].ToString(),
                            ParentTable      = r["ParentTable"].ToString(),
                            ReferencedColumn = r["ReferencedColumn"].ToString(),
                            ReferencedTable  = r["ReferencedTable"].ToString()
                        };

                        result.Add(item);
                    }
                }

            return(result);
        }
Beispiel #2
0
        private async Task <IEnumerable <PDependentTable> > GetDependentTables(CancellationToken cancellationToken)
        {
            var result = new List <PDependentTable>();

            using (var uof = _uowFactory.GetUnitOfWork())
                using (var dr = await uof.ExecuteReaderAsync(MSSQLSourceSchema.sqlFKs, cancellationToken))
                {
                    var dt = new DataTable();
                    dt.Load(dr);

                    foreach (DataRow r in dt.Rows)
                    {
                        var item = new PDependentTable
                        {
                            Name             = r["Name"].ToString(),
                            ParentColumn     = r["ParentColumn"].ToString(),
                            ParentTable      = r["ParentTable"].ToString(),
                            ReferencedColumn = r["ReferencedColumn"].ToString(),
                            ReferencedTable  = r["ReferencedTable"].ToString()
                        };

                        result.Add(item);
                    }
                }

            return(result);
        }
 public static IEnumerable <PField> PrepareFieldsForChild(PRecord child, string sqlVar, PDependentTable fk)
 {
     return(InjectSqlVariable(NotIdentityFields(child), sqlVar, child.TableName == fk.ParentTable ? fk.ParentColumn : fk.ReferencedColumn));
 }
Beispiel #4
0
        void ProcessOne(PRecord item, PRecord parentRecord, PDependentTable FK, IList <PRecord> moves = null)
        {
            Console.WriteLine("Process one entry:{0}, parentRecord:{1}", item.ToString(), parentRecord?.ToString());
            moves = moves ?? new List <PRecord>();
            if (moves.Any(_ => _.Equals(item)))
            {
                Console.WriteLine("Shit hits the fan !");
                return;
            }

            moves.Add(item);


            if (item.Parents.Any())
            {
                foreach (var parent in item.Parents)
                {
                    Console.WriteLine("item.Parent {0}", parent.PRecord);
                }

                foreach (var parent in item.Parents)
                {
                    if (!ProcessedItems.Any(_ => _.Equals(parent.PRecord)) &&
                        !moves.Any(_ => _.Equals(parent.PRecord))
                        )
                    {
                        Console.WriteLine("item.Parents, parentRecord:{0}", parent.PRecord?.ToString());
                        if (parent.PRecord.SqlBuildStrategy.NoInserts)
                        {
                            if (parent.PRecord.SqlBuildStrategy.ThrowExecptionIfNotExists)
                            {
                                IfNotExists(parent.PRecord);


        #line default
        #line hidden

        #line 95 "C:\MyProjects\ParameterizationExtractor\ParameterizationExtractor\ParameterizationExtractor\Templates\DefaultTemplate.tt"
                                this.Write("\t\tRAISERROR(\'Record from table ");


        #line default
        #line hidden

        #line 96 "C:\MyProjects\ParameterizationExtractor\ParameterizationExtractor\ParameterizationExtractor\Templates\DefaultTemplate.tt"
                                Write(parent.PRecord.TableName);

        #line default
        #line hidden

        #line 96 "C:\MyProjects\ParameterizationExtractor\ParameterizationExtractor\ParameterizationExtractor\Templates\DefaultTemplate.tt"
                                this.Write(" with unique values ");


        #line default
        #line hidden

        #line 96 "C:\MyProjects\ParameterizationExtractor\ParameterizationExtractor\ParameterizationExtractor\Templates\DefaultTemplate.tt"
                                Write(SqlHelper.GetNameNormalValueString(parent.PRecord.GetUniqueFields()));

        #line default
        #line hidden

        #line 96 "C:\MyProjects\ParameterizationExtractor\ParameterizationExtractor\ParameterizationExtractor\Templates\DefaultTemplate.tt"
                                this.Write(" can not be found\', 16, 1) \r\n");


        #line default
        #line hidden

        #line 97 "C:\MyProjects\ParameterizationExtractor\ParameterizationExtractor\ParameterizationExtractor\Templates\DefaultTemplate.tt"
                            }

                            GenerateSqlForNoExtractionTable(parent.PRecord);
                        }
                        else
                        {
                            Console.WriteLine("I am going to print GenerateSqlForParent, parentRecord:{0} item {1}", parent.PRecord?.ToString(), item);
                            GenerateSqlForParent(parent.PRecord);
                        }

                        foreach (var c in parent.PRecord.Childern)
                        {
                            Console.WriteLine("parent.PRecord.Childern {0}", c.PRecord);
                        }

                        foreach (var c in parent.PRecord.Childern.Where(_ => !moves.Any(t => t.Equals(_.PRecord))))
                        {
                            Console.WriteLine("Process parent children:{0}, parentRecord:{1}", c.PRecord.ToString(), parent.PRecord?.ToString());
                            ProcessOne(c.PRecord, parent.PRecord, c.FK, moves);
                        }
                    }

                    SqlHelper.PrepareFieldsForChild(item, parent.PRecord.GetPKVarName(), parent.FK);
                }
            }

            if (parentRecord != null && FK != null)
            {
                SqlHelper.PrepareFieldsForChild(item, parentRecord.GetPKVarName(), FK);
            }


            GenerateSql(item);

            foreach (var child in item.Childern.Where(_ => !moves.Any(t => t.Equals(_.PRecord))))
            {
                ProcessOne(child.PRecord, item, child.FK, moves);
                Write("\n");
            }
        }