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

Module MySQLdb.converters

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


Function Summary
  array2Str(o, d)
  Bool2Str(s, d)
  char_array(s)
  Float2Str(o, d)
  Instance2Str(o, d)
Convert an Instance to a string representation.
  Long2Int(s, d)
Convert something into a string via str().
  None2NULL(o, d)
Convert None to NULL.
  Set2Str(s, d)
  Str2Set(s)
  Thing2Literal(o, d)
Convert something into a SQL string literal.
  Thing2Str(s, d)
Convert something into a string via str().
  Unicode2Str(s, d)
Convert a unicode object to a string using the default encoding.

Variable Summary
dict conversions = {<type 'long'>: <function Thing2Str at 0xb...

Function Details

Instance2Str(o, d)

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.

Long2Int(s, d)

Convert something into a string via str().

None2NULL(o, d)

Convert None to NULL.

Thing2Literal(o, d)

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.

Thing2Str(s, d)

Convert something into a string via str().

Unicode2Str(s, d)

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.


Variable Details

conversions

Type:
dict
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 0xb7cf7bc4>,
 8: <type 'long'>,
...                                                                    

Generated by Epydoc 2.1 on Sat Mar 3 21:14:16 2007 http://epydoc.sf.net