@@ -51,18 +51,22 @@ Describe "Invoke-DBOQuery PostgreSQL tests" -Tag $commandName, IntegrationTests
51
51
It " should run the query" {
52
52
$query = " SELECT 1 AS A, 2 AS B UNION ALL SELECT NULL AS A, 4 AS B"
53
53
$result = Invoke-DBOQuery - Query $query @connParams -As DataTable
54
+ $result.Columns.ColumnName | Should - Be @ (' A' , ' B' )
54
55
$result.A | Should - Be 1 , ([DBNull ]::Value)
55
56
$result.B | Should - Be 2 , 4
56
57
}
57
58
It " should select NULL" {
58
59
$query = " SELECT NULL"
59
60
$result = Invoke-DBOQuery - Query $query @connParams -As DataTable
61
+ $result.Columns.ColumnName | Should - Be @ (' Column1' )
60
62
$result.Column1 | Should - Be ([DBNull ]::Value)
61
63
}
62
64
It " should run the query with semicolon" {
63
65
$query = " SELECT 1 AS A, 2 AS B;
64
66
SELECT 3 AS A, 4 AS B"
65
67
$result = Invoke-DBOQuery - Query $query @connParams -As DataTable
68
+ $result [0 ].Columns.ColumnName | Should - Be @ (' A' , ' B' )
69
+ $result [1 ].Columns.ColumnName | Should - Be @ (' A' , ' B' )
66
70
$result [0 ].A | Should - Be 1
67
71
$result [0 ].B | Should - Be 2
68
72
$result [1 ].A | Should - Be 3
@@ -72,6 +76,8 @@ Describe "Invoke-DBOQuery PostgreSQL tests" -Tag $commandName, IntegrationTests
72
76
$query = " SELECT 1 AS A, 2 AS B;
73
77
SELECT 3 AS A, 4 AS B"
74
78
$result = Invoke-DBOQuery - Query $query @connParams -As Dataset
79
+ $result.Tables [0 ].Columns.ColumnName | Should Be @ (' A' , ' B' )
80
+ $result.Tables [1 ].Columns.ColumnName | Should Be @ (' A' , ' B' )
75
81
$result.Tables [0 ].A | Should - Be 1
76
82
$result.Tables [0 ].B | Should - Be 2
77
83
$result.Tables [1 ].A | Should - Be 3
@@ -80,6 +86,7 @@ Describe "Invoke-DBOQuery PostgreSQL tests" -Tag $commandName, IntegrationTests
80
86
It " should run the query as a PSObject" {
81
87
$query = " SELECT 1 AS A, 2 AS B UNION ALL SELECT NULL AS A, 4 AS B"
82
88
$result = Invoke-DBOQuery - Query $query @connParams -As PSObject
89
+ $result [0 ].psobject.properties.Name | Should - Be @ (' A' , ' B' )
83
90
$result.A | Should - Be 1 , $null
84
91
$result.B | Should - Be 2 , 4
85
92
}
@@ -94,6 +101,8 @@ Describe "Invoke-DBOQuery PostgreSQL tests" -Tag $commandName, IntegrationTests
94
101
" SELECT 1 AS A, 2 AS B" | Out-File $file1 - Force
95
102
" SELECT 3 AS A, 4 AS B" | Out-File $file2 - Force - Encoding bigendianunicode
96
103
$result = Invoke-DBOQuery - InputFile $file1 , $file2 @connParams -As DataTable
104
+ $result [0 ].Columns.ColumnName | Should - Be @ (' A' , ' B' )
105
+ $result [1 ].Columns.ColumnName | Should - Be @ (' A' , ' B' )
97
106
$result [0 ].A | Should - Be 1
98
107
$result [0 ].B | Should - Be 2
99
108
$result [1 ].A | Should - Be 3
@@ -105,11 +114,15 @@ Describe "Invoke-DBOQuery PostgreSQL tests" -Tag $commandName, IntegrationTests
105
114
" SELECT 1 AS A, 2 AS B" | Out-File $file1 - Force
106
115
" SELECT 3 AS A, 4 AS B" | Out-File $file2 - Force - Encoding bigendianunicode
107
116
$result = Get-Item $file1 , $file2 | Invoke-DBOQuery @connParams -As DataTable
117
+ $result [0 ].Columns.ColumnName | Should - Be @ (' A' , ' B' )
118
+ $result [1 ].Columns.ColumnName | Should - Be @ (' A' , ' B' )
108
119
$result [0 ].A | Should - Be 1
109
120
$result [0 ].B | Should - Be 2
110
121
$result [1 ].A | Should - Be 3
111
122
$result [1 ].B | Should - Be 4
112
123
$result = $file1 , $file2 | Invoke-DBOQuery @connParams -As DataTable
124
+ $result [0 ].Columns.ColumnName | Should - Be @ (' A' , ' B' )
125
+ $result [1 ].Columns.ColumnName | Should - Be @ (' A' , ' B' )
113
126
$result [0 ].A | Should - Be 1
114
127
$result [0 ].B | Should - Be 2
115
128
$result [1 ].A | Should - Be 3
@@ -118,12 +131,14 @@ Describe "Invoke-DBOQuery PostgreSQL tests" -Tag $commandName, IntegrationTests
118
131
It " should run the query with custom variables" {
119
132
$query = " SELECT '#{Test}' AS A, '#{Test2}' AS B UNION ALL SELECT '3' AS A, '4' AS B"
120
133
$result = Invoke-DBOQuery - Query $query @connParams -As DataTable - Variables @ { Test = ' 1' ; Test2 = ' 2' }
134
+ $result.Columns.ColumnName | Should - Be @ (' A' , ' B' )
121
135
$result.A | Should - Be ' 1' , ' 3'
122
136
$result.B | Should - Be ' 2' , ' 4'
123
137
}
124
138
It " should connect to the server from a custom variable" {
125
139
$query = " SELECT 1 AS A, 2 AS B UNION ALL SELECT 3 AS A, 4 AS B"
126
- $result = Invoke-DBOQuery - Type PostgreSQL - Database postgres - Query $query - SqlInstance ' #{srv}' - Credential $script :postgresqlCredential -As DataTable - Variables @ { Srv = $script :postgresqlInstance }
140
+ $result = Invoke-DBOQuery - Type PostgreSQL - Database postgres - Query $query - SqlInstance ' #{srv}' - Credential $script :postgresqlCredential -As DataTable - Variables @ { srv = $script :postgresqlInstance }
141
+ $result.Columns.ColumnName | Should - Be @ (' A' , ' B' )
127
142
$result.A | Should - Be ' 1' , ' 3'
128
143
$result.B | Should - Be ' 2' , ' 4'
129
144
}
@@ -154,7 +169,9 @@ Describe "Invoke-DBOQuery PostgreSQL tests" -Tag $commandName, IntegrationTests
154
169
}
155
170
It " should throw a connection timeout error" {
156
171
$query = " SELECT 1/0"
157
- { $null = Invoke-DBOQuery - Type PostgreSQL - Query $query - SqlInstance localhost:6493 - Credential $script :postgresqlCredential - ConnectionTimeout 1 } | Should throw " The operation has timed out"
172
+ try { $null = Invoke-DBOQuery - Type PostgreSQL - Query $query - SqlInstance localhost:6493 - Credential $script :postgresqlCredential - ConnectionTimeout 1 }
173
+ catch { $errVar = $_ }
174
+ $errVar.Exception.Message | Should -Match " The operation has timed out|Connection refused"
158
175
}
159
176
It " should fail when credentials are wrong" {
160
177
try { Invoke-DBOQuery - Type PostgreSQL - Query ' SELECT 1' - SqlInstance $script :postgresqlInstance - Credential ([pscredential ]::new(' nontexistent' , ([securestring ]::new()))) }
0 commit comments