Public version of _process_params() to work on bytes and/or strings - OR - How to _process_params (escape, quote and type-transform) mysql parameters to use outside of mysql-connector/python - OR - cursor.py: _process_params(): returned strings (0.1.5), now bytes (0.3.2)

Asked by tormen

We have a mysql query stored as STRING in a mysql table.
This query needs to be modified within python code.
We used _process_params() to make sure things are well escaped.

This worked fine on our string within 0.1.5:
   strings --into--> _process_params() --> strings out of it
Now in 0.3.2 _process_params() this changed:
   strings --into--> _process_params() --> bytes out of it

I understand why this makes sense (to be able to handle byte (data) parameters).

But I was wondering if you could maybe provide a /public/ .processParams() function within cursor (or elsewhere) to use for the above use case.
And also make it usable for a string --> string case and bytes --> bytes (so to preserved whatever type it got passed in.

Thanks!

tormen

Question information

Language:
English Edit question
Status:
Answered
For:
MySQL Connector/Python Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Whiteboard:
Sorry about this question expiring. Yes, it makes sense to have some public function to process parameters, to make them ready for MySQL. We will consider it. Just need time to do it! :)
Revision history for this message
tormen (quickhelp) said :
#1

Sorry I titled the question (partly) as:
"How to escape mysql parameters to use outside of mysql-connector/python "

Because I meant _process_params, so all 3 things that this function does:
        "escape", "quote" and the conversion of python types to mysql

Beause we are having a list of python strings and want to put them into a mysql query, so the _process_params() seems nice to have (instead of calling .quote(), .escape() and .to_mysql() ourself).

Looking in conversion.py at .escape(): It seems to work transparently on bytes and strings,
but .quote() does NOT ... it misses the "if isinstance(value,bytes)" IMHO?!

I think My above problem should originate in _str_to_mysql(): It always encodes strings into (by default charset utf8) byte strings. Even though for a (utf8) string u'xxx' in python2 or '' in python3 this is not necessary.
This is a pity, because it would be nice to have the .to_myql() functionality to convert python types into mysql usable format available within a (public) .process_params() call somewhere...

Revision history for this message
Launchpad Janitor (janitor) said :
#2

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Geert JM Vanderkelen (geertjmvdk) said :
#3

Sorry about this question expiring. Yes, it makes sense to have some public function to process parameters, to make them ready for MySQL. We will consider it. Just need time to do it! :)

Can you help with this problem?

Provide an answer of your own, or ask tormen for more information if necessary.

To post a message you must log in.