Skip to content

Commit 7f6c09c

Browse files
authored
v2.0.2 - JSON fix (#139)
- Added additional Extension overload to handle SqlParameters instead of Hashtable. - Added check of PSObject as parameter and returning the baseObject instead. - Added tests to verify that JSON as PSObject won't throw errors (when it is a parameter value)
1 parent 15d7f0e commit 7f6c09c

9 files changed

Lines changed: 47 additions & 3 deletions

File tree

ModuleManifest/SimplySql.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'SimplySql.Cmdlets.dll'
1313

1414
# Version number of this module.
15-
ModuleVersion = '2.0.1.69'
15+
ModuleVersion = '2.0.2.70'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()

Tests/mssql.tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,10 @@ Describe "MSSQL" {
154154
} | Should -Not -Throw
155155
}
156156
}
157+
158+
Context "Validations..." {
159+
It "Handles JSON as PSObject" {
160+
Invoke-SqlScalar "SELECT @json" -Parameters @{json = (1..5 | ConvertTo-Json -Compress)} | Should -Be "[1,2,3,4,5]"
161+
}
162+
}
157163
}

Tests/mysql.tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ Describe "MySql" {
176176
} | Should -Not -Throw
177177
}
178178
}
179+
180+
Context "Validations..." {
181+
It "Handles JSON as PSObject" {
182+
Invoke-SqlScalar "SELECT @json" -Parameters @{json = (1..5 | ConvertTo-Json -Compress)} | Should -Be "[1,2,3,4,5]"
183+
}
184+
}
179185
}
180186

181187
<#

Tests/oracle.tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ Describe "Oracle" {
172172
} | Should -Not -Throw
173173
}
174174
}
175+
176+
Context "Validations..." {
177+
It "Handles JSON as PSObject" {
178+
Invoke-SqlScalar "SELECT :json FROM dual" -Parameters @{json = (1..5 | ConvertTo-Json -Compress)} | Should -Be "[1,2,3,4,5]"
179+
}
180+
}
175181
}
176182
<#
177183
requires that the predefined account HR is unlocked and has password hr

Tests/postgre.tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,10 @@ Describe "PostGre" {
137137
} | Should -Not -Throw
138138
}
139139
}
140+
141+
Context "Validations..." {
142+
It "Handles JSON as PSObject" {
143+
Invoke-SqlScalar "SELECT @json" -Parameters @{json = (1..5 | ConvertTo-Json -Compress)} | Should -Be "[1,2,3,4,5]"
144+
}
145+
}
140146
}

Tests/sqlite.tests.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Describe "SQLite" {
22
BeforeEach { Open-SQLiteConnection }
33
AfterEach { Show-SqlConnection -all | Close-SqlConnection }
4+
AfterAll {
5+
Remove-Item "$home\temp.db"
6+
}
47

58
It "Test ConnectionString Switch" {
69
{
@@ -163,5 +166,9 @@ Describe "SQLite" {
163166
}
164167
}
165168

166-
It "Remove File" { { Remove-Item "$home\temp.db" } | Should -Not -Throw }
169+
Context "Validations..." {
170+
It "Handles JSON as PSObject" {
171+
Invoke-SqlScalar "SELECT @json" -Parameters @{json = (1..5 | ConvertTo-Json -Compress)} | Should -Be "[1,2,3,4,5]"
172+
}
173+
}
167174
}

source/SimplySql.Engine/Dry.vb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Imports System.Data.Common
1+
Imports System.Data
2+
Imports System.Data.Common
23
Imports System.Runtime.CompilerServices
34
Module Dry
45
<Extension>
@@ -19,4 +20,14 @@ Module Dry
1920
this.Data.Add("ParameterExceptionMessage", ex.Message)
2021
End Try
2122
End Sub
23+
24+
<Extension>
25+
Sub AddQueryDetails(this As Exception, query As String, sqlParams As IDataParameterCollection)
26+
this.Data.Add("Query", query)
27+
Try
28+
this.Data.Add("Parameters", sqlParams)
29+
Catch ex As Exception
30+
this.Data.Add("ParameterExceptionMessage", ex.Message)
31+
End Try
32+
End Sub
2233
End Module

source/SimplySql.Engine/ProviderBase.vb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Public MustInherit Class ProviderBase
3939
Public MustOverride Sub ChangeDatabase(databaseName As String) Implements ISimplySqlProvider.ChangeDatabase
4040

4141
Public Overridable Function HandleParamValue(x As Object) As Object
42+
If TypeOf x Is System.Management.Automation.PSObject Then x = DirectCast(x, System.Management.Automation.PSObject).BaseObject
4243
Return If(x, DBNull.Value)
4344
End Function
4445
#End Region

source/SimplySql.Engine/SimplySql.Engine.vbproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<PackageReference Include="Npgsql" Version="8.0.1" />
2626
<PackageReference Include="Npgsql.NetTopologySuite" Version="8.0.1" />
2727
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.19.220" />
28+
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
2829
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
2930
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.118" />
3031
</ItemGroup>

0 commit comments

Comments
 (0)