MySQLdb - A DB API v2.0 compatible interface to MySQL.
This package is a wrapper around _mysql, which mostly implements the MySQL C API.
connect() – connects to server
See the C API specification and the MySQL documentation for more info on other items.
For information on how MySQLdb handles type conversion, see the MySQLdb.converters module.
Factory function for connections.Connection.
Factory function for connections.Connection.
alias of date
alias of time
alias of datetime
Convert UNIX ticks into a date instance.
Convert UNIX ticks into a time instance.
Convert UNIX ticks into a datetime instance.
Bases: _mysql_exceptions.DatabaseError
Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range, etc.
Bases: _mysql_exceptions.Error
Exception raised for errors that are related to the database.
Bases: _mysql_exceptions.MySQLError
Exception that is the base class of all other error exceptions (not Warning).
Bases: _mysql_exceptions.DatabaseError
Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails, duplicate key, etc.
Bases: _mysql_exceptions.Error
Exception raised for errors that are related to the database interface rather than the database itself.
Bases: _mysql_exceptions.DatabaseError
Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync, etc.
Bases: exceptions.StandardError
Exception related to operation with MySQL.
Bases: _mysql_exceptions.DatabaseError
Exception raised in case a method or database API was used which is not supported by the database, e.g. requesting a .rollback() on a connection that does not support transaction or has transactions turned off.
Bases: frozenset
A special type of set for which A == x is true if A is a DBAPISet and x is a member of that set.
Bases: _mysql_exceptions.DatabaseError
Exception raised for errors that are related to the database’s operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc.
Bases: _mysql_exceptions.DatabaseError
Exception raised for programming errors, e.g. table not found or already exists, syntax error in the SQL statement, wrong number of parameters specified, etc.
Bases: exceptions.Warning, _mysql_exceptions.MySQLError
Exception raised for important warnings like data truncations while inserting, etc.
Factory function for connections.Connection.
Does a DBUG_PUSH with the given string. mysql_debug() uses the Fred Fish debug library. To use this function, you must compile the client library to support debugging.
escape(obj, dict) – escape any special characters in object obj using mapping dict to provide quoting functions for each type. Returns a SQL literal string.
escape_sequence(d, dict) – escape any special characters in dictionary d using mapping dict to provide quoting functions for each type. Returns a dictionary of escaped items.
escape_sequence(seq, dict) – escape any special characters in sequence seq using mapping dict to provide quoting functions for each type. Returns a tuple of escaped items.
escape_string(s) – quote any SQL-interpreted characters in string s.
Use connection.escape_string(s), if you use it at all. _mysql.escape_string(s) cannot handle character sets. You are probably better off using connection.escape(o) instead, since it will escape entire sequences as well as strings.
get_client_info() – Returns a string that represents the client library version.
string_literal(obj) – converts object obj into a SQL string literal. This means, any special SQL characters are escaped, and it is enclosed within single quotes. In other words, it performs:
“’%s’” % escape_string(str(obj))
Use connection.string_literal(obj), if you use it at all. _mysql.string_literal(obj) cannot handle character sets.
This module implements connections for MySQLdb. Presently there is only one class: Connection. Others are unlikely. However, you might want to make your own subclasses. In most cases, you will probably override Connection.default_cursor with a non-standard Cursor class.
Bases: _mysql.connection
MySQL Database Connection Object
Bases: _mysql_exceptions.DatabaseError
Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range, etc.
Bases: _mysql_exceptions.Error
Exception raised for errors that are related to the database.
Bases: _mysql_exceptions.MySQLError
Exception that is the base class of all other error exceptions (not Warning).
Bases: _mysql_exceptions.DatabaseError
Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails, duplicate key, etc.
Bases: _mysql_exceptions.Error
Exception raised for errors that are related to the database interface rather than the database itself.
Bases: _mysql_exceptions.DatabaseError
Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync, etc.
Bases: _mysql_exceptions.DatabaseError
Exception raised in case a method or database API was used which is not supported by the database, e.g. requesting a .rollback() on a connection that does not support transaction or has transactions turned off.
Bases: _mysql_exceptions.DatabaseError
Exception raised for errors that are related to the database’s operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc.
Bases: _mysql_exceptions.DatabaseError
Exception raised for programming errors, e.g. table not found or already exists, syntax error in the SQL statement, wrong number of parameters specified, etc.
Bases: exceptions.Warning, _mysql_exceptions.MySQLError
Exception raised for important warnings like data truncations while inserting, etc.
Explicitly begin a connection. Non-standard. DEPRECATED: Will be removed in 1.3. Use an SQL BEGIN statement instead.
Create a cursor on which queries may be performed. The optional cursorclass parameter is used to create the Cursor. By default, self.cursorclass=cursors.Cursor is used.
alias of Cursor
If cursor is not None, (errorclass, errorvalue) is appended to cursor.messages; otherwise it is appended to connection.messages. Then errorclass is raised with errorvalue as the value.
You can override this with your own error handler by assigning it to the instance.
If o is a single object, returns an SQL literal as a string. If o is a non-string sequence, the items of the sequence are converted and returned as a sequence.
Non-standard. For internal use; do not use this in your applications.
Set the connection character set to charset. The character set can only be changed in MySQL-4.1 and newer. If you try to change the character set from the current value in an older version, NotSupportedError will be raised.
Set the connection sql_mode. See MySQL documentation for legal values.
Return detailed information about warnings as a sequence of tuples of (Level, Code, Message). This is only supported in MySQL-4.1 and up. If your server is an earlier version, an empty sequence is returned.
MySQLdb type conversion module
This module handles all the type conversions for MySQL. If the default type conversions aren’t what you need, you can make your own. The dictionary conversions maps some kind of type to a conversion function which returns the corresponding value:
Key: FIELD_TYPE.* (from MySQLdb.constants)
Conversion function:
Arguments: string
Returns: Python object
Key: Python type object (from types) or class
Conversion function:
- Arguments: Python object of indicated type or class AND
- conversion dictionary
Returns: SQL literal value
- Notes: Most conversion functions can ignore the dictionary, but
- it is a required parameter. It is necessary for converting things like sequences and instances.
Don’t modify conversions if you can avoid it. Instead, make copies (with the copy() method), modify the copies, and then pass them to MySQL.connect().
Convert None to NULL.
Convert something into a SQL string literal. If using MySQL-3.23 or newer, string_literal() is a method of the _mysql.MYSQL object, and this function will be overridden with that method when the connection is created.
Convert something into a string via str().
Convert a unicode object to a string using the default encoding. This is only used as a placeholder for the real function, which is connection-dependent.
MySQLdb Cursors
This module implements Cursors of various types for MySQLdb. By default, MySQLdb uses the Cursor class.
Bases: MySQLdb.cursors.CursorStoreResultMixIn, MySQLdb.cursors.CursorTupleRowsMixIn, MySQLdb.cursors.BaseCursor
This is the standard Cursor class that returns rows as tuples and stores the result set in the client.
times module
This module provides some Date and Time classes for dealing with MySQL data.
Use Python datetime module to handle date and time columns.
Convert UNIX ticks into a date instance.
Format a DateTime object as an ISO timestamp.
Format a DateTimeDelta object as a time.
Convert UNIX ticks into a time instance.
Convert UNIX ticks into a datetime instance.
Convert a MySQL TIMESTAMP to a Timestamp object.