NAME
DBSimple::Type - describes types of fields in tables in databases
DESCRIPTION
An DBSimple::Type
object is used to define the type of each DBSimple::Field
object. Each database implementation must register which types it knows how to handle, along with any special instructions for the handling of those types. When you call DBSimple::Table->bind
, the binding propagates down to the DBSimple::Type
for each field, at which point the special instructions for each particular field type are attached.
All references to types in the DBSimple
suite are mediated through DBSimple::Type
objects. You probably shouldn't need to use this stuff directly at all.
Everything is a method except for DBSimple::Type->register
; nothing is exported.
CONSTRUCTORS
- new ( type, [ attributes hash | attributes hashref ] )
-
Creates and returns a new
DBSimple::Type
object. Additional attributes may be specified, and are mostly ignored except by means of the special instructions a database implementation may register. Default handling, however, recognises 3 attributes called 'size', 'notnull' and 'key', where 'size' is the maximum permitted length of a char (string) field, 'notnull' is 1 if the field is not permitted to be undefined (else 0), and 'key' is 1 if the field is the primary key for the table (else 0). - scandef ( def )
-
Parses a type definition and returns a new
DBSimple::Type
object that describes it. The definition consists of the type name (typically 'char', 'int' or 'real') on its own, or followed by a ':' and additional attributes information, consisting of any or all of a sequence of digits representing the maximum size of the field, an 'N' if the field is not permitted to be set to NULL, or a 'K' if the field is the primary key for the table. If more than one attribute is specified, they must appear in the order described above.
METHODS
- clone ( )
-
Returns a blessed deep copy of itself. Used by
DBSimple::Field->clone
. - bind ( database )
-
database should be a database implementation class derived from
DBSimple::DB
. This binds the type, so that it knows how to read and write itself. Used byDBSimple::Field->bind
. - read ( text )
-
Returns the value represented when the given text comes from a field of this type. Uses the 'read' method registered for this type in this database, if defined, else returns the text unaltered.
- write ( value )
-
Returns the text required to insert the given value into a field of this type. Uses the 'write' method registered for this type in this database, if defined, else returns the value unaltered.
- fielddef ( )
-
Returns the text required to define a field of this type. Uses the 'fielddef' method registered for this type in this database, if defined, else attempts to build a default string. This string is typically used to build a SQL 'CREATE' statement, and the default will cope with simple cases using no more than the attributes it knows about.
FUNCTIONS
- register ( database, type, [ bindings hash | bindings hashref ] )
-
Registers the bindings for a particular type relevant to a particular database implementation. Each of the bindings ties a code reference to a particular name, which is assumed to be one of the overrides available: 'read', 'write' or 'fielddef'.
Each such code reference, when called, will be passed a type object as the first parameter, followed by any other parameters relevant to the call.
FUTURE
Dunno how useful this abstraction will turn out to be once we have a need for some other database implementations, but I'm fairly hopeful.
HISTORY
v0.03 Hugo 29/3/97
cleaned up some for external release
v0.02 Hugo 3/3/97
Unroll calls to _doself for efficiency
v0.01 written by Hugo before 15/11/96