handle capital letters and quotes in Raw SQL Track this (#1811)

This commit is contained in:
Rikin Kachhia 2019-03-19 14:23:19 +05:30 committed by GitHub
parent 97ac88edb5
commit 2bc2c40532
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,14 +2,23 @@ const createSQLRegex = /create\s*(?:|or\s*replace)\s*(view|table|function)\s*((\
const createSQLRegexNoFunction = /create\s*(?:|or\s*replace)\s*(view|table)\s*((\"?\w+\"?)\.(\"?\w+\"?)|(\"?\w+\"?))/; // eslint-disable-line
const getSQLValue = value => {
const quotedStringRegex = /^".*"$/;
let sqlValue = value;
if (!quotedStringRegex.test(value)) {
sqlValue = value.toLowerCase();
}
return sqlValue.replace(/['"]+/g, '');
};
const parseCreateSQL = (sql, allowFunction) => {
const _objects = [];
const formattedSQL = sql.toLowerCase();
const regExp = allowFunction ? createSQLRegex : createSQLRegexNoFunction;
const matches = formattedSQL.match(new RegExp(regExp, 'gmi'));
const matches = sql.match(new RegExp(regExp, 'gmi'));
if (matches) {
matches.forEach(element => {
const itemMatch = element.match(new RegExp(regExp, 'i'));
@ -32,8 +41,8 @@ const parseCreateSQL = (sql, allowFunction) => {
}
_object.type = type.toLowerCase();
_object.name = name.replace(/['"]+/g, '').trim();
_object.schema = schema.replace(/['"]+/g, '').trim();
_object.name = getSQLValue(name);
_object.schema = getSQLValue(schema);
_objects.push(_object);
}