Package MySQLdb :: Module converters
[hide private]
[frames] | no frames]

Module converters

source code

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



Functions [hide private]
 
Str2Set(s) source code
 
Set2Str(s, d) source code
 
Thing2Str(s, d)
Convert something into a string via str().
source code
 
Unicode2Str(s, d)
Convert a unicode object to a string using the default encoding.
source code
 
Long2Int(s, d)
Convert something into a string via str().
source code
 
Float2Str(o, d) source code
 
None2NULL(o, d)
Convert None to NULL.
source code
 
Thing2Literal(o, d)
Convert something into a SQL string literal.
source code
 
Instance2Str(o, d)
Convert an Instance to a string representation.
source code
 
char_array(s) source code
 
array2Str(o, d) source code
 
Bool2Str(s, d) source code
Variables [hide private]
  conversions = {0: <class 'decimal.Decimal'>, 1: <type 'int'>, ...
Function Details [hide private]

Unicode2Str(s, d)

source code 
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.

Thing2Literal(o, d)

source code 
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.

Instance2Str(o, d)

source code 
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.

Variables Details [hide private]

conversions

Value:
{0: <class 'decimal.Decimal'>,
 1: <type 'int'>,
 2: <type 'int'>,
 3: <type 'long'>,
 4: <type 'float'>,
 5: <type 'float'>,
 7: <function mysql_timestamp_converter at 0xb79b5614>,
 8: <type 'long'>,
...