Skip to content

Commit

Permalink
Fix issues and improve code related to arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-golebiowski committed Dec 23, 2022
1 parent 34b9fa6 commit 143ddd4
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions SqlSizer-MSSQL/Private/Get-TableSelect.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down Expand Up @@ -59,7 +59,7 @@ function Get-TableSelect
}

$j += 1
$result += $select
$null = $result.Add($select)
}
}

Expand Down
2 changes: 1 addition & 1 deletion SqlSizer-MSSQL/Private/Initialize-OperationsTable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# initialize operations
foreach ($table in $DatabaseInfo.Tables)
{
if ($table.PrimaryKey.Length -eq 0)
if ($table.PrimaryKey.Count -eq 0)
{
continue
}
Expand Down
8 changes: 4 additions & 4 deletions SqlSizer-MSSQL/Private/Install-SqlSizerResultViews.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions SqlSizer-MSSQL/Private/Install-SqlSizerSecureViews.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions SqlSizer-MSSQL/Public/Get-SubsetTableStatistics.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion SqlSizer-MSSQL/Public/Install-SqlSizer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 143ddd4

Please sign in to comment.