⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.pl

📁 ARM上的如果你对底层感兴趣
💻 PL
📖 第 1 页 / 共 2 页
字号:
        print"\nThe DSN for connection #", $O->Connection(), ":\n";
        print "\tDSN...\n";
        foreach (sort(keys(%DSNAttributes))){
            print "\t$_ = \"$DSNAttributes{$_}\"\n";
        }
    }



####
#   T E S T  8
####
    PrintTest(8, "Dump list of ALL tables in datasource");

    print "\nList of tables for \"$DSN\"\n\n";
    $Num = 0;
    if ($O->Catalog("", "", "%", "'TABLE','VIEW','SYSTEM TABLE', 'GLOBAL TEMPORARY','LOCAL TEMPORARY','ALIAS','SYNONYM'")){

        print "\tCursor is currently named \"", $O->GetCursorName(), "\".\n";
        print "\tRenaming cursor to \"TestCursor\"...", (($O->SetCursorName("TestCursor"))? "Success":"Failure"), ".\n";
        print "\tCursor is currently named \"", $O->GetCursorName(), "\".\n\n";

        @FieldNames = $O->FieldNames();

        $~ = "Test_8_Header";
        write;

        $~ = "Test_8_Body";
        while($O->FetchRow()){
            undef %Data;
            %Data = $O->DataHash();
            write;
        }
    }
    print "\n\tTotal number of tables displayed: $Num\n";



####
#   T E S T  9
####
    PrintTest(9, "Dump list of non-system tables and views in datasource");

    print "\n";
    $Num = 0;

    foreach  $Temp ($O->TableList("", "", "%", "TABLE, VIEW, SYSTEM_TABLE")){
        $Table = $Temp;
        print "\t", ++$Num, ".) \"$Temp\"\n";
    }
    print "\n\tTotal number of tables displayed: $Num\n";


####
#   T E S T  10
####
    PrintTest(10, "Dump contents of the table: \"$Table\"");

    print "\n";

    print "\tResetting (dropping) cursor...", (($O->DropCursor())? "Successful":"Failure"), ".\n\n";

    print "\tCurrently the cursor type is: ", $O->GetStmtOption($O->SQL_CURSOR_TYPE), "\n";
    print "\tSetting Cursor to Dynamic (", ($O->SQL_CURSOR_DYNAMIC), ")...", (($O->SetStmtOption($O->SQL_CURSOR_TYPE, $O->SQL_CURSOR_DYNAMIC))? "Success":"Failure"), ".\n";
    print "\t\tThis may have failed depending on your ODBC Driver.\n";
    print "\t\tThis is not really a problem, it will default to another value.\n";
    print "\tUsing the cursor type of: ", $O->GetStmtOption($O->SQL_CURSOR_TYPE), "\n\n";

    print "\tSetting the connection to only grab $MaxRows row", ($MaxRows == 1)? "":"s", " maximum...";
    if ($O->SetStmtOption($O->SQL_MAX_ROWS, $MaxRows)){
        print "Success!\n";
    }else{
        $Failed{'Test 10a'} = "SetStmtOption(): " . Win32::ODBC::Error();
        print "Failure.\n";
    }

    $iTemp = $O->GetStmtOption($O->SQL_MAX_ROWS);
    print "\tUsing the maximum rows: ", (($iTemp)? $iTemp:"No maximum limit"), "\n\n";

    print "\tCursor is currently named \"", $O->GetCursorName(), "\".\n";
    print "\tRenaming cursor to \"TestCursor\"...", (($O->SetCursorName("TestCursor"))? "Success":"Failure"), ".\n";
    print "\tCursor is currently named \"", $O->GetCursorName(), "\".\n\n";

    if (! $O->Sql("SELECT * FROM [$Table]")){
        @FieldNames = $O->FieldNames();
        $Cols = $#FieldNames + 1;
        $Cols = 8 if ($Cols > 8);

        $FmH = "format Test_10_Header =\n";
        $FmH2 = "";
        $FmH3 = "";
        $FmB = "format Test_10_Body = \n";
        $FmB2 = "";

        for ($iTemp = 0; $iTemp < $Cols; $iTemp++){
            $FmH .= "@" . "<" x (80/$Cols - 2) . " ";
            $FmH2 .= "\$FieldNames[$iTemp],";
            $FmH3 .= "-" x (80/$Cols - 1) . " ";

            $FmB .= "@" . "<" x (80/$Cols - 2) . " ";
            $FmB2 .= "\$Data{\$FieldNames[$iTemp]},";
        }
        chop $FmH2;
        chop $FmB2;

        eval"$FmH\n$FmH2\n$FmH3\n.\n";
        eval "$FmB\n$FmB2\n.\n";

        $~ = "Test_10_Header";
        write();
        $~ = "Test_10_Body";

            # Fetch the next rowset
        while($O->FetchRow()){
            undef %Data;
            %Data = $O->DataHash();
            write();
        }
            ####
            #   THE preceeding block could have been written like this:
            #   ------------------------------------------------------
            #
            #       print "\tCurrently the cursor type is: ", $O->GetStmtOption($O->SQL_CURSOR_TYPE), "\n";
            #       print "\tSetting Cursor to Dynamic (", ($O->SQL_CURSOR_DYNAMIC), ")...", (($O->SetStmtOption($O->SQL_CURSOR_TYPE, $O->SQL_CURSOR_DYNAMIC))? "Success":"Failure"), ".\n";
            #       print "\t\tThis may have failed depending on your ODBC Driver. No real problem.\n";
            #       print "\tUsing the cursor type of: ", $O->GetStmtOption($O->SQL_CURSOR_TYPE), "\n\n";
            #
            #       print "\tSetting rowset size = 15 ...", (($O->SetStmtOption($O->SQL_ROWSET_SIZE, 15))? "Success":"Failure"), ".\n";
            #       print "\tGetting rowset size: ", $O->GetStmtOption($O->SQL_ROWSET_SIZE), "\n\n";
            #
            #       while($O->FetchRow()){
            #           $iNum = 1;
            #               #  Position yourself in the rowset
            #           while($O->SetPos($iNum++ ,$O->SQL_POSITION, $O->SQL_LOCK_NO_CHANGE)){
            #               undef %Data;
            #               %Data = $O->DataHash();
            #               write();
            #           }
            #           print "\t\tNext rowset...\n";
            #       }
            #
            #   The reason I didn't write it that way (which is easier) is to
            #   show that we can now SetPos(). Also Fetch() now uses
            #   SQLExtendedFetch() so it can position itself and retrieve
            #   rowsets. Notice earlier in this Test 10 we set the
            #   SQL_ROWSET_SIZE. If this was not set it would default to
            #   no limit (depending upon your ODBC Driver).
            ####

        print "\n\tNo more records available.\n";
    }else{
        $Failed{'Test 10'} = "Sql(): " . $O->Error();
    }

    $O->Close();

####
#   T E S T 11
####
    if ($iTempDSN){
        PrintTest(11, "Remove the temporary DSN");
        print "\n\tRemoving the temporary DSN:\n";
        print "\t\tDSN = \"$DSN\"\n\t\tDriver = \"$DriverType\"\n";

        if (Win32::ODBC::ConfigDSN(ODBC_REMOVE_DSN, $DriverType, "DSN=$DSN")){
            print "\tSuccessful!\n";
        }else{
            print "\tFailed.\n";
            $Failed{'Test 11'} = "ConfigDSN(): Could not remove \"$DSN\":" . Win32::ODBC::Error();
        }
    }


    PrintTest("E N D   O F   T E S T");
    PresentErrors();



#----------------------- F U N C T I O N S ---------------------------

sub Error{
    my($Data) = @_;
    $Data->DumpError() if ref($Data);
    Win32::ODBC::DumpError() if ! ref($Data);
}


sub Center{
    local($Temp, $Width) = @_;
    local($Len) = ($Width - length($Temp)) / 2;
    return " " x int($Len), $Temp, " " x (int($Len) + (($Len != int($Len))? 1:0));
}

sub PrintTest{
    my($Num, $String) = @_;
    my($Temp);
    if (length($String)){
        $Temp = "  T E S T  $Num $String ";
    }else{
        $Temp = "  $Num  ";
    }
    $Len = length($Temp);
    print "\n", "-" x ((79 - $Len)/2), $Temp, "-" x ((79 - $Len)/2 - 1), "\n";
    print "\t$String\n";
}

sub PresentErrors{
    PrintTest("", "Error Report:");
    if (keys(%Failed)){
        print "The following were errors:\n";
        foreach (sort(keys(%Failed))){
            print "$_ = $Failed{$_}\n";
        }
    }else{
        print "\n\nThere were no errors reported during this test.\n\n";
    }
}


sub Initialize{
format Test_8_Header =
       @<<<<<<<<<<<<<<<<<<<<<<<<<<< @|||||||||||| @|||||||||||| @|||||||||||
       $FieldNames[0],     $FieldNames[1], $FieldNames[2], $FieldNames[3]
       ---------------------------- ------------- ------------- ------------
.
format Test_8_Body =
   @>. @<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<
 ++$Num, $Data{$FieldNames[0]},  $Data{$FieldNames[1]},   $Data{$FieldNames[2]}, $Data{$FieldNames[3]}
.
format Test_9_Header =
          @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<<<<<
           $FieldNames[0],  $FieldNames[1],   $FieldNames[2], $FieldNames[3]
.
format Test_9_Body =
          @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<<<<<
           $Data{$FieldNames[0]},  $Data{$FieldNames[1]},   $Data{$FieldNames[2]}, $Data{$FieldNames[3]}
.
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -