コード例 #1
0
 public TInfoRecord(TInfoRecord clone, EDbObjectType dbObjectType)
 {
     this.fileName       = clone.fileName;
     this.SPName_Renamed = clone.SPName_Renamed;
     this.table          = clone.table;
     this.column         = clone.column;
     this.dbObjectType   = dbObjectType;
 }
コード例 #2
0
        protected internal virtual void analyzeStmt(TCustomSqlStatement stmt, int pNest)
        {
            TTable      lcTable = null;
            TObjectName lcColumn = null;
            string      tn = "", cn = "";

            if (stmt is TStoredProcedureSqlStatement)
            {
                spList.Push((TStoredProcedureSqlStatement)stmt);
                TInfoRecord spRecord = new TInfoRecord(EDbObjectType.procedure);
                spRecord.SPName = spList.Peek().StoredProcedureName;
            }
            //System.out.println( numberOfSpace(pNest)+ stmt.sqlstatementtype);
            infos.Append(numberOfSpace(pNest) + stmt.sqlstatementtype + newline);

            for (int i = 0; i < stmt.tables.size(); i++)
            {
                //if  (stmt.tables.getTable(i).isBaseTable())
                //{
                lcTable = stmt.tables.getTable(i);
                TInfoRecord tableRecord = new TInfoRecord(lcTable);
                tableRecord.FileName = this.sqlFileName;
                if (spList.Count > 0)
                {
                    tableRecord.SPName = spList.Peek().StoredProcedureName;
                }
                infoList.Add(tableRecord);

                if (lcTable.TableType == ETableSource.subquery)
                {
                    tn = "(subquery, alias:" + lcTable.AliasName + ")";
                }
                else
                {
                    tn = lcTable.TableName.ToString();
                    if (lcTable.LinkTable != null)
                    {
                        tn = tn + "(" + lcTable.LinkTable.TableName.ToString() + ")";
                    }
                    else if (lcTable.CTEName)
                    {
                        tn = tn + "(CTE)";
                    }
                }
                //System.out.println(numberOfSpace(pNest+1)+tn.getName());
                if ((showTableEffect) && (lcTable.BaseTable))
                {
                    infos.Append(numberOfSpace(pNest + 1) + tn + "(" + lcTable.EffectType + ")" + newline);
                }
                else
                {
                    infos.Append(numberOfSpace(pNest + 1) + tn + newline);
                }

                tableColumnList.Append("," + tn);

                if (!((lcTable.TableType == ETableSource.subquery) || (lcTable.CTEName)))
                {
                    if (lcTable.LinkTable != null)
                    {
                        // tablelist.append(lcTable.getLinkTable().toString()+newline);
                        tablelist.Add(lcTable.LinkTable.ToString());
                    }
                    else
                    {
                        // tablelist.append(lcTable.toString()+newline);
                        tablelist.Add(lcTable.TableName.ToString());
                    }
                }

                for (int j = 0; j < stmt.tables.getTable(i).LinkedColumns.size(); j++)
                {
                    lcColumn = stmt.tables.getTable(i).LinkedColumns.getObjectName(j);
                    TInfoRecord columnRecord = new TInfoRecord(tableRecord, EDbObjectType.column);
                    columnRecord.Column = lcColumn;
                    infoList.Add(columnRecord);
                    cn = lcColumn.ColumnNameOnly;

                    //System.out.println(numberOfSpace(pNest+2)+cn.getColumnNameOnly());
                    if (showColumnLocation)
                    {
                        string posStr = "";
                        //                        if ( lcColumn.getColumnToken() != null) {
                        //                            TSourceToken lcStartToken = lcColumn.getColumnToken();
                        //                            posStr ="("+ lcStartToken.lineNo+","+lcStartToken.columnNo+ ")";
                        //                        }
                        infos.Append(numberOfSpace(pNest + 3) + lcColumn.ColumnNameOnly + posStr + "(" + lcColumn.Location + ")" + newline);
                    }
                    else
                    {
                        infos.Append(numberOfSpace(pNest + 3) + lcColumn.ColumnNameOnly + newline);
                    }

                    if (!((lcTable.TableType == ETableSource.subquery) || (lcTable.CTEName)))
                    {
                        if ((listStarColumn) || (!(lcColumn.ColumnNameOnly.Equals("*"))))
                        {
                            if (lcTable.LinkTable != null)
                            {
                                fieldlist.Add(lcTable.LinkTable.TableName + dotChar + cn);
                            }
                            else
                            {
                                fieldlist.Add(tn + dotChar + cn);
                            }
                        }
                    }
                    tableColumnList.Append("," + tn + dotChar + cn);
                }

                //}
            }

            if (stmt.OrphanColumns.size() > 0)
            {
                infos.Append(numberOfSpace(pNest + 1) + " orphan columns:" + newline);
                string oc = "";
                for (int k = 0; k < stmt.OrphanColumns.size(); k++)
                {
                    TInfoRecord columnRecord = new TInfoRecord(EDbObjectType.column);
                    columnRecord.Column   = stmt.OrphanColumns.getObjectName(k);
                    columnRecord.FileName = this.sqlFileName;
                    infoList.Add(columnRecord);

                    oc = stmt.OrphanColumns.getObjectName(k).ColumnNameOnly; // stmt.getOrphanColumns().getObjectName(k).toString();
                    if (showColumnLocation)
                    {
                        infos.Append(numberOfSpace(pNest + 3) + oc + "(" + stmt.OrphanColumns.getObjectName(k).Location + ")" + newline);
                    }
                    else
                    {
                        infos.Append(numberOfSpace(pNest + 3) + oc + newline);
                    }

                    if ((linkOrphanColumnToFirstTable) && (stmt.FirstPhysicalTable != null))
                    {
                        if ((listStarColumn) || (!(oc.Equals("*", StringComparison.CurrentCultureIgnoreCase))))
                        {
                            fieldlist.Add(stmt.FirstPhysicalTable.ToString() + dotChar + oc);
                        }
                        columnRecord.Table = stmt.FirstPhysicalTable;
                    }
                    else
                    {
                        fieldlist.Add("missed" + dotChar + oc);
                    }
                    tableColumnList.Append(",missed" + dotChar + oc + newline);
                }
            }

            for (int i = 0; i < stmt.Statements.size(); i++)
            {
                analyzeStmt(stmt.Statements.get(i), pNest + 1);
            }

            if (stmt is TStoredProcedureSqlStatement)
            {
                spList.Pop();
            }
        }