diff --git a/console/src/components/Services/Data/RawSQL/utils.js b/console/src/components/Services/Data/RawSQL/utils.js index ae99a9e2877..10a728d192d 100644 --- a/console/src/components/Services/Data/RawSQL/utils.js +++ b/console/src/components/Services/Data/RawSQL/utils.js @@ -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); }