Skip to content

Fix SQL column names with spaces and reserved keywords#86

Merged
PhenX merged 4 commits intomainfrom
copilot/fix-sql-column-names-issue
Dec 21, 2025
Merged

Fix SQL column names with spaces and reserved keywords#86
PhenX merged 4 commits intomainfrom
copilot/fix-sql-column-names-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 21, 2025

  • Analyze the issue: SQL column names with spaces/reserved keywords fail during bulk insert
  • Identify root cause: GetUpdates() method in SqlDialectBuilder.cs uses unquoted column names
  • Fix GetUpdates() in SqlDialectBuilder.cs to use GetQuotedColumnName() instead of GetColumnName()
  • Add test entity with column name containing spaces (TestEntityWithSpecialColumnNames)
  • Add test for bulk insert with special column names
  • Verify fix works with existing tests (93 tests pass)
  • Run code review - no issues found
  • Run security scanning - no vulnerabilities found
  • Skip merge test on Oracle (does not support insert+merge+return)
Original prompt

This section details on the original issue you should resolve

<issue_title>SQL Column Names with Spaces and Keywords Fail</issue_title>
<issue_description>We have a legacy SQL database running in Sql 2019 with a column name Business Function Text mapped to an entity with property named BusinessFunctionText. When executing a bulk insert we're getting the error:

fail: HcmDataApi.Scheduler.Jobs.SyncHcmDatabaseJob[0]
      Failed to run task SyncHcmInfo. Incorrect syntax near the keyword 'Function'.
      Microsoft.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near the keyword 'Function'.
         at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
         at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
         at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, SqlCommand command, Boolean callerHasConnectionLock, Boolean asyncClose)
         at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
         at Microsoft.Data.SqlClient.SqlCommand.InternalEndExecuteNonQuery(IAsyncResult asyncResult, Boolean isInternal, String endMethod)
         at Microsoft.Data.SqlClient.SqlCommand.EndExecuteNonQueryInternal(IAsyncResult asyncResult)
         at Microsoft.Data.SqlClient.SqlCommand.EndExecuteNonQueryAsync(IAsyncResult asyncResult)
         at Microsoft.Data.SqlClient.SqlCommand.<>c.<InternalExecuteNonQueryAsync>b__193_1(IAsyncResult asyncResult)
         at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)

If I were to wager a guess it would be that the translation is not handling the column name with spaces properly perhaps. If this is the case - it should be wrapping it in square braces:

SELECT [Business Function Text] FROM MyTable
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Changed GetColumnName to GetQuotedColumnName in SqlDialectBuilder.GetUpdates()
to properly quote column names in UPDATE SET clauses.

Added test entity TestEntityWithSpecialColumnNames with columns like
"Business Function Text" and "Order Number" to verify the fix.

Added test cases for both basic insert and merge operations with
special column names.

Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SQL column names with spaces and keywords issue Fix SQL column names with spaces and reserved keywords Dec 21, 2025
Copilot AI requested a review from PhenX December 21, 2025 10:46
@PhenX
Copy link
Copy Markdown
Owner

PhenX commented Dec 21, 2025

@copilot ignore the insert+merge+return test on oracle as it does not support it

Oracle does not support insert+merge+return operations.

Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 21, 2025

@copilot ignore the insert+merge+return test on oracle as it does not support it

Done in 1045b60. Added Oracle to the skip list for the InsertEntities_WithSpecialColumnNames_Merge test.

@PhenX PhenX marked this pull request as ready for review December 21, 2025 12:39
@PhenX PhenX merged commit c9a8eb6 into main Dec 21, 2025
2 checks passed
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.

SQL Column Names with Spaces and Keywords Fail

2 participants