Chapter 4 Extending your Models with Profiles


Defining the script of an autofix

If the custom check you have defined supports an automatic correction, you can type the body of this function in the Autofix Script tab of the custom check properties.

The autofix is visible in the Check Model Parameters dialog box, it is selected by default if you select the Execute the Automatic Correction by Default check box in the General tab of the custom check properties.

By default, the Autofix Script tab displays the following script items:

We will use the same example as in section Defining the script of a custom check, to define an autofix script that removes the columns with incorrect data type from index.

Steps To define the script of an autofix:

  1. Click the Autofix Script tab in the custom check properties.

    By default, the function is declared at the beginning of the script. You should not modify this line.
  2. Type a comment after the function declaration in order to document the custom check, and then declare the different variables used in the script:

    Dim c 'temporary  index column
    Dim col 'temporary column
    Dim position
    Dim DT_col
  3. Enter the function body:

    %Fix% = False
       If obj.type = "LF" or obj.type = "HG" or obj.type = "CMP" or obj.type ="HNG" Then
          For Each c In obj.IndexColumns
             Set col = c.column
             position = InStr(col.datatype,"(") 
             If position <> 0 Then
                DT_col = Left(col.datatype, position -1) 
             Else 
                DT_col = col.datatype
             End If
             If (Ucase(DT_col) = "VARCHAR") And (col.length > 255) Then
                outmsg = "Automatic correction has removed column " & col.Name & " from index."
                c.Delete
                %Fix% = True
             End If
          Next
       End If

  4. Click Apply to save your changes.

 


Copyright (C) 2008. Sybase Inc. All rights reserved.