Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_snowflake_lexicon(self):
from jardin.database.drivers.sf import Lexicon
sql, params = Lexicon.standardize_interpolators(
'SELECT * FROM users WHERE a = %(abc)s AND b = %(def)s',
{'def': 2, 'abc': 1}
)
self.assertEqual(
'SELECT * FROM users WHERE a = %s AND b = %s',
sql
)
self.assertEqual([1, 2], params)
def standardize_interpolators(sql, params):
sql, params = super(Lexicon, Lexicon).standardize_interpolators(sql, params)
param_names = re.findall(r'\%\((\w+)\)s', sql)
if len(param_names):
sql = re.sub(r'\%\(\w+\)s', '%s', sql)
if isinstance(params, dict):
params = list(map(lambda x: params[x], param_names))
return sql, params