Esempio n. 1
0
 private void parseInsertStmt(TInsertSqlStatement insert)
 {
     if (insert.TargetTable.TableName != null)
     {
         string        tableName     = insert.TargetTable.TableName.TableString;
         string        tableSchema   = insert.TargetTable.TableName.SchemaString;
         string        databaseName  = insert.TargetTable.TableName.DatabaseString;
         TableMetaData tableMetaData = new TableMetaData(vendor, strict);
         tableMetaData.Name       = tableName;
         tableMetaData.SchemaName = tableSchema;
         if (isNotEmpty(databaseName))
         {
             tableMetaData.CatalogName = databaseName;
         }
         else
         {
             tableMetaData.CatalogName = database;
         }
         tableMetaData.View = false;
         if (!tableColumns.ContainsKey(tableMetaData))
         {
             tableColumns[tableMetaData] = new List <ColumnMetaData>();
         }
         else
         {
             IList <TableMetaData> tables = new List <TableMetaData>(tableColumns.Keys);
             tableMetaData      = (TableMetaData)tables[tables.IndexOf(tableMetaData)];
             tableMetaData.View = false;
         }
         if (insert.SubQuery != null)
         {
             ColumnImpact impact = new ColumnImpact(insert.SubQuery.ToString(), insert.dbvendor, tableColumns, strict);
             impact.ignoreTopSelect(true);
             impact.Debug             = false;
             impact.ShowUIInfo        = true;
             impact.TraceErrorMessage = false;
             impact.impactSQL();
             ColumnImpactModel columnImpactModel = impact.generateModel();
             parseSubQueryColumnDefinition(insert, insert.SubQuery, tableMetaData, columnImpactModel);
         }
     }
 }
Esempio n. 2
0
 private void parseCreateView(TCreateViewSqlStatement createView)
 {
     if (createView.ViewName != null)
     {
         string        tableName    = createView.ViewName.TableString;
         string        tableSchema  = createView.ViewName.SchemaString;
         string        databaseName = createView.ViewName.DatabaseString;
         TableMetaData viewMetaData = new TableMetaData(vendor, strict);
         viewMetaData.Name       = tableName;
         viewMetaData.SchemaName = tableSchema;
         if (isNotEmpty(databaseName))
         {
             viewMetaData.CatalogName = databaseName;
         }
         else
         {
             viewMetaData.CatalogName = database;
         }
         viewMetaData.View = true;
         if (!tableColumns.ContainsKey(viewMetaData))
         {
             tableColumns[viewMetaData] = new List <ColumnMetaData>();
         }
         else
         {
             IList <TableMetaData> tables = new List <TableMetaData>(tableColumns.Keys);
             viewMetaData      = (TableMetaData)tables[tables.IndexOf(viewMetaData)];
             viewMetaData.View = true;
         }
         if (createView.Subquery != null)
         {
             ColumnImpact impact = new ColumnImpact(createView.Subquery.ToString(), createView.dbvendor, tableColumns, strict);
             impact.ignoreTopSelect(true);
             impact.Debug             = false;
             impact.ShowUIInfo        = true;
             impact.TraceErrorMessage = false;
             impact.impactSQL();
             ColumnImpactModel columnImpactModel = impact.generateModel();
             parseSubQueryColumnDefinition(createView, createView.Subquery, viewMetaData, columnImpactModel);
         }
     }
 }
Esempio n. 3
0
        public virtual string getColumnImpactResult(bool analyzeDlineage)
        {
            if (string.ReferenceEquals(sqlContent, null))
            {
                Document doc = null;
                Element  columnImpactResult = null;

                doc = new Document();
                XDeclaration declaration = new XDeclaration("1.0", "utf-8", "no");
                doc.Declaration    = declaration;
                columnImpactResult = new XElement("columnImpactResult");
                doc.Add(columnImpactResult);

                if (sqlDir != null && sqlDir.Attributes.HasFlag(FileAttributes.Directory))
                {
                    Element dirNode = new Element("dir");
                    dirNode.Add(new XAttribute("name", sqlDir.FullName));
                    columnImpactResult.Add(dirNode);
                }


                FileInfo[] children = sqlFiles == null?listFiles(sqlDir) : sqlFiles;

                for (int i = 0; i < children.Length; i++)
                {
                    FileInfo child = children[i];
                    if (child.Attributes.HasFlag(FileAttributes.Directory))
                    {
                        continue;
                    }
                    if (child != null)
                    {
                        Element fileNode = new Element("file");
                        fileNode.Add(new XAttribute("name", child.FullName));
                        ColumnImpact impact = new ColumnImpact(fileNode, vendor, tableColumns, strict);
                        impact.Debug             = false;
                        impact.ShowUIInfo        = showUIInfo;
                        impact.TraceErrorMessage = false;
                        impact.AnalyzeDlineage   = analyzeDlineage;
                        impact.ignoreTopSelect(false);
                        impact.impactSQL();
                        if (!string.ReferenceEquals(impact.ErrorMessage, null) && impact.ErrorMessage.Trim().Length > 0)
                        {
                            Console.Error.WriteLine(impact.ErrorMessage.Trim());
                        }
                        if (fileNode.HasElements)
                        {
                            columnImpactResult.Add(fileNode);
                        }
                    }
                }
                if (doc != null)
                {
                    try
                    {
                        StringBuilder xmlBuffer = new StringBuilder();

                        using (StringWriter writer = new Utf8StringWriter(xmlBuffer))
                        {
                            doc.Save(writer, SaveOptions.None);
                        }
                        string result = xmlBuffer.ToString().Trim();
                        return(result);
                    }
                    catch (IOException e)
                    {
                        Console.WriteLine(e.ToString());
                        Console.Write(e.StackTrace);
                    }
                }
            }
            else
            {
                ColumnImpact impact = new ColumnImpact(sqlContent, vendor, tableColumns, strict);
                impact.Debug             = false;
                impact.ShowUIInfo        = showUIInfo;
                impact.TraceErrorMessage = false;
                impact.AnalyzeDlineage   = true;
                impact.impactSQL();
                if (!string.ReferenceEquals(impact.ErrorMessage, null) && impact.ErrorMessage.Trim().Length > 0)
                {
                    Console.Error.WriteLine(impact.ErrorMessage.Trim());
                }
                return(impact.ImpactResult);
            }
            return(null);
        }