Import-DbaCsv, Export-DbaCsv - Normalize table/schema names via Get-ObjectNameParts#10306
Conversation
…bjectNameParts Fixes inconsistency where commands with bracketed table names (e.g. [My.Table]) failed because sys.tables stores bare names without brackets. - Import-DbaCsv: normalize $table/$schema with Get-ObjectNameParts before using them in parameterized metadata queries (sys.tables, sys.schemas, INFORMATION_SCHEMA.COLUMNS). Also handles two-part schema.table input. - Export-DbaCsv: replace naive dot-split regex with Get-ObjectNameParts so that names like [Gross.Table.Name] are correctly parsed instead of being split on the dot inside the brackets. Closes #9010 (do *Csv*) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
|
@claude please review this PR carefully as a lot of tests fail. Test-Output: |
|
Claude finished @andreasjordan's task in 1m 38s —— View job Review & Fix Complete
Root Cause
# After the if/elseif/else block that sets $tableName via $parsedTable...
$tableName = $nameParts.Name # ← $nameParts no longer exists → evaluates to $null
$sqlToExecute = "SELECT * FROM [$schemaName].[$tableName]"
# Result: SELECT * FROM [dbo].[] ← SQL Server rejects thisWhen the variable was renamed from
This affected all 12 test cases because every Fix AppliedRemoved the stale line —
|
…y table name Rename was incomplete: \$nameParts.Name on the line after the if/elseif/else block was not updated to \$parsedTable, overwriting \$tableName with \$null and producing SQL error "An object or column name is missing or empty". (do Export-DbaCsv) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
|
Ok, tests pass now. |
|
🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 thank you! |
Fixes inconsistency where commands with bracketed table names (e.g. [My.Table]) failed because sys.tables stores bare names without brackets.
Generated with Claude Code
Edit of andreasjordan:
Fixes part of #9010 - more PRs need to follow. So we keep the issue open but limit this PR to the DbaCsv commands. After this is merged we can find other commands that need the same fix.
IMPORTANT: This is a breaking change so maybe merge later together with other breaking changes and release a new version 2.8.0