Field Information

Each database cursor has a Field object accessable from the fields attribute.

Below is an example Field object

self.fields = base.Fields(
        'Char':     base.CharConverter       ("CHAR(1)",        (254,)),
        'String':   base.StringConverter     ("VARCHAR(255)",   (253,)),
        'Text':     base.TextConverter       ("MEDIUMBLOB",     (252,)),
        'Integer':  base.IntegerConverter    ("INT(11)",        (3,5,)),
        'Float':    base.FloatConverter      ("FLOAT",          (4,)),
        'Date':     base.DateConverter       ("DATE",           (10,)),
        'Time':     base.TimeConverter       ("TIME",           (11,)),
        'DateTime': base.DateTimeConverter   ("DATETIME",       (12,)),

The Field object is made up of an SQLFieldConverter object for each field type the cursor supports. These SQLFieldConverter objects take two parameters, createSQL is a string containing the SQL needed to create the field and codes is a tuple containing all the FieldCodes that can be used to for that particular field. (For example you may be able to store a web.database.object Char field in a MySQL CHAR(1) or VARCHAR(255) field so both these fields may be available to use for the Char object.)

The SQLFieldConverter objects may at a future date also contain information about the minimum or maximum values a field can take. This would be specified using the params parameter.

Each SQLFieldConverter object has two methods, object(field) and sql(object). object(field) takes an SQL string representation of the field as returned by the underlying cursor and converts it into a Python object. sql(object) takes a Python object and encodes it into an SQL string.

To add support for a new field type all you need to do is create a SQLFieldConverter object for that field and then add the field to each Cursor's Field object.

See About this document... for information on suggesting changes.