Skip to content

Conversation

MaddyDev
Copy link
Contributor

@MaddyDev MaddyDev commented May 4, 2022

Fixes #232 where the column names are case insensitive, we are building the sql query converting the columns to lowercase but the javascript object keys are being passed as defined and the sql query is expecting lowercased values.

Fix: Added an extra step to convert the JObjects keys to lower case and passed that to the sql query.
Tried using the JsonSerializerSettings and passing the NamingStrategy to convert property names to lowercase but that was not working and still returned keys as is. Alternatively manually updated the properties to lower case by iterating through them.

{
// ToDo: add check for duplicate primary keys once we find a way to get primary keys.
// JObjects ignore serializer settings (https://web.archive.org/web/20171005181503/http://json.codeplex.com/workitem/23853)
// so we have to manually convert property names to lower case before inserting into the query in that case
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about case sensitive collations?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(even if this works, clarifying that it works in a comment would be helpful to readers)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case sensitive has always been up to the caller to get right - we have no way of knowing what the expected case is. Case insensitive is just always converted to lower case for comparisons for convenience (since the casing still has to be the same, but we can control that for case insensitive)

https://github.com/Azure/azure-functions-sql-extension/blob/main/src/SqlAsyncCollector.cs#L526

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This behavior should be documented somewhere but I don't think this is the right place to get into that fine of detail. I'll see if I can find a better place to do that)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaddyDev MaddyDev merged commit 19945e8 into main May 5, 2022
@MaddyDev MaddyDev deleted the maddy/fixJSCasingIssue branch May 5, 2022 02:23
PBBlox pushed a commit to PBBlox/azure-functions-sql-extension that referenced this pull request Apr 6, 2025
* add lowercasing of jobject properties

* add comments

* check for c# type

* Refactor

* remove unused

* fix

Co-authored-by: chgagnon <chgagnon@microsoft.com>
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.

Cannot insert the value NULL into column <COLUMN_NAME> on SQL output binding in Javascript function
3 participants