From 9d52bc57447fc86d7ea9eafc2a109a50f1095747 Mon Sep 17 00:00:00 2001 From: Teamcity Date: Fri, 25 Oct 2024 17:41:26 +0000 Subject: [PATCH 1/2] Bump plugin version to 0.2.10 for next development track --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9143d0f..9789cfb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "SQLServer", - "version": "0.2.9", + "version": "0.2.10", "author": "hackolade", "engines": { "hackolade": "7.7.10", From 010437b8acd14ebf4ae3deae7fe242b0f206fe5c Mon Sep 17 00:00:00 2001 From: Yevhenii Moroziuk Date: Mon, 28 Oct 2024 12:16:16 +0200 Subject: [PATCH 2/2] HCK-8490: Escape quotes in comment in DDL: SQLServer (#112) * HCK-8498: Fix DDL when single key in composite key (primary and unique) * HCK-8490: Escape quotes in comment in DDL: SQLServer * HCK-8490: Escape quotes in comment in DDL: SQLServer --------- Co-authored-by: Vitalii Yarmus <71256742+Vitalii4as@users.noreply.github.com> --- forward_engineering/configs/templates.js | 16 +++++------ forward_engineering/ddlProvider.js | 27 ++++++++++++------- .../helpers/columnDefinitionHelper.js | 25 ++++++++--------- .../helpers/constraintsHelper.js | 2 +- forward_engineering/utils/general.js | 8 ++++++ 5 files changed, 48 insertions(+), 30 deletions(-) diff --git a/forward_engineering/configs/templates.js b/forward_engineering/configs/templates.js index 267e2ce..82a11e7 100644 --- a/forward_engineering/configs/templates.js +++ b/forward_engineering/configs/templates.js @@ -91,16 +91,16 @@ module.exports = { dropType: 'DROP TYPE IF EXISTS ${name}${terminator}', createSchemaComment: - "EXEC sp_addextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}${terminator}", + "EXEC sp_addextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}${terminator}", createTableComment: - "EXEC sp_addextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}, 'table', ${tableName}${terminator}", + "EXEC sp_addextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}, 'table', ${tableName}${terminator}", createColumnComment: - "EXEC sp_addextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}, 'table', ${tableName}, 'column', ${columnName}${terminator}", + "EXEC sp_addextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}, 'table', ${tableName}, 'column', ${columnName}${terminator}", createViewComment: - "EXEC sp_addextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}, 'view', ${viewName}${terminator}", + "EXEC sp_addextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}, 'view', ${viewName}${terminator}", dropSchemaComment: "EXEC sp_dropextendedproperty 'MS_Description', 'schema', ${schemaName}${terminator}", @@ -114,14 +114,14 @@ module.exports = { "EXEC sp_dropextendedproperty 'MS_Description', 'schema', ${schemaName}, 'view', ${viewName}${terminator}", updateSchemaComment: - "EXEC sp_updateextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}${terminator}", + "EXEC sp_updateextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}${terminator}", updateTableComment: - "EXEC sp_updateextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}, 'table', ${tableName}${terminator}", + "EXEC sp_updateextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}, 'table', ${tableName}${terminator}", updateColumnComment: - "EXEC sp_updateextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}, 'table', ${tableName}, 'column', ${columnName}${terminator}", + "EXEC sp_updateextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}, 'table', ${tableName}, 'column', ${columnName}${terminator}", updateViewComment: - "EXEC sp_updateextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}, 'view', ${viewName}${terminator}", + "EXEC sp_updateextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}, 'view', ${viewName}${terminator}", }; diff --git a/forward_engineering/ddlProvider.js b/forward_engineering/ddlProvider.js index cc1adf4..7ab9d6d 100644 --- a/forward_engineering/ddlProvider.js +++ b/forward_engineering/ddlProvider.js @@ -40,7 +40,7 @@ module.exports = (baseProvider, options, app) => { const { wrapIfNotExistSchema, wrapIfNotExistDatabase, wrapIfNotExistTable, wrapIfNotExistView } = require('./helpers/ifNotExistStatementHelper')(app); const { getPartitionedTables, getCreateViewData } = require('./helpers/viewHelper')(app); - const { getFullTableName } = require('./utils/general')(_); + const { getFullTableName, escapeSpecialCharacters } = require('./utils/general')(_); const terminator = getTerminator(options); @@ -773,7 +773,7 @@ module.exports = (baseProvider, options, app) => { createSchemaComment({ schemaName, comment, customTerminator }) { return assignTemplates(templates.createSchemaComment, { - value: comment, + value: escapeSpecialCharacters(comment), schemaName: wrapInBrackets(schemaName), terminator: customTerminator ?? terminator, }); @@ -783,8 +783,9 @@ module.exports = (baseProvider, options, app) => { if (!schemaName) { return ''; } + return assignTemplates(templates.createTableComment, { - value: comment, + value: escapeSpecialCharacters(comment), schemaName: wrapInBrackets(schemaName), tableName: wrapInBrackets(tableName), terminator: customTerminator ?? terminator, @@ -795,8 +796,9 @@ module.exports = (baseProvider, options, app) => { if (!tableName || !columnName) { return ''; } + return assignTemplates(templates.createColumnComment, { - value: comment, + value: escapeSpecialCharacters(comment), schemaName: wrapInBrackets(schemaName), tableName: wrapInBrackets(tableName), columnName: wrapInBrackets(columnName), @@ -808,8 +810,9 @@ module.exports = (baseProvider, options, app) => { if (!schemaName) { return ''; } + return assignTemplates(templates.createViewComment, { - value: comment, + value: escapeSpecialCharacters(comment), schemaName: wrapInBrackets(schemaName), viewName: wrapInBrackets(viewName), terminator: customTerminator ?? terminator, @@ -827,6 +830,7 @@ module.exports = (baseProvider, options, app) => { if (!schemaName) { return ''; } + return assignTemplates(templates.dropTableComment, { schemaName: wrapInBrackets(schemaName), tableName: wrapInBrackets(tableName), @@ -838,6 +842,7 @@ module.exports = (baseProvider, options, app) => { if (!schemaName || !tableName) { return ''; } + return assignTemplates(templates.dropColumnComment, { schemaName: wrapInBrackets(schemaName), tableName: wrapInBrackets(tableName), @@ -850,6 +855,7 @@ module.exports = (baseProvider, options, app) => { if (!schemaName) { return ''; } + return assignTemplates(templates.dropViewComment, { schemaName: wrapInBrackets(schemaName), viewName: wrapInBrackets(viewName), @@ -859,7 +865,7 @@ module.exports = (baseProvider, options, app) => { updateSchemaComment({ schemaName, comment, customTerminator }) { return assignTemplates(templates.updateSchemaComment, { - value: comment, + value: escapeSpecialCharacters(comment), schemaName: wrapInBrackets(schemaName), terminator: customTerminator ?? terminator, }); @@ -869,8 +875,9 @@ module.exports = (baseProvider, options, app) => { if (!schemaName) { return ''; } + return assignTemplates(templates.updateTableComment, { - value: comment, + value: escapeSpecialCharacters(comment), schemaName: wrapInBrackets(schemaName), tableName: wrapInBrackets(tableName), terminator: customTerminator ?? terminator, @@ -881,8 +888,9 @@ module.exports = (baseProvider, options, app) => { if (!schemaName || !tableName) { return ''; } + return assignTemplates(templates.updateColumnComment, { - value: comment, + value: escapeSpecialCharacters(comment), schemaName: wrapInBrackets(schemaName), tableName: wrapInBrackets(tableName), columnName: wrapInBrackets(columnName), @@ -894,8 +902,9 @@ module.exports = (baseProvider, options, app) => { if (!schemaName) { return ''; } + return assignTemplates(templates.updateViewComment, { - value: comment, + value: escapeSpecialCharacters(comment), schemaName: wrapInBrackets(schemaName), viewName: wrapInBrackets(viewName), terminator: customTerminator ?? terminator, diff --git a/forward_engineering/helpers/columnDefinitionHelper.js b/forward_engineering/helpers/columnDefinitionHelper.js index 47d6c63..0eefc7d 100644 --- a/forward_engineering/helpers/columnDefinitionHelper.js +++ b/forward_engineering/helpers/columnDefinitionHelper.js @@ -3,6 +3,7 @@ const templates = require('../configs/templates'); module.exports = app => { const { assignTemplates } = app.require('@hackolade/ddl-fe-utils'); const _ = app.require('lodash'); + const { wrapInBrackets, escapeSpecialCharacters } = require('../utils/general')(_); const addLength = (type, length) => { return `${type}(${length})`; @@ -15,9 +16,9 @@ module.exports = app => { const addScalePrecision = (type, precision, scale) => { if (_.isNumber(scale)) { return `${type}(${precision},${scale})`; - } else { - return `${type}(${precision})`; } + + return `${type}(${precision})`; }; const addPrecision = (type, precision) => { @@ -69,17 +70,17 @@ module.exports = app => { return `'${escapeQuotes(defaultValue)}'`; } else if (type === 'XML') { return `CAST(N'${defaultValue}' AS xml)`; - } else { - return defaultValue; } + + return defaultValue; }; const getIdentity = identity => { if (!identity.seed || !identity.increment) { return ''; - } else { - return ` IDENTITY(${identity.seed}, ${identity.increment})`; } + + return ` IDENTITY(${identity.seed}, ${identity.increment})`; }; const addClustered = (statement, columnDefinition) => { @@ -89,9 +90,9 @@ module.exports = app => { if (!columnDefinition.clustered) { return statement + ' NONCLUSTERED'; - } else { - return statement + ' CLUSTERED'; } + + return statement + ' CLUSTERED'; }; const getEncryptedWith = encryption => { @@ -118,10 +119,10 @@ module.exports = app => { return ''; } const commentStatement = assignTemplates(templates.createColumnComment, { - value: comment, - schemaName: `[${schemaName}]`, - tableName: `[${tableName}]`, - columnName: `[${name}]`, + value: escapeSpecialCharacters(comment), + schemaName: wrapInBrackets(schemaName), + tableName: wrapInBrackets(tableName), + columnName: wrapInBrackets(name), terminator, }); diff --git a/forward_engineering/helpers/constraintsHelper.js b/forward_engineering/helpers/constraintsHelper.js index 302a90a..a021c23 100644 --- a/forward_engineering/helpers/constraintsHelper.js +++ b/forward_engineering/helpers/constraintsHelper.js @@ -66,7 +66,7 @@ module.exports = app => { const cleaned = clean(_.omit(keyData, 'keyType', 'indexOption', 'columns')); - return !_.isEmpty(cleaned) || keyData.columns?.length > 1; + return !_.isEmpty(cleaned) || keyData.columns?.length; }; const adaptIndexOptions = indexOption => { diff --git a/forward_engineering/utils/general.js b/forward_engineering/utils/general.js index 392d61e..267a47a 100644 --- a/forward_engineering/utils/general.js +++ b/forward_engineering/utils/general.js @@ -62,6 +62,7 @@ module.exports = _ => { } else if (!isNaN(name)) { return `\`${name}\``; } + return name; }; const replaceSpaceWithUnderscore = (name = '') => { @@ -79,6 +80,7 @@ module.exports = _ => { const getFullCollectionName = collectionSchema => { const collectionName = getEntityName(collectionSchema); const bucketName = collectionSchema.compMod?.keyspaceName; + return getNamePrefixedWithSchemaName(collectionName, bucketName); }; @@ -156,6 +158,10 @@ module.exports = _ => { return `[${name}]`; }; + const escapeSpecialCharacters = (name = '') => { + return name.replace(/'/g, "''"); + }; + const buildScript = statements => { const formattedScripts = statements .filter(Boolean) @@ -183,6 +189,7 @@ module.exports = _ => { if (!newProperty && !oldProperty) { return; } + return !_.isEqual(newProperty, oldProperty); }; @@ -209,6 +216,7 @@ module.exports = _ => { commentDeactivatedInlineKeys, buildScript, wrapInBrackets, + escapeSpecialCharacters, getFullEntityName, getFullTableName, getFullCollectionName,