Skip to content

Instantly share code, notes, and snippets.

@physacco
Created April 18, 2013 03:07
Show Gist options
  • Save physacco/5409729 to your computer and use it in GitHub Desktop.
Save physacco/5409729 to your computer and use it in GitHub Desktop.
Some notes about libmysql's API and the python MySQLdb module.

C API _mysql

|--------------------------------+-------------------------------------+------------------------------------------|
| C API                          | _mysql                              | Note                                     |
|--------------------------------+-------------------------------------+------------------------------------------|
| mysql_affected_rows()          | conn.affected_rows()                |                                          |
| mysql_autocommit()             | conn.autocommit()                   | COM_QUERY set autocommit=                |
| mysql_character_set_name()     | conn.character_set_name()           |                                          |
| mysql_close()                  | conn.close()                        | COM_QUIT                                 |
| mysql_commit()                 | conn.commit()                       |                                          |
| mysql_connect()                | _mysql.connect()                    |                                          |
| mysql_data_seek()              | result.data_seek()                  |                                          |
| mysql_debug()                  | _mysql.debug()                      |                                          |
| mysql_dump_debug_info          | conn.dump_debug_info()              | COM_DEBUG; ok for root; error for others |
| mysql_escape_string()          | _mysql.escape_string()              |                                          |
| mysql_fetch_row()              | result.fetch_row()                  |                                          |
| mysql_get_character_set_info() | conn.get_character_set_info()       | name, collation...; no communication     |
| mysql_get_client_info()        | _mysql.get_client_info()            | '5.1.55'; no communication               |
| mysql_get_host_info()          | conn.get_host_info()                | '127.0.0.1 via TCP/IP'; no communication |
| mysql_get_proto_info()         | conn.get_proto_info()               | 10; no communication                     |
| mysql_get_server_info()        | conn.get_server_info()              | '5.1.55'; no communication               |
| mysql_info()                   | conn.info()                         |                                          |
| mysql_insert_id()              | conn.insert_id()                    |                                          |
| mysql_num_fields()             | result.num_fields()                 |                                          |
| mysql_num_rows()               | result.num_rows()                   |                                          |
| mysql_options()                | various options to _mysql.connect() |                                          |
| mysql_ping()                   | conn.ping()                         | COM_PING                                 |
| mysql_query()                  | conn.query()                        |                                          |
| mysql_real_connect()           | _mysql.connect()                    |                                          |
| mysql_real_query()             | conn.query()                        |                                          |
| mysql_real_escape_string()     | conn.escape_string()                |                                          |
| mysql_rollback()               | conn.rollback()                     |                                          |
| mysql_row_seek()               | result.row_seek()                   |                                          |
| mysql_row_tell()               | result.row_tell()                   |                                          |
| mysql_select_db()              | conn.select_db()                    | COM_INIT_DB                              |
| mysql_set_character_set()      | conn.set_character_set()            |                                          |
| mysql_ssl_set()                | ssl option to _mysql.connect()      |                                          |
| mysql_stat()                   | conn.stat()                         | COM_STATISTICS                           |
| mysql_store_result()           | conn.store_result()                 |                                          |
| mysql_thread_id()              | conn.thread_id()                    | 3; no communication                      |
| mysql_thread_safe_client()     | conn.thread_safe_client()           |                                          |
| mysql_use_result()             | conn.use_result()                   |                                          |
| mysql_warning_count()          | conn.warning_count()                | no communication                         |
| CLIENT_*                       | MySQLdb.constants.CLIENT.*          |                                          |
| CR_*                           | MySQLdb.constants.CR.*              |                                          |
| ER_*                           | MySQLdb.constants.ER.*              |                                          |
| FIELD_TYPE_*                   | MySQLdb.constants.FIELD_TYPE.*      |                                          |
| FLAG_*                         | MySQLdb.constants.FLAG.*            |                                          |
|--------------------------------+-------------------------------------+------------------------------------------|

Does the MySQLdb module support prepared statements?

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment