Public/Get-FoxProIndexMetaData.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function Get-FoxProIndexMetaData {
    <#
    .SYNOPSIS
    Displays metadata for FoxPro indexes
 
    .DESCRIPTION
    Displays metadata for FoxPro indexes
 
    .NOTES
    For what it is worth, FoxPro does not seem to support "keys", either primary keys or alternate keys.
    It does support indexes. There are columns in the output that indicate uniqueness, etc.
 
    .PARAMETER DataSource
    Which FoxPro location is of interest?
 
    .PARAMETER TableName
    What is the name of the table(s) of interest? Null means 'all tables'.
 
    .PARAMETER IndexName
    What is the name of the index(es) of interest? Null means 'all indexes'.
 
    .EXAMPLE
    $Path = 'C:\Program Files (x86)\Microsoft Visual FoxPro OLE DB Provider\Samples\Northwind'
    Get-FoxProIndexMetaData -datasource $Path
    # Shows the index information for all of the tables at that location
 
    .EXAMPLE
    $Path = 'C:\Program Files (x86)\Microsoft Visual FoxPro OLE DB Provider\Samples\Northwind'
    Get-FoxProIndexMetaData -datasource $Path -TableName 'employees'
    # Shows the index information for the table named 'employees'.
 
    .EXAMPLE
    Get-FoxProIndexMetaData -datasource '\\server\share\path' -TableName "dept"
    # Shows all of the primary keys for the named table at that location.
    #>


    param (
        [Parameter(Mandatory = $True, ValueFromPipeline = $True, ValueFromPipelinebyPropertyName = $True)]
        $Datasource,
        $TableName,
        $IndexName
    )
    try {
        $cn = Get-FoxProConnection -DataSource $Datasource

        # Not all of the columns that OleDbSchemaIndex returns are useful/valid/supported in Dbase
        # and I commented those out.
        Get-OleDbIndexMetadata -Connection $cn -TableName $TableName -IndexName $IndexName |
            Select-Object TableName,
            # TableCatalog,
            # TableSchema,
            # IndexCatalog,
            # IndexSchema,
            IndexName,
            PrimaryKey,
            Unique,
            # Clustered,
            Type,
            # FillFactor,
            # InitialSize,
            Nulls,
            SortBookmarks,
            # AutoUpdate,
            NullCollation,
            OrdinalPosition,
            ColumnName,
            # ColumnGuid,
            # ColumnPropID,
            Collation,
            Cardinality,
            # Pages,
            # FilterCondition,
            Integrated,
            Expression
    }

    finally {
        $cn.Close()
        $cn.Dispose()
    }

}