Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shared/helpers/instanceHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const getTableDdl = async ({ connection, schemaName, tableName, objectType, logg

await connection.execute({ query: clearQuery, callable: true, inparam: opToken });

return ddlResult.map(row => queryHelper.ensureTerminator({ query: row.SQL_STMT })).join('\n');
return ddlResult.map(queryHelper.postProcessDdlStatement).join('\n');
} catch (error) {
logger.error(error);

Expand Down
21 changes: 21 additions & 0 deletions shared/helpers/queryHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ const cleanUpQuery = ({ query = '' }) => query.replaceAll(/\s+/g, ' ');

const ensureTerminator = ({ query = '' }) => (query.trimEnd().endsWith(';') ? query : `${query};`);

/**
* finds every quoted identifier and removes *only* trailing whitespace
* @param {{ query: string }} params
* @returns {string}
*/
const normalizeDb2Identifiers = ({ query = '' }) => {
return query.replaceAll(/"([^"]*)"/g, (_, name) => `"${name.trimEnd()}"`);
};

/**
* @param {{ query: string, schemaNameKeyword: string }} params
* @returns {string}
Expand Down Expand Up @@ -109,6 +118,16 @@ const getClearTableDdlQuery = () => {
return 'CALL SYSPROC.DB2LK_CLEAN_TABLE(?);';
};

/**
* @param {{ SQL_STMT: string}} row - select query ddl result
* @returns {string}
*/
const postProcessDdlStatement = row => {
let statement = queryHelper.ensureTerminator({ query: row.SQL_STMT });
statement = queryHelper.normalizeDb2Identifiers({ query: statement });
return statement;
};

const queryHelper = {
cleanUpQuery,
getDbVersionQuery,
Expand All @@ -119,6 +138,8 @@ const queryHelper = {
getSelectTableDdlQuery,
getClearTableDdlQuery,
ensureTerminator,
normalizeDb2Identifiers,
postProcessDdlStatement,
};

module.exports = {
Expand Down