diff --git a/SqlSizer-MSSQL/Private/Get-TableSelect.ps1 b/SqlSizer-MSSQL/Private/Get-TableSelect.ps1 index 073b5e9..3b97c10 100644 --- a/SqlSizer-MSSQL/Private/Get-TableSelect.ps1 +++ b/SqlSizer-MSSQL/Private/Get-TableSelect.ps1 @@ -12,7 +12,7 @@ function Get-TableSelect [string]$MaxLength = $null ) - $result = @() + $result = [System.Collections.Generic.List[string]]@() $j = 0 for ($i = 0; $i -lt $TableInfo.Columns.Count; $i++) @@ -59,7 +59,7 @@ function Get-TableSelect } $j += 1 - $result += $select + $null = $result.Add($select) } } diff --git a/SqlSizer-MSSQL/Private/Initialize-OperationsTable.ps1 b/SqlSizer-MSSQL/Private/Initialize-OperationsTable.ps1 index ac17def..60a4069 100644 --- a/SqlSizer-MSSQL/Private/Initialize-OperationsTable.ps1 +++ b/SqlSizer-MSSQL/Private/Initialize-OperationsTable.ps1 @@ -24,7 +24,7 @@ # initialize operations foreach ($table in $DatabaseInfo.Tables) { - if ($table.PrimaryKey.Length -eq 0) + if ($table.PrimaryKey.Count -eq 0) { continue } diff --git a/SqlSizer-MSSQL/Private/Install-SqlSizerResultViews.ps1 b/SqlSizer-MSSQL/Private/Install-SqlSizerResultViews.ps1 index 07f41e8..560117c 100644 --- a/SqlSizer-MSSQL/Private/Install-SqlSizerResultViews.ps1 +++ b/SqlSizer-MSSQL/Private/Install-SqlSizerResultViews.ps1 @@ -64,14 +64,14 @@ function GetResultViewsTableJoin $processing = $Structure.GetProcessingName($signature, $SessionId) - $select = @() - $join = @() + $select = [System.Collections.Generic.List[string]]@() + $join = [System.Collections.Generic.List[string]]@() $i = 0 foreach ($column in $primaryKey) { - $select += "p.Key$i" - $join += "t.$column = rr.Key$i" + $null = $select.Add("p.Key$i") + $null = $join.Add("t.$column = rr.Key$i") $i = $i + 1 } diff --git a/SqlSizer-MSSQL/Private/Install-SqlSizerSecureViews.ps1 b/SqlSizer-MSSQL/Private/Install-SqlSizerSecureViews.ps1 index d1467a7..9afcddc 100644 --- a/SqlSizer-MSSQL/Private/Install-SqlSizerSecureViews.ps1 +++ b/SqlSizer-MSSQL/Private/Install-SqlSizerSecureViews.ps1 @@ -36,7 +36,7 @@ function Install-SqlSizerSecureViews $max = $null } - $total = @() + $total = [System.Collections.Generic.List[string]]@() foreach ($table in $DatabaseInfo.Tables) { if ($table.SchemaName.StartsWith('SqlSizer')) @@ -59,10 +59,10 @@ function Install-SqlSizerSecureViews # create a view $sql = "CREATE VIEW SqlSizer_$($SessionId).Secure_$($table.SchemaName)_$($table.TableName) AS SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS SqlSizer_RowSequence, $tableSelect, HASHBYTES('SHA2_512', $hashInput) as row_sha2_512 FROM $($table.SchemaName).$($table.TableName) t INNER JOIN $join" $null = Invoke-SqlcmdEx -Sql $sql -Database $Database -ConnectionInfo $ConnectionInfo -Statistics $false - $total += "SELECT '$($table.SchemaName)' as [Schema], '$($table.TableName)' as [Table], CONVERT(VARCHAR(max), HASHBYTES('SHA1', STRING_AGG(CONVERT(VARCHAR(max), row_sha2_512, 2), '|')), 2) as [TableHash_SHA_1], CONVERT(VARCHAR(max), HASHBYTES('SHA2_256', STRING_AGG(CONVERT(VARCHAR(max), row_sha2_512, 2), '|')), 2) as [TableHash_SHA_256], CONVERT(VARCHAR(max), HASHBYTES('SHA2_512', STRING_AGG(CONVERT(VARCHAR(max), row_sha2_512, 2), '|')), 2) as [TableHash_SHA_512] FROM SqlSizer_$($SessionId).Secure_$($table.SchemaName)_$($table.TableName)" + $null = $total.Add("SELECT '$($table.SchemaName)' as [Schema], '$($table.TableName)' as [Table], CONVERT(VARCHAR(max), HASHBYTES('SHA1', STRING_AGG(CONVERT(VARCHAR(max), row_sha2_512, 2), '|')), 2) as [TableHash_SHA_1], CONVERT(VARCHAR(max), HASHBYTES('SHA2_256', STRING_AGG(CONVERT(VARCHAR(max), row_sha2_512, 2), '|')), 2) as [TableHash_SHA_256], CONVERT(VARCHAR(max), HASHBYTES('SHA2_512', STRING_AGG(CONVERT(VARCHAR(max), row_sha2_512, 2), '|')), 2) as [TableHash_SHA_512] FROM SqlSizer_$($SessionId).Secure_$($table.SchemaName)_$($table.TableName)") } - if ($total.Length -ne 0) + if ($total.Count -ne 0) { $sql = "CREATE VIEW SqlSizer_$($SessionId).Secure_Summary AS $([string]::Join(' UNION ALL ', $total))" $null = Invoke-SqlcmdEx -Sql $sql -Database $Database -ConnectionInfo $ConnectionInfo -Statistics $false diff --git a/SqlSizer-MSSQL/Public/Get-SubsetTableStatistics.ps1 b/SqlSizer-MSSQL/Public/Get-SubsetTableStatistics.ps1 index da3011b..8ebeeda 100644 --- a/SqlSizer-MSSQL/Public/Get-SubsetTableStatistics.ps1 +++ b/SqlSizer-MSSQL/Public/Get-SubsetTableStatistics.ps1 @@ -30,7 +30,7 @@ function Get-SubsetTableStatistics $rows = Invoke-SqlcmdEx -Sql $sql -Database $Database -ConnectionInfo $ConnectionInfo - $result = @() + $result = [System.Collections.Generic.List[SubsettingTableResult]]@() foreach ($row in $rows) { $tableInfo = $DatabaseInfo.Tables | Where-Object { ($_.SchemaName -eq $row.SchemaName) -and ($_.TableName -eq $row.TableName) } @@ -46,7 +46,7 @@ function Get-SubsetTableStatistics $obj.PrimaryKeySize = $tableInfo.PrimaryKey.Count $obj.CanBeDeleted = $tableInfo.IsHistoric -eq $false $obj.RowCount = $row.Count - $result += $obj + $null = $result.Add($obj) } return $result diff --git a/SqlSizer-MSSQL/Public/Install-SqlSizer.ps1 b/SqlSizer-MSSQL/Public/Install-SqlSizer.ps1 index cdfd0f0..e44b670 100644 --- a/SqlSizer-MSSQL/Public/Install-SqlSizer.ps1 +++ b/SqlSizer-MSSQL/Public/Install-SqlSizer.ps1 @@ -155,7 +155,7 @@ throw "No tables have been found. Cannot install SqlSizer on database without tables." } - $withPrimaryKey = $DatabaseInfo.Tables | Where-Object { ($_.SchemaName -notin @('SqlSizer', 'SqlSizerHistory')) -and ($null -ne $_.PrimaryKey) -and ($_.PrimaryKey.Length -gt 0) } + $withPrimaryKey = $DatabaseInfo.Tables | Where-Object { ($_.SchemaName -notin @('SqlSizer', 'SqlSizerHistory')) -and ($null -ne $_.PrimaryKey) -and ($_.PrimaryKey.Count -gt 0) } if ($null -eq $withPrimaryKey) { throw "No table has been found with primary key. Run Install-PrimaryKeys or set up manually first."