From 27483365f5e69584fc7667da6620b050dc236423 Mon Sep 17 00:00:00 2001 From: "steven.rogers" Date: Wed, 4 Feb 2026 11:53:42 +1000 Subject: [PATCH 1/3] Support spaces in table names Add new option to include column names as comments --- generalFuncs.js | 23 +++++++++++++++-------- package.json | 5 +++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/generalFuncs.js b/generalFuncs.js index 296de1a..07e2e0d 100644 --- a/generalFuncs.js +++ b/generalFuncs.js @@ -8,11 +8,12 @@ const extensionId = 'lz-scripts'; async function runForInsert( query) { let allowIdentity = vscode.workspace.getConfiguration('LzScripts').get('addIdentityColumns') === true; let allowMultipleInsert = vscode.workspace.getConfiguration('LzScripts').get('allowInsertPerRow') === true; + let includeColumnNamesAsComment = vscode.workspace.getConfiguration('LzScripts').get('includeColumnNamesAsComment') === true; let insetStr = []; let tableInfos = extractTableInfo(query); let tableInfo = tableInfos.length > 0 ? tableInfos[0] : {}; - let table = IsEmptyObj(tableInfo) ? '' : tableInfo.table.replaceAll('[','').replaceAll(']',''); + let table = IsEmptyObj(tableInfo) ? '' : tableInfo.table.replaceAll('[','').replaceAll(']','').trim(); const mssqlApi = await getMssqlApi(); const connectionUri = await connectToActiveEditor(); @@ -68,11 +69,14 @@ async function runForInsert( query) { if (data.columnInfo[col].isIdentity === true && !allowIdentity) continue; - if (data.columnInfo[col].dataTypeName !== 'timestamp') - dataStr += (`/* ${data.columnInfo[col].columnName} */ ` + ( - data.rows[row][col].isNull === true ? 'null' : + if (data.columnInfo[col].dataTypeName !== 'timestamp') { + if (includeColumnNamesAsComment) { + dataStr += `/* ${data.columnInfo[col].columnName} */ `; + } + dataStr += ((data.rows[row][col].isNull === true ? 'null' : getValue(data.rows[row][col].displayValue, data.columnInfo[col])) + ' ,'); + } } dataStr = dataStr.slice(0, dataStr.length - 1); @@ -90,11 +94,14 @@ async function runForInsert( query) { if (data.columnInfo[col].isIdentity === true && !allowIdentity) continue; - if (data.columnInfo[col].dataTypeName !== 'timestamp') - dataStr += (`/* ${data.columnInfo[col].columnName} */ ` + ( - data.rows[row][col].isNull === true ? 'null' : + if (data.columnInfo[col].dataTypeName !== 'timestamp') { + if (includeColumnNamesAsComment) { + dataStr += `/* ${data.columnInfo[col].columnName} */ `; + } + dataStr += ((data.rows[row][col].isNull === true ? 'null' : getValue(data.rows[row][col].displayValue, data.columnInfo[col])) + ' ,'); + } } dataStr = dataStr.slice(0, dataStr.length - 1); @@ -199,7 +206,7 @@ function IsEmptyObj(obj) } function extractTableInfo(sql) { - let regex = /\bFROM\s+([\w\.\[\]]+)|\bJOIN\s+([\w\.\[\]]+)|\bUPDATE\s+([\w\.\[\]]+)|\bINTO\s+([\w\.\[\]]+)/ig; + let regex = /\bFROM\s+([\w\.\s?\[\]]+)|\bJOIN\s+([\w\.\s?\[\]]+)|\bUPDATE\s+([\w\.\s?\[\]]+)|\bINTO\s+([\w\.\s?\[\]]+)/ig; let match; let tables = []; diff --git a/package.json b/package.json index f900481..faecda5 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,11 @@ "type": "boolean", "default": false, "description": "Generate Insert for each data row found" + }, + "LzScripts.includeColumnNamesAsComment": { + "type": "boolean", + "default": true, + "description": "Include column name as a comment in values" } } }, From 611920e791c436e290273a714efbc245d2933195 Mon Sep 17 00:00:00 2001 From: "steven.rogers" Date: Wed, 4 Feb 2026 14:38:43 +1000 Subject: [PATCH 2/3] removing question mark from regex --- generalFuncs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generalFuncs.js b/generalFuncs.js index 07e2e0d..02b0403 100644 --- a/generalFuncs.js +++ b/generalFuncs.js @@ -206,7 +206,7 @@ function IsEmptyObj(obj) } function extractTableInfo(sql) { - let regex = /\bFROM\s+([\w\.\s?\[\]]+)|\bJOIN\s+([\w\.\s?\[\]]+)|\bUPDATE\s+([\w\.\s?\[\]]+)|\bINTO\s+([\w\.\s?\[\]]+)/ig; + let regex = /\bFROM\s+([\w\.\s\[\]]+)|\bJOIN\s+([\w\.\s\[\]]+)|\bUPDATE\s+([\w\.\s\[\]]+)|\bINTO\s+([\w\.\s\[\]]+)/ig; let match; let tables = []; From 8f1e8068988f066b060a45af8269fb28bf953295 Mon Sep 17 00:00:00 2001 From: "steven.rogers" Date: Thu, 5 Feb 2026 11:04:20 +1000 Subject: [PATCH 3/3] only add identity_insert if the table has an identity column --- generalFuncs.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/generalFuncs.js b/generalFuncs.js index 02b0403..4d6283a 100644 --- a/generalFuncs.js +++ b/generalFuncs.js @@ -112,18 +112,19 @@ async function runForInsert( query) { } - return PostProcessing(insetStr, tableInfo.full, vscode.workspace.getConfiguration('LzScripts')); + return PostProcessing(insetStr, tableInfo.full, data, vscode.workspace.getConfiguration('LzScripts')); } /** * @param {string[]} insetStr + * @param {any} data * @param {vscode.WorkspaceConfiguration} config * @param {string} table */ -function PostProcessing(insetStr, table, config) { +function PostProcessing(insetStr, table, data, config) { let allowIdentity = config.get('addIdentityColumns') === true; - if (allowIdentity) { + if (allowIdentity && data.columnInfo.some(x=>x.isIdentity === true)) { insetStr.unshift(`set identity_insert ${table} on; \ngo; \n`); insetStr.push(`set identity_insert ${table} off; \ngo; \n`); }