|
| 1 | +# API Guide and Class Documentation |
| 2 | + |
| 3 | +## Table of Contents |
| 4 | + |
| 5 | +- [Functions](#functions) |
| 6 | + - [Dismount-Database](#dismount-database) |
| 7 | + - [Get-Database](#get-database) |
| 8 | + - [Get-DatabaseTable](#get-database-table) |
| 9 | + - [Invoke-DatabaseNonQuery](#invoke-database-non-query) |
| 10 | + - [Invoke-DatabaseQuery](#invoke-database-query) |
| 11 | + - [Mount-Database](#mount-database) |
| 12 | + - [New-SqlQueryDataSet](#new-sql-query-data-set) |
| 13 | +- [Classes](#classes) |
| 14 | + - [SqlQueryDataSet Parent Class Details](#sql-query-data-set-parent-class-details) |
| 15 | + - [Class SqlQueryDataSet Properties](#class-sql-query-data-set-properties) |
| 16 | + - [Class SqlQueryDataSet Methods](#class-sql-query-data-set-methods) |
| 17 | + - [Child Class SqlQueryTable Properties](#child-class-sql-query-table-properties) |
| 18 | + - [Child Class SqlQueryTable Methods](#child-class-sql-query-table-methods) |
| 19 | + |
| 20 | +## Functions |
| 21 | + |
| 22 | +```powershell |
| 23 | +Get-Command -Module "SqlQueryClass" -Syntax |
| 24 | +
|
| 25 | +- Dismount-Database [[-connectionString] <Object>] [[-Database] <Object>] [-Quiet] |
| 26 | +- Get-Database [[-connectionString] <Object>] [[-query] <Object>] [-Quiet] |
| 27 | +- Get-DatabaseTable [[-connectionString] <Object>] [[-query] <Object>] [-Quiet] |
| 28 | +- Invoke-DatabaseNonQuery [[-connectionString] <Object>] [[-NonQuery] <Object>] [-Quiet] |
| 29 | +- Invoke-DatabaseQuery [[-connectionString] <Object>] [[-query] <Object>] [-Quiet] |
| 30 | +- Mount-Database [[-connectionString] <Object>] [[-Database] <Object>] [[-DatabaseFilePath] <Object>] [-Quiet] |
| 31 | +- New-SqlQueryDataSet [[-SQLServer] <string>] [[-Database] <string>] [[-ConnectionString] <string>] [[-Query] <string>] [[-TableName] <string>] [[-DisplayResults] <bool>] [<CommonParameters>] |
| 32 | +``` |
| 33 | + |
| 34 | +New-SqlQueryDataSet is the Constructor method for creating an instance of Parent Class [SqlQueryDataSet] and is the main cmdlet. |
| 35 | + |
| 36 | +To see the examples, type: "Get-Help New-SqlQueryDataSet -Examples" |
| 37 | +For more information, type: "Get-Help New-SqlQueryDataSet -Detailed" |
| 38 | +For technical information, type: "Get-Help New-SqlQueryDataSet -Full" |
| 39 | + |
| 40 | +### Dismount-Database |
| 41 | + |
| 42 | +```powershell |
| 43 | +NAME |
| 44 | + Dismount-Database |
| 45 | +SYNTAX |
| 46 | + Dismount-Database [[-connectionString] <Object>] [[-Database] <Object>] [-Quiet] |
| 47 | +DESCRIPTION |
| 48 | + Detaches a database from the SQL Server. |
| 49 | +PARAMETERS |
| 50 | + -connectionString: The connection string to the SQL Server. |
| 51 | + -Database: The name of the database to detach. |
| 52 | + -Quiet: Suppresses output. |
| 53 | +``` |
| 54 | + |
| 55 | +### Get-Database |
| 56 | + |
| 57 | +```powershell |
| 58 | +NAME |
| 59 | + Get-Database |
| 60 | +SYNTAX |
| 61 | + Get-Database [[-connectionString] <Object>] [[-query] <Object>] [-Quiet] |
| 62 | +DESCRIPTION |
| 63 | + Executes a query against the SQL Server and returns the results. |
| 64 | +PARAMETERS |
| 65 | + -connectionString: The connection string to the SQL Server. |
| 66 | + -query: The SQL query to execute. |
| 67 | + -Quiet: Suppresses output. |
| 68 | +``` |
| 69 | + |
| 70 | +### Get-DatabaseTable |
| 71 | + |
| 72 | +```powershell |
| 73 | +NAME |
| 74 | + Get-DatabaseTable |
| 75 | +SYNTAX |
| 76 | + Get-DatabaseTable [[-connectionString] <Object>] [[-query] <Object>] [-Quiet] |
| 77 | +DESCRIPTION |
| 78 | + Executes a query against the SQL Server and returns the results as a table. |
| 79 | +PARAMETERS |
| 80 | + -connectionString: The connection string to the SQL Server. |
| 81 | + -query: The SQL query to execute. |
| 82 | + -Quiet: Suppresses output. |
| 83 | +``` |
| 84 | + |
| 85 | +### Invoke-DatabaseNonQuery |
| 86 | + |
| 87 | +```powershell |
| 88 | +NAME |
| 89 | + Invoke-DatabaseNonQuery |
| 90 | +SYNTAX |
| 91 | + Invoke-DatabaseNonQuery [[-connectionString] <Object>] [[-NonQuery] <Object>] [-Quiet] |
| 92 | +DESCRIPTION |
| 93 | + Executes a non-query SQL command against the SQL Server. |
| 94 | +PARAMETERS |
| 95 | + -connectionString: The connection string to the SQL Server. |
| 96 | + -NonQuery: The non-query SQL command to execute. |
| 97 | + -Quiet: Suppresses output. |
| 98 | +``` |
| 99 | + |
| 100 | +### Invoke-DatabaseQuery |
| 101 | + |
| 102 | +```powershell |
| 103 | +NAME |
| 104 | + Invoke-DatabaseQuery |
| 105 | +SYNTAX |
| 106 | + Invoke-DatabaseQuery [[-connectionString] <Object>] [[-query] <Object>] [-Quiet] |
| 107 | +DESCRIPTION |
| 108 | + Executes a query against the SQL Server and returns the results. |
| 109 | +PARAMETERS |
| 110 | + -connectionString: The connection string to the SQL Server. |
| 111 | + -query: The SQL query to execute. |
| 112 | + -Quiet: Suppresses output. |
| 113 | +``` |
| 114 | + |
| 115 | +### Mount-Database |
| 116 | + |
| 117 | +```powershell |
| 118 | +NAME |
| 119 | + Mount-Database |
| 120 | +SYNTAX |
| 121 | + Mount-Database [[-connectionString] <Object>] [[-Database] <Object>] [[-DatabaseFilePath] <Object>] [-Quiet] |
| 122 | +DESCRIPTION |
| 123 | + Attaches a database to the SQL Server. |
| 124 | +PARAMETERS |
| 125 | + -connectionString: The connection string to the SQL Server. |
| 126 | + -Database: The name of the database to attach. |
| 127 | + -DatabaseFilePath: The file path of the database to attach. |
| 128 | + -Quiet: Suppresses output. |
| 129 | +``` |
| 130 | + |
| 131 | +### New-SqlQueryDataSet |
| 132 | + |
| 133 | +```powershell |
| 134 | +NAME |
| 135 | + New-SqlQueryDataSet |
| 136 | +SYNOPSIS |
| 137 | + New-SqlQueryDataSet -- Creates and returns an Object instance of the [SqlQueryDataSet] class configured with or without the specified parameters. |
| 138 | +SYNTAX |
| 139 | + New-SqlQueryDataSet [[-SQLServer] <String>] [[-Database] <String>] [[-ConnectionString] <String>] [[-Query] <String>] [[-TableName] <String>] [[-DisplayResults] <Boolean>] [<CommonParameters>] |
| 140 | +DESCRIPTION |
| 141 | + This function initializes a new instance of the [SqlQueryDataSet] class and the resulting object is configured is based which parameters were specified. |
| 142 | + All parameters are optional as the can be configured later using the [SqlQueryDataSet]$object returned when calling $object = New-SqlQueryDataSet |
| 143 | + When using $SQLServer and $Database, both must be specified together. The [SqlQueryDataSet] class will auto generate a SQL ConnectionString. |
| 144 | + Specifying $ConnectionString overrides auto generation even when $SQLServer and $Database are also specified. |
| 145 | + Based on which parameters are passed, this CmdLet will use one of the overloaded class constructors and configure instance settings with the other parameters: |
| 146 | + - [SqlQueryDataSet]::new() |
| 147 | + - [SqlQueryDataSet]::new(string SQLServer, string Database) |
| 148 | + - [SqlQueryDataSet]::new(string SQLServer, string Database, string Query) |
| 149 | + Explanation of Parameter Sets: |
| 150 | + - **`ServerDatabase`**: This parameter set allows the user to specify the SQL Server and Database separately without needing a full connection string. |
| 151 | + - **`ServerDatabaseWithConnectionString`**: This parameter set allows the user to provide both the SQL Server and Database separately, or use a connection string. |
| 152 | + - **`ConnectionString`**: This parameter set allows the user to provide a connection string directly. |
| 153 | +REMARKS |
| 154 | + To see the examples, type: "Get-Help New-SqlQueryDataSet -Examples" |
| 155 | + For more information, type: "Get-Help New-SqlQueryDataSet -Detailed" |
| 156 | + For technical information, type: "Get-Help New-SqlQueryDataSet -Full" |
| 157 | +``` |
| 158 | + |
| 159 | +## Classes |
| 160 | + |
| 161 | +### [SqlQueryDataSet] Parent Class Details |
| 162 | + |
| 163 | +Instances of [SqlQueryDataSet] Parent Class are created using the New-SqlQueryDataSet() helper CmdLet. The object returned is of type [SqlQueryDataSet]. The properties and methods are used to manage and configure database information and connections, manage creation of the Child Class, execute queries, and save the results. Instances of Child Classes are collected in the Tables property of the Parent Class. Tables is a collection of [SqlQueryTable] objects. One is created for every unique query that was added or executed. |
| 164 | + |
| 165 | +Each instance of the [SqlQueryTable] Class holds the Query configuration and execution results. |
| 166 | + |
| 167 | +For technical information, see: |
| 168 | + |
| 169 | +- Get-Help New-SqlQueryDataSet -Full |
| 170 | +- New-SqlQueryDataSets.tests.ps1 in the Tests (C:\Git\SqlQueryClass\tests\) folder has full usage examples used to validate usage |
| 171 | + |
| 172 | +### Class [SqlQueryDataSet] Properties |
| 173 | + |
| 174 | +Name | Type |
| 175 | +----------------- | ---------------------------------------------------------------------- |
| 176 | +SQLServer | [System.String] |
| 177 | +Database | [System.String] |
| 178 | +ConnectionTimeout | [System.Int32] |
| 179 | +CommandTimeout | [System.Int32] |
| 180 | +ConnectionString | [System.String] |
| 181 | +SQLConnection | [System.Object] |
| 182 | +TableIndex | [System.Int32] |
| 183 | +Tables | [System.Collections.Generic.List`1[[SqlQueryTable, PowerShell Class Assembly, Version=1.0.0.2, Culture=neutral, PublicKeyToken=null]]] |
| 184 | +TableNames | [System.Collections.Hashtable] |
| 185 | +DisplayResults | [System.Boolean] |
| 186 | +KeepAlive | [System.Boolean] |
| 187 | + |
| 188 | +### Class [SqlQueryDataSet] Methods |
| 189 | + |
| 190 | +Name | Syntax |
| 191 | +-------------------------- | ------------------------------------------------------------- |
| 192 | +AddQuery | int AddQuery(string Query) |
| 193 | +AddQuery | int AddQuery(string TableName, string Query) |
| 194 | +GetTableFromQuery | System.Object GetTableFromQuery(string Query) |
| 195 | +GetTableFromTableName | System.Object GetTableFromTableName(string TableName) |
| 196 | +BuildOleDbConnectionString | string BuildOleDbConnectionString() |
| 197 | +LoadQueryFromFile | void LoadQueryFromFile(string Path) |
| 198 | +OpenConnection | void OpenConnection() |
| 199 | +CloseConnection | void CloseConnection() |
| 200 | +GetSqlCommand | System.Data.SqlClient.SqlCommand GetSqlCommand(string query) |
| 201 | +Clear | void Clear() |
| 202 | +Execute | System.Object Execute() |
| 203 | +Execute | System.Object Execute(SqlQueryTable table) |
| 204 | +Execute | System.Object Execute(int TableIndex) |
| 205 | +Execute | System.Object Execute(string SqlQuery) |
| 206 | +Execute | System.Object Execute(ResultType ResultType) |
| 207 | +ExecuteNonQuery | System.Object ExecuteNonQuery(string SqlQuery) |
| 208 | +ExecuteQuery | System.Object ExecuteQuery(string SqlQuery) |
| 209 | +ExecuteQuery | System.Object ExecuteQuery(string TableName, string SqlQuery) |
| 210 | +ExecuteAsDataTable | System.Object ExecuteAsDataTable(string SqlQuery) |
| 211 | +ExecuteAsDataAdapter | System.Object ExecuteAsDataAdapter(string SqlQuery) |
| 212 | +ExecuteAsDataSet | System.Object ExecuteAsDataSet(string SqlQuery) |
| 213 | +ExecuteAsDataRows | System.Object ExecuteAsDataRows(string SqlQuery) |
| 214 | +SaveChanges | System.Object SaveChanges() |
| 215 | +GetDBTableSchema | System.Object GetDBTableSchema(string TableName) |
| 216 | +GetDBTableIndexesV17 | System.Object GetDBTableIndexesV17(string TableName) |
| 217 | +GetDBTableIndexes | System.Object GetDBTableIndexes(string TableName) |
| 218 | +GetCreateBasicDLL | System.Object GetCreateBasicDLL(string TableName) |
| 219 | +GetCreateDDL | System.Object GetCreateDDL(string TableName) |
| 220 | +ParseSQLQuery | System.Object ParseSQLQuery(string Query) |
| 221 | + |
| 222 | +### Child Class [SqlQueryTable] Properties |
| 223 | + |
| 224 | +Name | Type |
| 225 | +-------------- | ----------------- |
| 226 | +TableIndex | [System.Int32] |
| 227 | +TableName | [System.String] |
| 228 | +Query | [System.String] |
| 229 | +SQLCommand | [System.Object] |
| 230 | +SqlDataAdapter | [System.Object] |
| 231 | +ResultType | [ResultType] |
| 232 | +Result | [System.Object] |
| 233 | +isDirty | [System.Boolean] |
| 234 | +QueryFile | [System.String] |
| 235 | +Parent | [SqlQueryDataSet] |
| 236 | + |
| 237 | +### Child Class [SqlQueryTable] Methods |
| 238 | + |
| 239 | +Class Has No Methods |
0 commit comments