Skip to content
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

Allow SFDataConverter to convert from AnsiString to TEXT #1106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

seantempleton
Copy link

The following error is observed when trying to insert or update a TEXT column with a DbParameter of type AnsiString whose value is DBNull. "No corresponding Snowflake type for type AnsiString."

To reproduce this with the Dapper ORM library, set Dapper to use DbType.AnsiString for .NET strings with this "SqlMapper.AddTypeMap(typeof(string), System.Data.DbType.AnsiString);". Try to insert or update a TEXT column with a null value for a string and the exception will be thrown. Alternatively, without Dapper, create a SnowflakeDbParameter and set the DbType to AnsiString and the Value to DBNull.Value.

Using AnsiString with an actual value works because the DbType property in SnowflakeDbParameter knows there is a value, calls GetType(), which returns System.String, and then uses the TypeToDbTypeMap which maps to DbType.String.

When the value is DBNull the DbType property checks for DBNull and simply returns DbType.AnsiString. CSharpTypeValToSfTypeVal() then throws the exception due to the AnsiString type not being in the switch statement.

The following error is observed when trying to insert or update a TEXT column with a DbParameter of type AnsiString whose value is DBNull. "No corresponding Snowflake type for type AnsiString."
To reproduce this with the Dapper ORM library, set Dapper to use DbType.AnsiString for .NET strings with this "SqlMapper.AddTypeMap(typeof(string), System.Data.DbType.AnsiString);". Try to insert or update a TEXT column with a null value for a string and the exception will be thrown.
Alternatively, without Dapper, create a SnowflakeDbParameter and set the DbType to AnsiString and the Value to DBNull.Value.

Using AnsiString with an actual value works because the DbType property in SnowflakeDbParameter knows there is a value, calls GetType(), which returns System.String, and then uses the TypeToDbTypeMap which maps to DbType.String.
When the value is DBNull the DbType property checks for DBNull and simply returns DbType.AnsiString. CSharpTypeValToSfTypeVal() then throws the exception due to the AnsiString type not being in the switch statement.
@seantempleton seantempleton requested a review from a team as a code owner February 27, 2025 16:39
Copy link

github-actions bot commented Feb 27, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@seantempleton
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant