-
-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DbaCsv needs support for GUID target columns #9433
Comments
If you think it's an issue with SqlBulkCopy - why don't you open an issue against SqlBulkCopy? As you have shown, there is nothing dbatools can do here. |
I don't believe that I've demonstrated there is nothing to be done. A cursory glance at the SqlBulkCopy source code seems to imply that GUID support exists (it would be a little shocking if it didn't). While I am unable at this time to parse out where the root cause exists, I'll be happy to open up an issue against either the SqlBulkCopy source or docs pages as and when the time seems ripe to do so. Even assuming SqlBulkCopy must be modified at source to support GUID target types, I imagine the lack of support demonstrated in this issue might warrant the addition of a unit test on resolution. |
My last comment was maybe too short. I don't see a quick fix. And I don't have time to do deeper investigations. So if you have the time and a solution, I would be happy to include it in the dbatools source code. But maybe in the future, some other contributor can take the time and come up with a solution. |
if bulkcopy didn't support GUIDs there would be zillions of users ranting. |
Idk, there appears to exist a GUID unit test in the LumenWorks source 🤔 namespace LumenWorks.Framework.Tests.Unit.IO.Csv
{
[TestFixture]
public class ColumnTests
{
[Test]
public void ConvertGuid()
{
var expected = Guid.NewGuid();
var column = new Column { Name = "A", Type = typeof(Guid) };
var candidate = column.Convert(expected.ToString());
Assert.IsInstanceOf<Guid>(candidate);
Assert.That(expected == (Guid)candidate);
} |
and what tells lumen to use a guid column when reading ? it doesn't do heuristic AFAIK, so we know that lumen supports guid, but IMHO we're not telling via Import-DbaCsv (again, AFAIK, we support playing with column mapping via NAME, nothing via TYPE) that a guid column is needed when reading the csv. |
BTW, definitely related to #8409 as noted in the issue, it's the same exact deal (in that case, we're not telling Lumen to output a bit, in this we're not telling Lumen to output a guid) |
so, ideally, fixable. I'll work on this and report back if there are further limitations |
This condition pops if-and-only-if we're inserting to a pre-existing table. At first thought a schema check would allow mapping of this sort. Since |
when the table gets autocreated all columns are nvarchar(max) so it's easy :D |
I did not forget about this, something that seemed like a 50LOC update is turning into a 500LOC one. I need to play a bit with lumen's API (fortunately there are examples to follow) directly in c# to figure out how to make it work on PS. |
Verified issue does not already exist?
I have searched and found no existing issue
What error did you receive?
No obvious quick fix jumps out at me reading through the SqlBulkCopy docs at this time.
Possibly related: #8409
Steps to Reproduce
It appears that the
SqlBulkCopy
object as currently defined inInvoke-DbaCsv
does not support inserting valid guid strings into auniqueidentifier
target column.The below repro errors out:
I tried to step through the source code to see if there was something obvious I was missing about this functionality. Extracting just the relevant code for a minimal repro appears to indicate that this may be an underlying issue with
SqlBulkCopy
SqlBulkCopy repro initialisation
After running the above initialisation, executing the below errors out.
Please confirm that you are running the most recent version of dbatools
v2.1.15
- May 18, 2024Other details or mentions
Slack channel chat context: https://sqlcommunity.slack.com/archives/C1M2WEASG/p1721846945371649
What PowerShell host was used when producing this error
VS Code (integrated terminal)
PowerShell Host Version
SQL Server Edition and Build number
.NET Framework Version
.NET 8.0.6
The text was updated successfully, but these errors were encountered: