Escape table names and keys

Summary:
https://github.com/facebook/flipper/issues/1426

Changelog: [Databases] Fixed escaping of column names, see #1426

Reviewed By: jknoxville

Differential Revision: D23293248

fbshipit-source-id: 6acbb87727524ba2bdc7973cad8c124a3ee026e6
This commit is contained in:
Michel Weststrate
2020-08-24 08:06:56 -07:00
committed by Facebook GitHub Bot
parent 39a465b8b8
commit 0b528f19ce
2 changed files with 12 additions and 12 deletions

View File

@@ -58,9 +58,9 @@ export function constructQueryClause(
? `'${val.value.replace(/'/g, "''")}'`
: `${val.value}`;
if (idx <= 0) {
return `${key}=${valueString}`;
return `\`${key}\`=${valueString}`;
} else {
return `${clauses} ${connector} ${key}=${valueString}`;
return `${clauses} ${connector} \`${key}\`=${valueString}`;
}
},
'',
@@ -72,7 +72,7 @@ export function constructUpdateQuery(
where: {[key: string]: Value},
change: {[key: string]: Value},
): string {
return `UPDATE ${table}
return `UPDATE \`${table}\`
SET ${constructQueryClause(change, ',')}
WHERE ${constructQueryClause(where, 'AND')}`;
}