Luciano Evaristo Guerche

A brazilian geek interested in .NET technologies

  • File Reference Finder Console Application - Lookup for references - not the best way, but...

    Imports System.IO

    Imports System.Text.RegularExpressions

     

    Module Module1

     

        Sub Main()

            Dim sampleFiles As String() = File.ReadAllLines("C:\Users\guercheLE\Documents\Visual Studio 2010\Projects\FileReferenceFinderConsoleApplication\FileReferenceFinderConsoleApplication\sample-nodes.txt")

     

            Console.WriteLine("Looking for references on 'Sample' files...")

            LookUpForReferences(sampleFiles.Select(Function(FullFileName) New FileData With {.FullFileName = FullFileName, .FileNameWithoutExtension = Path.GetFileNameWithoutExtension(FullFileName)}), "C:\Users\guercheLE\Documents\Visual Studio 2010\Projects\FileReferenceFinderConsoleApplication\FileReferenceFinderConsoleApplication\sample-edges.txt")

     

            Console.WriteLine("Press any key to finish...")

            Console.ReadKey()

        End Sub

     

        Private Sub LookUpForReferences(ByVal WhereToLookAt As IEnumerable(Of FileData), ByVal WhereToWriteReferencesTo As String)

            LookUpForReferences(WhereToLookAt, WhereToLookAt, WhereToWriteReferencesTo)

        End Sub

     

        Private Sub LookUpForReferences(ByVal WhereToLookAt As IEnumerable(Of FileData), ByVal WhatToLookFor As IEnumerable(Of FileData), ByVal WhereToWriteReferencesTo As String)

            Dim WhereToLookAtIndex As Integer

            Dim WhereToLookAtCount As Integer

            Dim FileContent As String

            Dim ReferencesFound As List(Of String)

     

            File.WriteAllText(WhereToWriteReferencesTo, "")

     

            WhereToLookAtIndex = 0

            WhereToLookAtCount = WhereToLookAt.Count()

     

            For Each WhereToLookAtItem In WhereToLookAt

                WhereToLookAtIndex += 1

                Console.WriteLine("Looking at '{0}' [{1} of {2}]...", WhereToLookAtItem.FileNameWithoutExtension, WhereToLookAtIndex, WhereToLookAtCount)

     

                If File.Exists(WhereToLookAtItem.FullFileName) Then

                    FileContent = File.ReadAllText(WhereToLookAtItem.FullFileName)

     

                    Do While Regex.IsMatch(FileContent, "/\*[^\*]*\*/", RegexOptions.Singleline)

                        FileContent = Regex.Replace(FileContent, "/\*[^\*]*\*/", "", RegexOptions.Singleline)

                    Loop

     

                    Do While Regex.IsMatch(FileContent, "^[^-]*--.*$", RegexOptions.Multiline)

                        FileContent = Regex.Replace(FileContent, "^([^-]*)--.*$", "$1", RegexOptions.Multiline)

                    Loop

     

                    Do While Regex.IsMatch(FileContent, "^[^\/]*\/\/.*$", RegexOptions.Multiline)

                        FileContent = Regex.Replace(FileContent, "^([^\/]*)\/\/.*$", "$1", RegexOptions.Multiline)

                    Loop

     

                    ReferencesFound = New List(Of String)

     

                    For Each WhatLookForItem In WhatToLookFor

                        If WhereToLookAtItem.FileNameWithoutExtension <> WhatLookForItem.FileNameWithoutExtension Then

                            'Console.WriteLine("Looking for '{0}'...", WhatLookForItem.FileNameWithoutExtension)

     

                            If Regex.IsMatch(FileContent, String.Format("\b{0}\b", WhatLookForItem.FileNameWithoutExtension), RegexOptions.IgnoreCase) Then

                                'Console.WriteLine("'{0}' found at '{1}'...", WhatLookForItem.FileNameWithoutExtension, WhereToLookAtItem.FullFileName)

                                ReferencesFound.Add(String.Format("{1}{0}{2}", vbTab, WhereToLookAtItem.FullFileName, WhatLookForItem.FullFileName))

                            End If

                        End If

                    Next

     

                    If ReferencesFound.Count() > 0 Then

                        'Console.WriteLine("Appending references to '{0}'...", WhereToWriteReferencesTo)

                        File.AppendAllLines(WhereToWriteReferencesTo, ReferencesFound)

                    End If

                End If

            Next

        End Sub

     

        Private Class FileData

            Public Property FullFileName As String

            Public Property FileNameWithoutExtension As String

        End Class

     

    End Module

     

     

    Read more...

  • Recursively walktrough Oracle's constraints

    WITH objectscte AS

     (SELECT ao.owner, ao.object_name, ao.object_type

        FROM all_objects ao

       WHERE ao.owner = '&owner'

         AND NOT ao.object_name LIKE 'BIN$%'

         AND NOT ao.object_name LIKE 'DMRS_%'

         AND NOT ao.object_name LIKE 'DMRV_%'

         AND NOT ao.object_name LIKE 'DT_%'

         AND NOT ao.object_name LIKE 'CG$%'),

    constraintscte AS

     (SELECT ac.owner

            ,ac.table_name xname

            ,'TABLE' xtype

            ,acr.owner referenced_owner

            ,acr.table_name referenced_name

            ,'TABLE' referenced_type

        FROM all_constraints ac

       INNER JOIN all_constraints acr

          ON ac.r_owner = acr.owner

         AND ac.r_constraint_name = acr.constraint_name

       WHERE ac.owner = '&owner'

         AND NOT ac.table_name LIKE 'BIN$%'

         AND NOT ac.table_name LIKE 'DMRS_%'

         AND NOT ac.table_name LIKE 'DMRV_%'

         AND NOT ac.table_name LIKE 'DT_%'

         AND NOT ac.table_name LIKE 'CG$%'

         AND ac.constraint_type = 'R'),

    nonreferencedobjectscte AS

     (SELECT *

        FROM objectscte oc

       WHERE NOT EXISTS (SELECT 1

                FROM constraintscte cc

               WHERE cc.referenced_owner = oc.owner

                 AND cc.referenced_name = oc.object_name

                 AND cc.referenced_type = oc.object_type)),

    orphanedobjectscte AS

     (SELECT *

        FROM nonreferencedobjectscte nroc

       WHERE NOT EXISTS (SELECT 1

                FROM constraintscte cc

               WHERE cc.owner = nroc.owner

                 AND cc.xname = nroc.object_name

                 AND cc.xtype = nroc.object_type)),

    nonorphanedobjectscte AS

     (SELECT *

        FROM nonreferencedobjectscte nroc

       WHERE EXISTS (SELECT 1

                FROM constraintscte cc

               WHERE cc.owner = nroc.owner

                 AND cc.xname = nroc.object_name

                 AND cc.xtype = nroc.object_type)),

    constraintsrecursivecte(owner,

    xname,

    xtype,

    xdepth,

    xpath) AS

     (SELECT nooc.owner

            ,nooc.object_name

            ,nooc.object_type

            ,1

            ,to_clob(nooc.owner || '.' || nooc.object_name)

        FROM nonorphanedobjectscte nooc

      UNION ALL

      SELECT cc.referenced_owner

            ,cc.referenced_name

            ,cc.referenced_type

            ,crc.xdepth + 1

            ,to_clob(to_char(crc.xpath) || '\' || cc.referenced_owner || '.' ||

                     cc.referenced_name)

        FROM constraintsrecursivecte crc

       INNER JOIN constraintscte cc

          ON crc.owner = cc.owner

         AND crc.xname = cc.xname

         AND crc.xtype = cc.xtype) search depth FIRST BY owner,

    xname,

    xtype SET xorder cycle owner,

    xname,

    xtype SET xcycle TO 1 DEFAULT 0

    SELECT owner, xname, xtype, xdepth, to_char(xpath), xorder, xcycle

      FROM constraintsrecursivecte;

     

    Read more...

  • Oracle's table, index and statistics maintenance...

    set serveroutput on size 1000000;

     

    DECLARE

      v_current_table   INTEGER;

      v_current_index   INTEGER;

      v_table_count     INTEGER;

      v_index_count     INTEGER;

      v_exception_count INTEGER;

    BEGIN

      v_current_table   := 1;

      v_exception_count := 0;

     

      SELECT COUNT(*)

        INTO v_table_count

        FROM all_all_tables aat

       WHERE aat.owner = 'SRQF1'

         AND aat.num_rows IS NOT NULL

       ORDER BY aat.num_rows;

     

      FOR t IN (

                SELECT *

                  FROM all_all_tables aat

                 WHERE aat.owner = 'SRQF1'

                   AND aat.num_rows IS NOT NULL

                 ORDER BY aat.num_rows

               )

      LOOP

        dbms_output.put_line('Processing table ' || t.owner || '.' || t.table_name || ' - ' || v_current_table ||

                             ' of ' || v_table_count || '...');

     

        BEGIN

          EXECUTE IMMEDIATE 'ALTER TABLE ' || t.owner || '.' || t.table_name || ' ENABLE ROW MOVEMENT';

          EXECUTE IMMEDIATE 'ALTER TABLE ' || t.owner || '.' || t.table_name || ' SHRINK SPACE CASCADE';

          EXECUTE IMMEDIATE 'ALTER TABLE ' || t.owner || '.' || t.table_name || ' DISABLE ROW MOVEMENT';

        EXCEPTION

          WHEN OTHERS THEN

            v_exception_count := v_exception_count + 1;

            BEGIN

              EXECUTE IMMEDIATE 'ALTER TABLE ' || t.owner || '.' || t.table_name || ' DISABLE ROW MOVEMENT';

            EXCEPTION

              WHEN OTHERS THEN

                v_exception_count := v_exception_count + 1;

            END;

            dbms_output.put_line('    Failed to shrink space cascade. Skipping...');

        END;

     

        v_current_index := 1;

     

        SELECT COUNT(*)

          INTO v_index_count

          FROM all_indexes ai

         WHERE ai.table_owner = t.owner

           AND ai.table_name = t.table_name

           AND ai.num_rows IS NOT NULL

         ORDER BY ai.num_rows;

     

        FOR i IN (

                  SELECT *

                    FROM all_indexes ai

                   WHERE ai.table_owner = t.owner

                     AND ai.table_name = t.table_name

                     AND ai.num_rows IS NOT NULL

                   ORDER BY ai.num_rows

                 )

        LOOP

          dbms_output.put_line('    Processing index ' || i.owner || '.' || i.index_name || ' - ' || v_current_index ||

                               ' of ' || v_index_count || '...');

       

          BEGIN

            EXECUTE IMMEDIATE 'ALTER INDEX ' || i.owner || '.' || i.index_name || ' REBUILD';

          EXCEPTION

            WHEN OTHERS THEN

              v_exception_count := v_exception_count + 1;

              dbms_output.put_line('        Failed to index rebuild. Skipping...');

          END;

       

          v_current_index := v_current_index + 1;

        END LOOP;

     

        dbms_output.put_line('    Gathering table stats...');

        BEGIN

          dbms_stats.gather_table_stats(t.owner, t.table_name);

        EXCEPTION

          WHEN OTHERS THEN

            v_exception_count := v_exception_count + 1;

            dbms_output.put_line('        Failed to gather stats. Skipping...');

        END;

     

        v_current_table := v_current_table + 1;

      END LOOP;

    END;

    /

     

    set serveroutput off;

     

    Read more...

  • Blogroll review (3): Blog feeds I haven't heard of for long

    Wish these people resumed blogging because they used to post great content.

    If you happen to know any of these feeds URLs are outdated, please comment their most up to date blog URL to this post, please.

    If you happen to know any of them, just let them know about their blog inactivity and that there are people out there subscribed to their feed.

    Cheers,
     

    Read more...