Skip to content

Instantly share code, notes, and snippets.

@moqada
Created September 7, 2012 10:36
Show Gist options
  • Save moqada/3665003 to your computer and use it in GitHub Desktop.
Save moqada/3665003 to your computer and use it in GitHub Desktop.
convert paramstyle format for MySQL to SQLite...
# -*- 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