cup.thirdp.MySQLdb package

Submodules

cup.thirdp.MySQLdb.connections module

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.

class cup.thirdp.MySQLdb.connections.Connection(*args, **kwargs)[source]

Bases: _mysql.connection

MySQL Database Connection Object

exception DataError

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.

exception Connection.DatabaseError

Bases: _mysql_exceptions.Error

Exception raised for errors that are related to the database.

exception Connection.Error

Bases: _mysql_exceptions.MySQLError

Exception that is the base class of all other error exceptions (not Warning).

exception Connection.IntegrityError

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.

exception Connection.InterfaceError

Bases: _mysql_exceptions.Error

Exception raised for errors that are related to the database interface rather than the database itself.

exception Connection.InternalError

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.

exception Connection.NotSupportedError

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.

exception Connection.OperationalError

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.

exception Connection.ProgrammingError

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.

exception Connection.Warning

Bases: exceptions.Warning, _mysql_exceptions.MySQLError

Exception raised for important warnings like data truncations while inserting, etc.

Connection.begin()[source]

Explicitly begin a connection. Non-standard. DEPRECATED: Will be removed in 1.3. Use an SQL BEGIN statement instead.

Connection.cursor(cursorclass=None)[source]

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.

Connection.default_cursor

alias of Cursor

Connection.errorhandler(connection, cursor, errorclass, errorvalue)

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.

Connection.literal(o)[source]

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.

Connection.set_character_set(charset)[source]

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.

Connection.set_sql_mode(sql_mode)[source]

Set the connection sql_mode. See MySQL documentation for legal values.

Connection.show_warnings()[source]

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.

cup.thirdp.MySQLdb.connections.defaulterrorhandler(connection, cursor, errorclass, errorvalue)[source]

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.

cup.thirdp.MySQLdb.connections.numeric_part(s)[source]

Returns the leading numeric part of a string.

>>> numeric_part("20-alpha")
20
>>> numeric_part("foo")
>>> numeric_part("16b")
16

cup.thirdp.MySQLdb.converters module

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().

cup.thirdp.MySQLdb.converters.Bool2Str(s, d)[source]
cup.thirdp.MySQLdb.converters.Float2Str(o, d)[source]
cup.thirdp.MySQLdb.converters.Instance2Str(o, d)[source]

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.

cup.thirdp.MySQLdb.converters.Long2Int(s, d)

Convert something into a string via str().

cup.thirdp.MySQLdb.converters.None2NULL(o, d)[source]

Convert None to NULL.

cup.thirdp.MySQLdb.converters.Set2Str(s, d)[source]
cup.thirdp.MySQLdb.converters.Str2Set(s)[source]
cup.thirdp.MySQLdb.converters.Thing2Literal(o, d)[source]

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.

cup.thirdp.MySQLdb.converters.Thing2Str(s, d)[source]

Convert something into a string via str().

cup.thirdp.MySQLdb.converters.Unicode2Str(s, d)[source]

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.

cup.thirdp.MySQLdb.converters.array2Str(o, d)[source]
cup.thirdp.MySQLdb.converters.char_array(s)[source]

cup.thirdp.MySQLdb.cursors module

MySQLdb Cursors

This module implements Cursors of various types for MySQLdb. By default, MySQLdb uses the Cursor class.

class cup.thirdp.MySQLdb.cursors.BaseCursor(connection)[source]

Bases: object

A base for Cursor classes. Useful attributes:

description
A tuple of DB API 7-tuples describing the columns in the last executed query; see PEP-249 for details.
description_flags
Tuple of column flags for last query, one entry per column in the result set. Values correspond to those in MySQLdb.constants.FLAG. See MySQL documentation (C API) for more information. Non-standard extension.
arraysize
default number of rows fetchmany() will fetch
exception DataError

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.

exception BaseCursor.DatabaseError

Bases: _mysql_exceptions.Error

Exception raised for errors that are related to the database.

exception BaseCursor.Error

Bases: _mysql_exceptions.MySQLError

Exception that is the base class of all other error exceptions (not Warning).

exception BaseCursor.IntegrityError

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.

exception BaseCursor.InterfaceError

Bases: _mysql_exceptions.Error

Exception raised for errors that are related to the database interface rather than the database itself.

exception BaseCursor.InternalError

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.

exception BaseCursor.MySQLError

Bases: exceptions.StandardError

Exception related to operation with MySQL.

exception BaseCursor.NotSupportedError

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.

exception BaseCursor.OperationalError

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.

exception BaseCursor.ProgrammingError

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.

exception BaseCursor.Warning

Bases: exceptions.Warning, _mysql_exceptions.MySQLError

Exception raised for important warnings like data truncations while inserting, etc.

BaseCursor.callproc(procname, args=())[source]

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.

BaseCursor.close()[source]

Close the cursor. No further queries will be possible.

BaseCursor.execute(query, args=None)[source]

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

BaseCursor.executemany(query, args)[source]

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().

BaseCursor.nextset()[source]

Advance to the next result set.

Returns None if there are no more result sets.

BaseCursor.setinputsizes(*args)[source]

Does nothing, required by DB API.

BaseCursor.setoutputsizes(*args)[source]

Does nothing, required by DB API.

class cup.thirdp.MySQLdb.cursors.Cursor(connection)[source]

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.

class cup.thirdp.MySQLdb.cursors.CursorDictRowsMixIn[source]

Bases: object

This is a MixIn class that causes all rows to be returned as dictionaries. This is a non-standard feature.

fetchallDict()[source]

Fetch all available rows as a list of dictionaries. Deprecated: Use fetchall() instead. Will be removed in 1.3.

fetchmanyDict(size=None)[source]

Fetch several rows as a list of dictionaries. Deprecated: Use fetchmany() instead. Will be removed in 1.3.

fetchoneDict()[source]

Fetch a single row as a dictionary. Deprecated: Use fetchone() instead. Will be removed in 1.3.

class cup.thirdp.MySQLdb.cursors.CursorOldDictRowsMixIn[source]

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.

class cup.thirdp.MySQLdb.cursors.CursorStoreResultMixIn[source]

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.

fetchall()[source]

Fetchs all available rows from the cursor.

fetchmany(size=None)[source]

Fetch up to size rows from the cursor. Result set may be smaller than size. If size is not defined, cursor.arraysize is used.

fetchone()[source]

Fetches a single row from the cursor. None indicates that no more rows are available.

scroll(value, mode='relative')[source]

Scroll the cursor in the result set to a new position according to mode.

If mode is ‘relative’ (default), value is taken as offset to the current position in the result set, if set to ‘absolute’, value states an absolute target position.

class cup.thirdp.MySQLdb.cursors.CursorTupleRowsMixIn[source]

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.

class cup.thirdp.MySQLdb.cursors.CursorUseResultMixIn[source]

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.

fetchall()[source]

Fetchs all available rows from the cursor.

fetchmany(size=None)[source]

Fetch up to size rows from the cursor. Result set may be smaller than size. If size is not defined, cursor.arraysize is used.

fetchone()[source]

Fetches a single row from the cursor.

next()[source]
class cup.thirdp.MySQLdb.cursors.DictCursor(connection)[source]

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.

class cup.thirdp.MySQLdb.cursors.SSCursor(connection)[source]

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.

class cup.thirdp.MySQLdb.cursors.SSDictCursor(connection)[source]

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.

cup.thirdp.MySQLdb.release module

cup.thirdp.MySQLdb.times module

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.

cup.thirdp.MySQLdb.times.DateFromTicks(ticks)[source]

Convert UNIX ticks into a date instance.

cup.thirdp.MySQLdb.times.DateTime2literal(d, c)[source]

Format a DateTime object as an ISO timestamp.

cup.thirdp.MySQLdb.times.DateTimeDelta2literal(d, c)[source]

Format a DateTimeDelta object as a time.

cup.thirdp.MySQLdb.times.DateTime_or_None(s)[source]
cup.thirdp.MySQLdb.times.Date_or_None(s)[source]
cup.thirdp.MySQLdb.times.TimeDelta_or_None(s)[source]
cup.thirdp.MySQLdb.times.TimeFromTicks(ticks)[source]

Convert UNIX ticks into a time instance.

cup.thirdp.MySQLdb.times.Time_or_None(s)[source]
cup.thirdp.MySQLdb.times.TimestampFromTicks(ticks)[source]

Convert UNIX ticks into a datetime instance.

cup.thirdp.MySQLdb.times.format_TIMEDELTA(v)[source]
cup.thirdp.MySQLdb.times.format_TIMESTAMP(d)[source]
cup.thirdp.MySQLdb.times.mysql_timestamp_converter(s)[source]

Convert a MySQL TIMESTAMP to a Timestamp object.

Module contents

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.

cup.thirdp.MySQLdb.Binary(x)[source]
cup.thirdp.MySQLdb.Connect(*args, **kwargs)[source]

Factory function for connections.Connection.

cup.thirdp.MySQLdb.Connection(*args, **kwargs)

Factory function for connections.Connection.

cup.thirdp.MySQLdb.Date

alias of date

cup.thirdp.MySQLdb.Time

alias of time

cup.thirdp.MySQLdb.Timestamp

alias of datetime

cup.thirdp.MySQLdb.DateFromTicks(ticks)

Convert UNIX ticks into a date instance.

cup.thirdp.MySQLdb.TimeFromTicks(ticks)

Convert UNIX ticks into a time instance.

cup.thirdp.MySQLdb.TimestampFromTicks(ticks)

Convert UNIX ticks into a datetime instance.

exception cup.thirdp.MySQLdb.DataError

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.

exception cup.thirdp.MySQLdb.DatabaseError

Bases: _mysql_exceptions.Error

Exception raised for errors that are related to the database.

exception cup.thirdp.MySQLdb.Error

Bases: _mysql_exceptions.MySQLError

Exception that is the base class of all other error exceptions (not Warning).

exception cup.thirdp.MySQLdb.IntegrityError

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.

exception cup.thirdp.MySQLdb.InterfaceError

Bases: _mysql_exceptions.Error

Exception raised for errors that are related to the database interface rather than the database itself.

exception cup.thirdp.MySQLdb.InternalError

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.

exception cup.thirdp.MySQLdb.MySQLError

Bases: exceptions.StandardError

Exception related to operation with MySQL.

exception cup.thirdp.MySQLdb.NotSupportedError

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.

class cup.thirdp.MySQLdb.DBAPISet[source]

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.

exception cup.thirdp.MySQLdb.OperationalError

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.

exception cup.thirdp.MySQLdb.ProgrammingError

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.

exception cup.thirdp.MySQLdb.Warning

Bases: exceptions.Warning, _mysql_exceptions.MySQLError

Exception raised for important warnings like data truncations while inserting, etc.

cup.thirdp.MySQLdb.connect(*args, **kwargs)

Factory function for connections.Connection.

cup.thirdp.MySQLdb.debug()

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.

cup.thirdp.MySQLdb.escape()

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.

cup.thirdp.MySQLdb.escape_dict()

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.

cup.thirdp.MySQLdb.escape_sequence()

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.

cup.thirdp.MySQLdb.escape_string()

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.

cup.thirdp.MySQLdb.get_client_info()

get_client_info() – Returns a string that represents the client library version.

cup.thirdp.MySQLdb.string_literal()

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.