my default mysql paramstle is :'format'
>>>MySQLdb.paramstyle
'format'
i want to change default paramstyle to 'pyformat' ,because of i can have query something like "WHERE name=%(name)s". is there any way to do that?
I'm pretty sure this isn't possible without monkeying around inside the librarie's internals... -- The paramstyle
is hardcoded to conform to PEP 249.
Also notice that the escaping always uses a tuple
...
I imagine you could get that to work if you replaced:
if args is not None:
query = query % tuple(( get_codec(a, self.encoders)(db, a) for a in args ))
with something like:
if args is not None:
if isinstance(args, tuple):
args = tuple(get_codec(a, self.encoders)(db, a) for a in args)
elif isinstance(args, dict):
args = {k: get_codec(a, self.encoders)(db, a) for a in args}
query = query % args
Here you'd probably want to do this in a Cursor subclass -- and you can pass that as an argument to the connection...
Ultimately, this is a bit "hairy" since re-writing the entire execute method will likely force you to use a bunch of stuff that isn't in the "public" API, but it should be possible at least.