Created
September 7, 2012 10:36
-
-
Save moqada/3665003 to your computer and use it in GitHub Desktop.
convert paramstyle format for MySQL to SQLite...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import re | |
PYFORMAT_REGEX = re.compile(r'%\((.*?)\)s') | |
def paramstyle_to_format(sql, params): | |
u""" paramstyle: pyformat -> format | |
""" | |
param_keys = PYFORMAT_REGEX.findall(sql) | |
sql = PYFORMAT_REGEX.sub('%s', sql) | |
new_params = [v for k, v in params.items() if k in param_keys] | |
return sql, new_params |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment