Skip to content

Commit

Permalink
enable no transaction
Browse files Browse the repository at this point in the history
fixes #5159
  • Loading branch information
potatoqualitee committed Mar 10, 2019
1 parent 7db0ac3 commit afbaf95
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions functions/Import-DbaCsv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ function Import-DbaCsv {
.PARAMETER UseColumnDefault
Use the column default values if the field is not in the record.
.PARAMETER NoTransaction
Do not use a transaction when performing the import.
.PARAMETER WhatIf
Shows what would happen if the command were to run. No actions are actually performed.
Expand Down Expand Up @@ -257,6 +260,7 @@ function Import-DbaCsv {
[switch]$SkipEmptyLine,
[switch]$SupportsMultiline,
[switch]$UseColumnDefault,
[switch]$NoTransaction,
[switch]$EnableException
)
begin {
Expand Down Expand Up @@ -406,10 +410,12 @@ function Import-DbaCsv {
Stop-Function -Message "Failure" -Category ConnectionError -ErrorRecord $_ -Target $instance -Continue
}

if ($PSCmdlet.ShouldProcess($instance, "Starting transaction in $Database")) {
# Everything will be contained within 1 transaction, even creating a new table if required
# and truncating the table, if specified.
$transaction = $sqlconn.BeginTransaction()
if (-not $NoTransaction) {
if ($PSCmdlet.ShouldProcess($instance, "Starting transaction in $Database")) {
# Everything will be contained within 1 transaction, even creating a new table if required
# and truncating the table, if specified.
$transaction = $sqlconn.BeginTransaction()
}
}

# Ensure database exists
Expand Down Expand Up @@ -589,10 +595,12 @@ function Import-DbaCsv {
Stop-Function -Continue -Message "Failure" -ErrorRecord $_
}
}
if ($PSCmdlet.ShouldProcess($instance, "Committing transaction")) {
if ($PSCmdlet.ShouldProcess($instance, "Finalizing import")) {
if ($completed) {
# "Note: This count does not take into consideration the number of rows actually inserted when Ignore Duplicates is set to ON."
$null = $transaction.Commit()
if (-not $NoTransaction) {
$null = $transaction.Commit()
}
if ($script:core) {
$rowscopied = "Unsupported in Core"
} else {
Expand Down

0 comments on commit afbaf95

Please sign in to comment.