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.
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.
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 an Instance to a string representation. If the __str__() method produces acceptable output, then you don’t need to add the class to conversions; it will be handled by the default converter. If the exact class is not found in d, it will use the first class it can find for which o is an instance.
Convert something into a string via str().
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.
MySQLdb Cursors
This module implements Cursors of various types for MySQLdb. By default, MySQLdb uses the Cursor class.
Bases: object
A base for Cursor classes. Useful attributes:
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: _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.
Execute stored procedure procname with args
procname – string, name of procedure to execute on server
args – Sequence of parameters to use with procedure
Returns the original args.
Compatibility warning: PEP-249 specifies that any modified parameters must be returned. This is currently impossible as they are only available by storing them in a server variable and then retrieved by a query. Since stored procedures return zero or more result sets, there is no reliable way to get at OUT or INOUT parameters via callproc. The server variables are named @_procname_n, where procname is the parameter above and n is the position of the parameter (from zero). Once all result sets generated by the procedure have been fetched, you can issue a SELECT @_procname_0, ... query using .execute() to get any OUT or INOUT values.
Compatibility warning: The act of calling a stored procedure itself creates an empty result set. This appears after any result sets generated by the procedure. This is non-standard behavior with respect to the DB-API. Be sure to use nextset() to advance through all result sets; otherwise you may get disconnected.
Execute a query.
query – string, query to execute on server args – optional sequence or mapping, parameters to use with query.
Note: If args is a sequence, then %s must be used as the parameter placeholder in the query. If a mapping is used, %(key)s must be used as the placeholder.
Returns long integer rows affected, if any
Execute a multi-row query.
query – string, query to execute on server
args
Sequence of sequences or mappings, parameters to use with query.
Returns long integer rows affected, if any.
This method improves performance on multiple-row INSERT and REPLACE. Otherwise it is equivalent to looping over args with execute().
Bases: cup.thirdp.MySQLdb.cursors.CursorStoreResultMixIn, cup.thirdp.MySQLdb.cursors.CursorTupleRowsMixIn, cup.thirdp.MySQLdb.cursors.BaseCursor
This is the standard Cursor class that returns rows as tuples and stores the result set in the client.
Bases: object
This is a MixIn class that causes all rows to be returned as dictionaries. This is a non-standard feature.
Fetch all available rows as a list of dictionaries. Deprecated: Use fetchall() instead. Will be removed in 1.3.
Bases: cup.thirdp.MySQLdb.cursors.CursorDictRowsMixIn
This is a MixIn class that returns rows as dictionaries with the same key convention as the old Mysqldb (MySQLmodule). Don’t use this.
Bases: object
This is a MixIn class which causes the entire result set to be stored on the client side, i.e. it uses mysql_store_result(). If the result set can be very large, consider adding a LIMIT clause to your query, or using CursorUseResultMixIn instead.
Fetch up to size rows from the cursor. Result set may be smaller than size. If size is not defined, cursor.arraysize is used.
Bases: object
This is a MixIn class that causes all rows to be returned as tuples, which is the standard form required by DB API.
Bases: object
This is a MixIn class which causes the result set to be stored in the server and sent row-by-row to client side, i.e. it uses mysql_use_result(). You MUST retrieve the entire result set and close() the cursor before additional queries can be peformed on the connection.
Bases: cup.thirdp.MySQLdb.cursors.CursorStoreResultMixIn, cup.thirdp.MySQLdb.cursors.CursorDictRowsMixIn, cup.thirdp.MySQLdb.cursors.BaseCursor
This is a Cursor class that returns rows as dictionaries and stores the result set in the client.
Bases: cup.thirdp.MySQLdb.cursors.CursorUseResultMixIn, cup.thirdp.MySQLdb.cursors.CursorTupleRowsMixIn, cup.thirdp.MySQLdb.cursors.BaseCursor
This is a Cursor class that returns rows as tuples and stores the result set in the server.
Bases: cup.thirdp.MySQLdb.cursors.CursorUseResultMixIn, cup.thirdp.MySQLdb.cursors.CursorDictRowsMixIn, cup.thirdp.MySQLdb.cursors.BaseCursor
This is a Cursor class that returns rows as dictionaries and stores the result set in the server.
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.
Format a DateTime object as an ISO timestamp.
Format a DateTimeDelta object as a time.
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.
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.