Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion public/Copy-DbaDbTableData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@ function Copy-DbaDbTableData {

process {
if ((Test-Bound -Not -ParameterName InputObject) -and ((Test-Bound -Not -ParameterName SqlInstance, Database -And) -or (Test-Bound -Not -ParameterName Table, View))) {
Stop-Function -Message "You must pipe in a table or specify SqlInstance, Database and [View|Table]."
if (Test-Bound -ParameterName Query) {
# Without the hint at Query the message reads as if SqlInstance or Database were missing (see #10676).
Stop-Function -Message "When using Query, you still have to specify SqlInstance, Database and [View|Table]. The query determines the data that is copied, but the command needs the table or view as the source object for its metadata."
} else {
Stop-Function -Message "You must pipe in a table or specify SqlInstance, Database and [View|Table]."
}
return
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Copy-DbaDbTableData.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ Describe $CommandName -Tag IntegrationTests {
$result = Copy-DbaDbTableData -SqlInstance $TestConfig.InstanceCopy2 -Database tempdb -Table dbo.dbatoolsci_example4 -Query "SELECT TOP (1) Id FROM tempdb.dbo.dbatoolsci_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate
$result.RowsCopied | Should -Be 1
}

It "Points at the Query requirement when Query is used without a source table" {
# The generic message reads as if SqlInstance or Database were missing (#10676).
$splatQueryOnly = @{
SqlInstance = $TestConfig.InstanceCopy2
Database = "tempdb"
Query = "SELECT TOP (1) Id FROM dbo.dbatoolsci_example4"
DestinationTable = "dbatoolsci_example3"
WarningAction = "SilentlyContinue"
}
$result = Copy-DbaDbTableData @splatQueryOnly
$result | Should -BeNullOrEmpty
$WarnVar | Should -Match "When using Query"
}
}

Context "When testing pipeline functionality" {
Expand Down