11

Does MySQLdb support server-side prepared statements? I can't figure this out from its manual.

RubenGeert
  • 2,902
  • 6
  • 32
  • 50
planetp
  • 14,248
  • 20
  • 86
  • 160

2 Answers2

18

Check the MySQLdb Package Comments:

"Parameterization" is done in MySQLdb by escaping strings and then blindly interpolating them into the query, instead of using the MYSQL_STMT API. As a result unicode strings have to go through two intermediate representations (encoded string, escaped encoded string) before they're received by the database.

So the answer is: No, it doesn't.

Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
12

It has some kind of parameterization, yes.

Even then, I advise you switch to oursql. It brings a lot of advantages over MySQLdb:

  • oursql has real parameterization.
  • oursql allows text or binary data to be streamed into the database and streamed out of the database, instead of requiring everything to be buffered in the client.
  • oursql can both insert rows lazily and fetch rows lazily.
  • oursql has unicode support on by default.
  • oursql supports python 2.4 through 2.7 without any deprecation warnings on 2.6+ (see PEP 218) and without completely failing on 2.7 (see PEP 328).
  • oursql is licensed under the BSD license.
nosklo
  • 217,122
  • 57
  • 293
  • 297