@@ -51,9 +51,9 @@ 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 ' )
55
- $result.A | Should - Be 1 , ([DBNull ]::Value)
56
- $result.B | Should - Be 2 , 4
54
+ $result.Columns.ColumnName | Should - Be @ (' a ' , ' b ' )
55
+ $result.a | Should - Be 1 , ([DBNull ]::Value)
56
+ $result.b | Should - Be 2 , 4
57
57
}
58
58
It " should select NULL" {
59
59
$query = " SELECT NULL"
@@ -65,30 +65,30 @@ Describe "Invoke-DBOQuery PostgreSQL tests" -Tag $commandName, IntegrationTests
65
65
$query = " SELECT 1 AS A, 2 AS B;
66
66
SELECT 3 AS A, 4 AS B"
67
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 ' )
70
- $result [0 ].A | Should - Be 1
71
- $result [0 ].B | Should - Be 2
72
- $result [1 ].A | Should - Be 3
73
- $result [1 ].B | Should - Be 4
68
+ $result [0 ].Columns.ColumnName | Should - Be @ (' a ' , ' b ' )
69
+ $result [1 ].Columns.ColumnName | Should - Be @ (' a ' , ' b ' )
70
+ $result [0 ].a | Should - Be 1
71
+ $result [0 ].b | Should - Be 2
72
+ $result [1 ].a | Should - Be 3
73
+ $result [1 ].b | Should - Be 4
74
74
}
75
75
It " should run the query with semicolon as a dataset" {
76
76
$query = " SELECT 1 AS A, 2 AS B;
77
77
SELECT 3 AS A, 4 AS B"
78
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 ' )
81
- $result.Tables [0 ].A | Should - Be 1
82
- $result.Tables [0 ].B | Should - Be 2
83
- $result.Tables [1 ].A | Should - Be 3
84
- $result.Tables [1 ].B | Should - Be 4
79
+ $result.Tables [0 ].Columns.ColumnName | Should Be @ (' a ' , ' b ' )
80
+ $result.Tables [1 ].Columns.ColumnName | Should Be @ (' a ' , ' b ' )
81
+ $result.Tables [0 ].a | Should - Be 1
82
+ $result.Tables [0 ].b | Should - Be 2
83
+ $result.Tables [1 ].a | Should - Be 3
84
+ $result.Tables [1 ].b | Should - Be 4
85
85
}
86
86
It " should run the query as a PSObject" {
87
87
$query = " SELECT 1 AS A, 2 AS B UNION ALL SELECT NULL AS A, 4 AS B"
88
88
$result = Invoke-DBOQuery - Query $query @connParams -As PSObject
89
- $result [0 ].psobject.properties.Name | Should - Be @ (' A ' , ' B ' )
90
- $result.A | Should - Be 1 , $null
91
- $result.B | Should - Be 2 , 4
89
+ $result [0 ].psobject.properties.Name | Should - Be @ (' a ' , ' b ' )
90
+ $result.a | Should - Be 1 , $null
91
+ $result.b | Should - Be 2 , 4
92
92
}
93
93
It " should run the query as a SingleValue" {
94
94
$query = " SELECT 1 AS A"
@@ -101,52 +101,52 @@ Describe "Invoke-DBOQuery PostgreSQL tests" -Tag $commandName, IntegrationTests
101
101
" SELECT 1 AS A, 2 AS B" | Out-File $file1 - Force
102
102
" SELECT 3 AS A, 4 AS B" | Out-File $file2 - Force - Encoding bigendianunicode
103
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 ' )
106
- $result [0 ].A | Should - Be 1
107
- $result [0 ].B | Should - Be 2
108
- $result [1 ].A | Should - Be 3
109
- $result [1 ].B | Should - Be 4
104
+ $result [0 ].Columns.ColumnName | Should - Be @ (' a ' , ' b ' )
105
+ $result [1 ].Columns.ColumnName | Should - Be @ (' a ' , ' b ' )
106
+ $result [0 ].a | Should - Be 1
107
+ $result [0 ].b | Should - Be 2
108
+ $result [1 ].a | Should - Be 3
109
+ $result [1 ].b | Should - Be 4
110
110
}
111
111
It " should run the query from InputObject" {
112
112
$file1 = Join-Path ' TestDrive:' 1. sql
113
113
$file2 = Join-Path ' TestDrive:' 2. sql
114
114
" SELECT 1 AS A, 2 AS B" | Out-File $file1 - Force
115
115
" SELECT 3 AS A, 4 AS B" | Out-File $file2 - Force - Encoding bigendianunicode
116
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 ' )
119
- $result [0 ].A | Should - Be 1
120
- $result [0 ].B | Should - Be 2
121
- $result [1 ].A | Should - Be 3
122
- $result [1 ].B | Should - Be 4
117
+ $result [0 ].Columns.ColumnName | Should - Be @ (' a ' , ' b ' )
118
+ $result [1 ].Columns.ColumnName | Should - Be @ (' a ' , ' b ' )
119
+ $result [0 ].a | Should - Be 1
120
+ $result [0 ].b | Should - Be 2
121
+ $result [1 ].a | Should - Be 3
122
+ $result [1 ].b | Should - Be 4
123
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 ' )
126
- $result [0 ].A | Should - Be 1
127
- $result [0 ].B | Should - Be 2
128
- $result [1 ].A | Should - Be 3
129
- $result [1 ].B | Should - Be 4
124
+ $result [0 ].Columns.ColumnName | Should - Be @ (' a ' , ' b ' )
125
+ $result [1 ].Columns.ColumnName | Should - Be @ (' a ' , ' b ' )
126
+ $result [0 ].a | Should - Be 1
127
+ $result [0 ].b | Should - Be 2
128
+ $result [1 ].a | Should - Be 3
129
+ $result [1 ].b | Should - Be 4
130
130
}
131
131
It " should run the query with custom variables" {
132
132
$query = " SELECT '#{Test}' AS A, '#{Test2}' AS B UNION ALL SELECT '3' AS A, '4' AS B"
133
133
$result = Invoke-DBOQuery - Query $query @connParams -As DataTable - Variables @ { Test = ' 1' ; Test2 = ' 2' }
134
- $result.Columns.ColumnName | Should - Be @ (' A ' , ' B ' )
135
- $result.A | Should - Be ' 1' , ' 3'
136
- $result.B | Should - Be ' 2' , ' 4'
134
+ $result.Columns.ColumnName | Should - Be @ (' a ' , ' b ' )
135
+ $result.a | Should - Be ' 1' , ' 3'
136
+ $result.b | Should - Be ' 2' , ' 4'
137
137
}
138
138
It " should connect to the server from a custom variable" {
139
139
$query = " SELECT 1 AS A, 2 AS B UNION ALL SELECT 3 AS A, 4 AS B"
140
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 ' )
142
- $result.A | Should - Be ' 1' , ' 3'
143
- $result.B | Should - Be ' 2' , ' 4'
141
+ $result.Columns.ColumnName | Should - Be @ (' a ' , ' b ' )
142
+ $result.a | Should - Be ' 1' , ' 3'
143
+ $result.b | Should - Be ' 2' , ' 4'
144
144
}
145
145
It " should run the query with custom parameters" {
146
146
$query = " SELECT @p1 AS A, @p2 AS B"
147
147
$result = Invoke-DBOQuery - Query $query @connParams - Parameter @ { p1 = ' 1' ; p2 = ' string' }
148
- $result.A | Should - Be 1
149
- $result.B | Should - Be string
148
+ $result.a | Should - Be 1
149
+ $result.b | Should - Be string
150
150
}
151
151
It " should connect to a specific database" {
152
152
$query = " SELECT current_database()"
@@ -156,8 +156,8 @@ Describe "Invoke-DBOQuery PostgreSQL tests" -Tag $commandName, IntegrationTests
156
156
It " should address column names automatically" {
157
157
$query = " SELECT 1 AS A, 2, 3"
158
158
$result = Invoke-DBOQuery - Query $query @connParams -As DataTable
159
- $result.Columns.ColumnName | Should - Be @ (' A ' , ' Column1' , ' Column2' )
160
- $result.A | Should Be 1
159
+ $result.Columns.ColumnName | Should - Be @ (' a ' , ' Column1' , ' Column2' )
160
+ $result.a | Should Be 1
161
161
$result.Column1 | Should Be 2
162
162
$result.Column2 | Should Be 3
163
163
}
0 commit comments