Comment crashes on SQL Server if comment already exists #13525
Labels
dialect: mssql
For issues and PRs. Things that involve MSSQL (and do not involve all dialects).
status: awaiting response
For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action
type: bug
Issue Creation Checklist
[x ] I have read the contribution guidelines
Issue Description
Storing Tables to SQL Server crashes if an extended Property already exists.
we suggest changing the Function CommentTemplate in MS SQL Querygenerator to
commentTemplate(comment, table, column) {
// Check if extended Property exists; insert / update accordingly
return
IF NOT EXISTS (SELECT NULL FROM SYS.EXTENDED_PROPERTIES WHERE [major_id] = OBJECT_ID(${this.quoteIdentifier(table)}) AND [name] = N'MS_Description' AND [minor_id] = (SELECT [column_id] FROM SYS.COLUMNS WHERE [name] = ${this.escape(column)} AND [object_id] = OBJECT_ID(${this.escape(table)}))) EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = ${this.escape(comment)}, @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = ${this.escape(table)}, @level2type = N'COLUMN', @level2name = ${this.escape(column)}; ELSE EXECUTE sp_updateextendedproperty @name = N'MS_Description', @value = ${this.escape(comment)}, @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = ${this.escape(table)}, @level2type = N'COLUMN', @level2name = ${this.escape(column)};
;Additional context
Add any other context or screenshots about the issue here.
Issue Template Checklist
Is this issue dialect-specific?
Would you be willing to resolve this issue by submitting a Pull Request?
YES -> See code to fix above
I am a first time contributor and am not 100% sure about the steps expected
The text was updated successfully, but these errors were encountered: