Skip to content

Commit 4868ab1

Browse files
committed
removing pipeline support
1 parent fc4aa3b commit 4868ab1

File tree

2 files changed

+73
-43
lines changed

2 files changed

+73
-43
lines changed

Public/Invoke-OracleCmd.Tests.ps1

+40-24
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Describe "Invoke-OracleCmd" {
1212
Import-LocalizedData -FileName 'com.oracle.credentials.psd1' -BindingVariable Credentials
1313
Write-Debug $Credentials.ServerInstance
1414
Write-Debug $Credentials.Username
15-
Write-Debug $Credentials.SecurePassword
1615

1716
$params = @{
1817
ServerInstance=$Credentials.ServerInstance;
@@ -51,46 +50,63 @@ Describe "Invoke-OracleCmd" {
5150
# arrange
5251
$Query='SELECT foobar'
5352

54-
# It "Generates a non-terminating exception" {
55-
# # act / assert
56-
# { Invoke-OracleCmd -Query $Query -Verbose } | Should Throw 'Invalid SQL statement'
57-
# }
58-
5953
# https://github.com/pester/Pester/issues/366
6054
It 'Generates a non-terminating exception 2' {
55+
# act
56+
$error.clear()
6157
Invoke-OracleCmd -Query $Query -Verbose -ErrorVariable err
58+
59+
# assert
6260
$err.Count | Should Not Be 0
63-
$err[1].Exception.Message | Should Be "Invalid SQL statement"
61+
$err[1].Exception.Message | Should Be "Invalid SQL statement`n`r"
6462
}
6563

6664
}
6765

68-
Context 'Queries supplied via pipeline' {
66+
Context 'Invalid identifier' {
6967

7068
# arrange
71-
$Queries='SELECT sysdate FROM dual','SELECT sysdate+1 TOMORROW FROM dual'
69+
$Query='SELECT sys FROM dual'
7270

73-
It 'Creates multiple recordsets' {
74-
$actual = $Queries | Invoke-OracleCmd -Verbose
71+
# https://github.com/pester/Pester/issues/366
72+
It 'Generates a non-terminating exception 2' {
73+
# act
74+
$error.clear()
75+
Invoke-OracleCmd -Query $Query -Verbose -ErrorVariable err
7576

76-
$actual.Count | Should Be 2
77-
$actual[0] | Should BeOfType System.Data.DataRow
78-
$actual[1] | Should BeOfType System.Data.DataRow
77+
# assert
78+
$err.Count | Should Not Be 0
79+
$err[1].Exception.Message | Should Be "Invalid identifier: ""SYS""`n`r"
7980
}
81+
8082
}
8183

82-
Context 'Invalid query supplied in the midst of valid queries' {
84+
# Context 'Queries supplied via pipeline' {
8385

84-
# arrange
85-
$Queries='SELECT sysdate FROM dual','SELECT foo','SELECT sysdate+1 TOMORROW FROM dual'
86+
# # arrange
87+
# $Queries='SELECT sysdate FROM dual','SELECT sysdate+1 TOMORROW FROM dual'
8688

87-
It 'Creates multiple recordsets, ignoring the invalid query' {
88-
$actual = $Queries | Invoke-OracleCmd -Verbose
89+
# It 'Creates multiple recordsets' {
90+
# $actual = $Queries | Invoke-OracleCmd -Verbose
8991

90-
$actual.Count | Should Be 2
91-
$actual[0] | Should BeOfType System.Data.DataRow
92-
$actual[1] | Should BeOfType System.Data.DataRow
93-
}
94-
}
92+
# $actual.Count | Should Be 2
93+
# $actual[0] | Should BeOfType System.Data.DataRow
94+
# $actual[1] | Should BeOfType System.Data.DataRow
95+
# }
96+
# }
97+
98+
# Context 'Invalid query supplied in the midst of valid queries' {
99+
100+
# # arrange
101+
# $Queries='SELECT sysdate FROM dual','SELECT foo','SELECT sysdate+1 TOMORROW FROM dual'
102+
103+
# It 'Creates multiple recordsets, ignoring the invalid query' {
104+
# $actual = $Queries | Invoke-OracleCmd -Verbose
105+
106+
# $actual.Count | Should Be 2
107+
# $actual[0] | Should BeOfType System.Data.DataRow
108+
# $actual[1] | Should BeOfType System.Data.DataRow
109+
# }
110+
# }
95111

96112
}

Public/Invoke-OracleCmd.ps1

+33-19
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ function Invoke-OracleCmd {
2727

2828
[CmdletBinding()]
2929
param (
30-
[Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)]
31-
[string[]]$Query,
30+
# [Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)]
31+
# [string[]]$Query,
32+
[Parameter(Position=0,Mandatory=$true)]
33+
[string]$Query,
3234

3335
# TODO: handle these?
3436
[string]$ServerInstance,
@@ -40,28 +42,29 @@ function Invoke-OracleCmd {
4042
BEGIN {
4143
Write-Debug "$($MyInvocation.MyCommand.Name)::BEGIN"
4244

43-
Write-Debug '-----PARAMS-----'
44-
Write-Debug "Query: $Query"
45-
Write-Debug "ServerInstance: $ServerInstance"
46-
Write-Debug "Username: $Username"
45+
# Write-Debug '---- PARAMS ----'
46+
# Write-Debug "Query: $Query"
47+
# Write-Debug "ServerInstance: $ServerInstance"
48+
# Write-Debug "Username: $Username"
49+
# Write-Debug '---- /PARAMS ----'
4750

48-
if ( !$global:connection ) {
51+
if ( !$global:connection ) {
4952
Open-Connection | Out-Null # don't add the token to the pipeline, as this will confuse 'down stream' processing
5053
}
5154

5255
} # /Begin
5356
PROCESS {
5457
Write-Debug "$($MyInvocation.MyCommand.Name)::PROCESS"
5558

56-
foreach ($Q In $Query) {
59+
# foreach ($Q In $Query) {
5760

5861
try {
5962

6063
Write-Verbose "Executing $Query"
61-
$command = New-Object System.Data.OracleClient.OracleCommand($query, $global:connection)
64+
$command = New-Object System.Data.OracleClient.OracleCommand($Query, $global:connection)
6265
# $command = New-Object Oracle.DataAccess.Client.OracleCommand($Query,$connection)
6366

64-
Write-Verbose "Filling DataSet"
67+
Write-Debug "Filling DataSet"
6568
$dataSet = New-Object System.Data.DataSet
6669
(New-Object System.Data.OracleClient.OracleDataAdapter($command)).Fill($dataSet) | Out-Null
6770
# (New-Object Oracle.DataAccess.Client.OracleDataAdapter($command)).Fill($dataSet) | Out-Null
@@ -71,20 +74,31 @@ function Invoke-OracleCmd {
7174

7275
} # /try
7376
catch [System.Data.OracleClient.OracleException] {
74-
75-
Write-Debug "* ERROR CODE: $($_.Exception.Code) **"
77+
78+
Write-Debug ("{0} [{1}]" -F $_.Exception.Message.Replace("`n",'') , $_.Exception.Code)
79+
80+
# save for use in switch
81+
$ex = $_
7682

7783
switch ( $_.Exception.Code ) {
84+
{$_ -In 904 } {
85+
# non-terminating error
86+
Write-Error -Message ("Invalid identifier: {0}`n`r" -F ($ex.Exception.Message -Split ': ')[1]) # -Exception $_ -ErrorId $ex.Exception.Code -Category InvalidData -TargetObject $command
87+
}
7888
{$_ -Eq 923 } {
79-
Write-Error -Message "Invalid SQL statement" # -Exception $_ -ErrorId $ex.Exception.Code -Category InvalidData -TargetObject $command
80-
# Throw 'Invalid SQL statement', $_
89+
# non-terminating error
90+
Write-Error -Message "Invalid SQL statement`n`r" # -Exception $_ -ErrorId $ex.Exception.Code -Category InvalidData -TargetObject $command
91+
}
92+
default {
93+
# terminating error
94+
throw
8195
}
82-
}
83-
96+
} # /switch
97+
8498
} # /catch
85-
86-
} # /foreach
87-
99+
100+
# } # /foreach
101+
88102
} # /PROCESS
89103
END { Write-Debug "$($MyInvocation.MyCommand.Name)::END" }
90104

0 commit comments

Comments
 (0)