🐛 Fix connectionTimeout, add requestTImeout and fix issue with column names with spaces (#1971)

* 🐛 fix issue sending connectionTimeout parameter

* 🐛 Fix issue when inserting data using columns with spaces

* 🐛 Fix issue when updating data using columns with spaces

* 🐛 Fix issue when deleting data using columns with spaces

Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Ricardo Espinoza 2021-07-06 18:26:34 -04:00 committed by GitHub
parent 8d235e94cb
commit c7db9c0a4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View file

@ -57,5 +57,12 @@ export class MicrosoftSql implements ICredentialType {
default: 15000, default: 15000,
description: 'Connection timeout in ms.', description: 'Connection timeout in ms.',
}, },
{
displayName: 'Request Timeout',
name: 'requestTimeout',
type: 'number',
default: 15000,
description: ' Request timeout in ms.',
},
]; ];
} }

View file

@ -121,7 +121,7 @@ export function extractUpdateSet(item: IDataObject, columns: string[]): string {
return columns return columns
.map( .map(
column => column =>
`${column} = ${ `"${column}" = ${
typeof item[column] === 'string' ? `'${item[column]}'` : item[column] typeof item[column] === 'string' ? `'${item[column]}'` : item[column]
}`, }`,
) )
@ -153,3 +153,9 @@ export function extractDeleteValues(items: IDataObject[], key: string): string {
.map(item => (typeof item[key] === 'string' ? `'${item[key]}'` : item[key])) .map(item => (typeof item[key] === 'string' ? `'${item[key]}'` : item[key]))
.join(',')})`; .join(',')})`;
} }
export function formatColumns(columns: string) {
return columns.split(',')
.map((column) => (`"${column.trim()}"`)).join(',');
}

View file

@ -29,6 +29,7 @@ import {
extractUpdateCondition, extractUpdateCondition,
extractUpdateSet, extractUpdateSet,
extractValues, extractValues,
formatColumns,
} from './GenericFunctions'; } from './GenericFunctions';
export class MicrosoftSql implements INodeType { export class MicrosoftSql implements INodeType {
@ -226,7 +227,8 @@ export class MicrosoftSql implements INodeType {
user: credentials.user as string, user: credentials.user as string,
password: credentials.password as string, password: credentials.password as string,
domain: credentials.domain ? (credentials.domain as string) : undefined, domain: credentials.domain ? (credentials.domain as string) : undefined,
connectTimeout: credentials.connectTimeout as number, connectionTimeout: credentials.connectTimeout as number,
requestTimeout: credentials.requestTimeout as number,
options: { options: {
encrypt: credentials.tls as boolean, encrypt: credentials.tls as boolean,
enableArithAbort: false, enableArithAbort: false,
@ -281,7 +283,7 @@ export class MicrosoftSql implements INodeType {
return pool return pool
.request() .request()
.query( .query(
`INSERT INTO ${table}(${columnString}) VALUES ${values};`, `INSERT INTO ${table}(${formatColumns(columnString)}) VALUES ${values};`,
); );
}); });
}, },
@ -364,7 +366,7 @@ export class MicrosoftSql implements INodeType {
return pool return pool
.request() .request()
.query( .query(
`DELETE FROM ${table} WHERE ${deleteKey} IN ${extractDeleteValues( `DELETE FROM ${table} WHERE "${deleteKey}" IN ${extractDeleteValues(
deleteValues, deleteValues,
deleteKey, deleteKey,
)};`, )};`,