Skip to content

Commit

Permalink
V1.9 updates (#64)
Browse files Browse the repository at this point in the history
* Update Classes.ps1 (#45)

- Replace `New-Object` with the `::new()` method on the type.

* Updated Mysql.data.dll version and related dependencies (#63)

* version summary updates

* Fixing .Prepare error duing BulkCopy for MySql provider

* moved .Prepare() to after parameters have been added.

* Removed Add-Type for google dll in MySql provider, unnecessary.

Co-authored-by: Joseph Alcorn <[email protected]>
Co-authored-by: Shawn Sesna <[email protected]>
  • Loading branch information
3 people authored May 28, 2022
1 parent cd7e5b9 commit 2dabd77
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 244 deletions.
2 changes: 1 addition & 1 deletion PesterTests/mysql.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ InModuleScope SimplySql {

Invoke-SqlBulkCopy -DestinationConnectionName bcp -SourceQuery $query -DestinationTable "mysql.tmpTable2" -Notify |
Should -Be 65536

Close-SqlConnection -ConnectionName bcp
}

Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ It has been released to PowerShellGallery. Installation is as simple as
This module requires PowerShell Version 5.0 or greater

## Latest Version

### 1.9.0
* Updated classes to use `::new()` constructor. thanks @joalcorn
* Updated MySql provider to use new library (8.0.28). thanks @twerthi
### 1.8.0
* Minor Update, enhancing progress notifications for Invoke-SqlBulkCopy, you can now specify -NotifyAction and pass in a scriptblock
### 1.7.0

* Minor update to expose the transaction object to the user via the new `Get-SqlTransaction` cmdlet.

[View Version History](VersionHistory.md)
4 changes: 2 additions & 2 deletions SimplySql/Classes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Class ProviderBase {
[int]$CommandTimeout = 30
[System.Data.IDbConnection]$Connection
[System.Data.IDbTransaction]$Transaction
[System.Collections.Generic.Queue[SqlMessage]]$Messages = (New-Object 'System.Collections.Generic.Queue[SqlMessage]')
[System.Collections.Generic.Queue[SqlMessage]]$Messages = ([System.Collections.Generic.Queue[SqlMessage]]::new())

ProviderBase() { If($this.GetType().Name -eq "ProviderBase") { Throw [System.InvalidOperationException]::new("ProviderBase must be inherited!") } }

Expand Down Expand Up @@ -154,4 +154,4 @@ Class ProviderBase {
static [System.Data.IDbConnection] CreateConnection([hashtable]$ht) {
Throw [System.NotImplementedException]::new("ProviderBase.CreateConnection must be overloaded!")
}
}
}
Binary file added SimplySql/Providers/MySql/BouncyCastle.Crypto.dll
Binary file not shown.
Binary file modified SimplySql/Providers/MySql/Google.Protobuf.dll
Binary file not shown.
Binary file not shown.
Binary file modified SimplySql/Providers/MySql/MySql.Data.dll
Binary file not shown.
Binary file added SimplySql/Providers/MySql/System.Memory.dll
Binary file not shown.
Binary file added SimplySql/Providers/MySql/Ubiety.Dns.Core.dll
Binary file not shown.
Binary file added SimplySql/Providers/MySql/ZstdNet.dll
Binary file not shown.
215 changes: 108 additions & 107 deletions SimplySql/Providers/MySql/config.ps1
Original file line number Diff line number Diff line change
@@ -1,108 +1,109 @@
#Load Up My Sql libraries
Add-Type -Path "$PSScriptRoot\MySql.Data.dll"

#Provider Class
. "$PSScriptRoot\provider.ps1"

#Open Cmdlet
Function Open-MySqlConnection {
<#
.Synopsis
Open a connection to a MySql Database.
.Description
Open a connection to a MySql Database.
MySql (MySql.Data)
MySql Managed Data Access @ https://dev.mysql.com/downloads/
.NET Provider @ https://www.nuget.org/packages/mysql.Data/6.9.9
.Parameter ConnectionName
The name to associate with the newly created connection.
This connection will be used with other cmdlets when specifying
-ConnectionName <name>. If you don't specify one, it will be
set to the default.
.Parameter ConnectionString
Specifies a provider specific connectionstring to be used.
.Parameter CommandTimeout
The default command timeout to be used for all commands executed against this connection.
.Parameter Server
The Server for the connection.
.Parameter Database
Database name.
.Parameter Port
Port to connect on, if different from default (3306).
.Parameter UserName
User to authenticate as. (deprecated, use -Credential)
.Parameter Password
Password for the user. (deprecated, use -Credential)
.Parameter SSLMode
None: Do not use SSL.
Required: Always use SSL. Deny connection if server does not support SSL. Do not perform server certificate validation.
VerifyCA: Always use SSL. Validate server SSL certificate, but different host name mismatch.
VerifyFull: Always use SSL and perform full certificate validation.
#>
[CmdletBinding(DefaultParameterSetName="default")]
Param([Parameter(ValueFromPipelineByPropertyName)][Alias("cn")][string]$ConnectionName = "default"
, [Parameter(ValueFromPipelineByPropertyName)][int]$CommandTimeout = 30
, [Parameter(ValueFromPipelineByPropertyName, ParameterSetName="default", Position=0)]
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName="userpass", Position=0)][string]$Server = "localhost"
, [Parameter(ValueFromPipelineByPropertyName, ParameterSetName="default", Position=1)]
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName="userpass", Position=1)][string]$Database = "mysql"
, [Parameter(ValueFromPipelineByPropertyName, ParameterSetName="default")]
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName="userpass")][int]$Port = 3306
, [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName="default")][pscredential]$Credential
, [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName="userpass")][string]$UserName
, [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName="userpass")][string]$Password
, [Parameter(ValueFromPipeline, ParameterSetName="default")]
[Parameter(ValueFromPipeline, ParameterSetName="userpass")]
[ValidateSet("None","Required","VerifyCA","VerifyFull")][string]$SSLMode = "None"
, [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName="Conn")][string]$ConnectionString)

If($Script:Connections.ContainsKey($ConnectionName)) { Close-SqlConnection $ConnectionName }

$sb = [MySql.Data.MySqlClient.MySqlConnectionStringBuilder]::new()

If($PSCmdlet.ParameterSetName -eq "Conn") { $conn = [MySql.Data.MySqlClient.MySqlConnection]::new($ConnectionString) }
Else {
$sb.Server = $Server
$sb.Database = $Database
If($Port) { $sb.Port = $Port }
If($Credential) {
$sb.UserID = $Credential.UserName
$sb.Password = $Credential.GetNetworkCredential().Password
}
Else {
Write-Warning "You are using -UserName and -Password, these options are deprecated and will be removed in the future. Please consider using -Credential."
$sb.UserId = $UserName
$sb.Password = $Password
}

$sb.UseAffectedRows = $true
$sb.AllowUserVariables = $true
$sb.SslMode = $SSLMode

$conn = [MySql.Data.MySqlClient.MySqlConnection]::new($sb.ConnectionString)
$sb.Clear()
$sb = $null
Remove-Variable sb
}

Try { $conn.Open() }
Catch {
$conn.Dispose()
Throw $_
}
$Script:Connections.$ConnectionName = [MySqlProvider]::new($ConnectionName, $CommandTimeout, $conn)
}

#Load Up My Sql libraries

Add-Type -Path "$PSScriptRoot\MySql.Data.dll"

#Provider Class
. "$PSScriptRoot\provider.ps1"

#Open Cmdlet
Function Open-MySqlConnection {
<#
.Synopsis
Open a connection to a MySql Database.
.Description
Open a connection to a MySql Database.
MySql (MySql.Data)
MySql Managed Data Access @ https://dev.mysql.com/downloads/
.NET Provider @ https://www.nuget.org/packages/mysql.Data/6.9.9
.Parameter ConnectionName
The name to associate with the newly created connection.
This connection will be used with other cmdlets when specifying
-ConnectionName <name>. If you don't specify one, it will be
set to the default.
.Parameter ConnectionString
Specifies a provider specific connectionstring to be used.
.Parameter CommandTimeout
The default command timeout to be used for all commands executed against this connection.
.Parameter Server
The Server for the connection.
.Parameter Database
Database name.
.Parameter Port
Port to connect on, if different from default (3306).
.Parameter UserName
User to authenticate as. (deprecated, use -Credential)
.Parameter Password
Password for the user. (deprecated, use -Credential)
.Parameter SSLMode
None: Do not use SSL.
Required: Always use SSL. Deny connection if server does not support SSL. Do not perform server certificate validation.
VerifyCA: Always use SSL. Validate server SSL certificate, but different host name mismatch.
VerifyFull: Always use SSL and perform full certificate validation.
#>
[CmdletBinding(DefaultParameterSetName="default")]
Param([Parameter(ValueFromPipelineByPropertyName)][Alias("cn")][string]$ConnectionName = "default"
, [Parameter(ValueFromPipelineByPropertyName)][int]$CommandTimeout = 30
, [Parameter(ValueFromPipelineByPropertyName, ParameterSetName="default", Position=0)]
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName="userpass", Position=0)][string]$Server = "localhost"
, [Parameter(ValueFromPipelineByPropertyName, ParameterSetName="default", Position=1)]
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName="userpass", Position=1)][string]$Database = "mysql"
, [Parameter(ValueFromPipelineByPropertyName, ParameterSetName="default")]
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName="userpass")][int]$Port = 3306
, [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName="default")][pscredential]$Credential
, [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName="userpass")][string]$UserName
, [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName="userpass")][string]$Password
, [Parameter(ValueFromPipeline, ParameterSetName="default")]
[Parameter(ValueFromPipeline, ParameterSetName="userpass")]
[ValidateSet("None","Required","VerifyCA","VerifyFull")][string]$SSLMode = "None"
, [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName="Conn")][string]$ConnectionString)

If($Script:Connections.ContainsKey($ConnectionName)) { Close-SqlConnection $ConnectionName }

$sb = [MySql.Data.MySqlClient.MySqlConnectionStringBuilder]::new()

If($PSCmdlet.ParameterSetName -eq "Conn") { $conn = [MySql.Data.MySqlClient.MySqlConnection]::new($ConnectionString) }
Else {
$sb.Server = $Server
$sb.Database = $Database
If($Port) { $sb.Port = $Port }
If($Credential) {
$sb.UserID = $Credential.UserName
$sb.Password = $Credential.GetNetworkCredential().Password
}
Else {
Write-Warning "You are using -UserName and -Password, these options are deprecated and will be removed in the future. Please consider using -Credential."
$sb.UserId = $UserName
$sb.Password = $Password
}

$sb.UseAffectedRows = $true
$sb.AllowUserVariables = $true
$sb.SslMode = $SSLMode

$conn = [MySql.Data.MySqlClient.MySqlConnection]::new($sb.ConnectionString)
$sb.Clear()
$sb = $null
Remove-Variable sb
}

Try { $conn.Open() }
Catch {
$conn.Dispose()
Throw $_
}
$Script:Connections.$ConnectionName = [MySqlProvider]::new($ConnectionName, $CommandTimeout, $conn)
}

Export-ModuleMember -Function Open-MySqlConnection
Loading

0 comments on commit 2dabd77

Please sign in to comment.