Skip to content

Commit a0ba83e

Browse files
committed
ConnectionAttribute
1 parent 73ee795 commit a0ba83e

File tree

9 files changed

+46
-3
lines changed

9 files changed

+46
-3
lines changed

dbops.psm1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ Set-PSFConfig -FullName dbops.Silent -Value $false -Initialize -Validation bool
138138
Set-PSFConfig -FullName dbops.Credential -Value $null -Initialize -Description "Database credentials to authenticate with."
139139
Set-PSFConfig -FullName dbops.Variables -Value $null -Initialize -Validation hashtable -Description "A hashtable with key/value pairs representing #{variables} that will be swapped during execution."
140140
Set-PSFConfig -FullName dbops.ConnectionString -Value $null -Initialize -Description "Connection string to the target database. If specified, overrides SqlInstance and Database parameters."
141+
Set-PSFConfig -FullName dbops.ConnectionAttribute -Value $null -Validation hashtable -Initialize -Description "Additional connection string parameters. Existing connection string will be augmented."
141142
Set-PSFConfig -FullName dbops.CreateDatabase -Value $false -Validation bool -Initialize -Description "Determines whether to create an empty database upon deployment if it haven't been created yet."
142143
Set-PSFConfig -FullName dbops.mail.Template -Value "bin\mail_template.htm" -Initialize -Description "Relative or absolute path to the email template file."
143144
Set-PSFConfig -FullName dbops.mail.SmtpServer -Value "" -Initialize -Description "Smtp server address."

functions/Install-DBOPackage.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@
9898
Defines the driver to use when connecting to the database server.
9999
Available options: SqlServer (default), Oracle
100100
101+
.PARAMETER ConnectionAttribute
102+
Additional connection string attributes that should be added to the existing connection string, provided as a hashtable.
103+
For example to enable SYSDBA permissions in Oracle, use the following: -ConnectionAttribute @{ 'DBA Privilege' = 'SYSDBA' }
104+
101105
.PARAMETER Confirm
102106
Prompts to confirm certain actions
103107
@@ -167,7 +171,8 @@
167171
[AllowNull()]
168172
[string]$ConnectionString,
169173
[Alias('ConnectionType', 'ServerType')]
170-
[DBOps.ConnectionType]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value)
174+
[DBOps.ConnectionType]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value),
175+
[hashtable]$ConnectionAttribute
171176
)
172177

173178
begin {

functions/Install-DBOSqlScript.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@
9595
Defines the driver to use when connecting to the database server.
9696
Available options: SqlServer (default), Oracle
9797
98+
.PARAMETER ConnectionAttribute
99+
Additional connection string attributes that should be added to the existing connection string, provided as a hashtable.
100+
For example to enable SYSDBA permissions in Oracle, use the following: -ConnectionAttribute @{ 'DBA Privilege' = 'SYSDBA' }
101+
98102
.PARAMETER Confirm
99103
Prompts to confirm certain actions
100104
@@ -163,7 +167,8 @@
163167
[AllowNull()]
164168
[string]$ConnectionString,
165169
[Alias('ConnectionType', 'ServerType')]
166-
[DBOps.ConnectionType]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value)
170+
[DBOps.ConnectionType]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value),
171+
[hashtable]$ConnectionAttribute
167172
)
168173

169174
begin {

functions/Invoke-DBOQuery.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ function Invoke-DBOQuery {
7878
Uses values in specified hashtable as parameters inside the SQL query.
7979
For example, <Invoke-DBOQuery -Query 'SELECT @p1' -Parameter @{ p1 = 1 }> would return "1" on SQL Server.
8080
81+
.PARAMETER ConnectionAttribute
82+
Additional connection string attributes that should be added to the existing connection string, provided as a hashtable.
83+
For example to enable SYSDBA permissions in Oracle, use the following: -ConnectionAttribute @{ 'DBA Privilege' = 'SYSDBA' }
84+
8185
.PARAMETER Interactive
8286
Opens connection to the server and launches interactive session to query the server directly from the command line
8387
@@ -152,6 +156,7 @@ function Invoke-DBOQuery {
152156
$As = "DataRow",
153157
[Alias('SqlParameters', 'SqlParameter', 'Parameters')]
154158
[System.Collections.IDictionary]$Parameter,
159+
[hashtable]$ConnectionAttribute,
155160
[Parameter(Mandatory = $true,
156161
Position = 1,
157162
ParameterSetName = 'Interactive')]

functions/Register-DBOPackage.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ function Register-DBOPackage {
8888
.PARAMETER Build
8989
Only register certain builds from the package.
9090
91+
.PARAMETER ConnectionAttribute
92+
Additional connection string attributes that should be added to the existing connection string, provided as a hashtable.
93+
For example to enable SYSDBA permissions in Oracle, use the following: -ConnectionAttribute @{ 'DBA Privilege' = 'SYSDBA' }
94+
9195
.PARAMETER Confirm
9296
Prompts to confirm certain actions
9397
@@ -154,7 +158,8 @@ function Register-DBOPackage {
154158
[AllowNull()]
155159
[string]$ConnectionString,
156160
[Alias('ConnectionType', 'ServerType')]
157-
[DBOps.ConnectionType]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value)
161+
[DBOps.ConnectionType]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value),
162+
[hashtable]$ConnectionAttribute
158163
)
159164

160165
begin {

internal/classes/DBOps.class.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,7 @@ class DBOpsConfig : DBOps {
10871087
[string]$Schema
10881088
[System.Nullable[bool]]$CreateDatabase
10891089
[string]$ConnectionString
1090+
[psobject]$ConnectionAttribute
10901091

10911092
hidden [DBOpsPackageBase]$Parent
10921093

internal/classes/DBOps.enums.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace DBOps {
2323
Schema,
2424
ConnectionString,
2525
CreateDatabase,
26+
ConnectionAttribute
2627
}
2728
}
2829
'@

internal/functions/Get-ConnectionString.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ function Get-ConnectionString {
55
[DBOpsConfig]$Configuration,
66
[Parameter(ParameterSetName = 'ConnString')]
77
[string]$ConnectionString,
8+
[hashtable]$ConnectionAttribute,
89
[DBOps.ConnectionType]$Type,
910
[switch]$Raw
1011
)
@@ -86,13 +87,29 @@ function Get-ConnectionString {
8687
$csBuilder["Integrated Security"] = $true
8788
}
8889
}
90+
# make attribute adjustments if any
91+
if ($Configuration.ConnectionAttribute) {
92+
foreach ($key in $Configuration.ConnectionAttribute.Keys) {
93+
if ($csBuilder.ContainsKey($key)) {
94+
$csBuilder[$key] = $Configuration.ConnectionAttribute.$key
95+
}
96+
}
97+
}
8998
}
9099
elseif ($Configuration) {
91100
$csBuilder = $builderType::new($Configuration.ConnectionString)
92101
}
93102
else {
94103
$csBuilder = $builderType::new($ConnectionString)
95104
}
105+
# make attribute adjustments if any
106+
if ($ConnectionAttribute) {
107+
foreach ($key in $ConnectionAttribute.Keys) {
108+
if ($csBuilder.ContainsKey($key)) {
109+
$csBuilder[$key] = $ConnectionAttribute.$key
110+
}
111+
}
112+
}
96113
# generate the connection string
97114
if ($Raw) {
98115
return $csBuilder

tests/DBOpsConfig.class.Tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ Describe "DBOpsConfig class tests" -Tag $commandName, UnitTests, DBOpsConfig {
144144
$config.Credential.GetNetworkCredential().Password | Should Be $testPassword
145145
$config.SetValue('Credential', $null)
146146
$config.Credential | Should Be $null
147+
#hashtable
148+
$config.SetValue('ConnectionAttribute', @{ 'Connection Timeout' = 10 })
149+
$config.ConnectionAttribute.'Connection Timeout' | Should -Be 10
147150
#Negatives
148151
{ $config.SetValue('AppplicationName', 'MyApp3') } | Should Throw
149152
}

0 commit comments

Comments
 (0)