This is an old revision of the document!
setCustomMetaType
From Version 5.22
See Also
Syntax
bool setCustomMetaType( string $metaType, string $actualType, mixed $handler )
Description
The function setCustomMetaType()
takes an input string that represents a database-specific data type, and creates an ADOdb metaType associated with it. If the physical type is already bound to an existing metaType, the new setting overrides the old. For full functionality, a corresponding setCustomActualType() command should be issued.
Data Handler
The handler can be of three types:
- Not set: No post processing of data prior to insertion of data
- String: Post processing of data based on metaType passed. The string value must be that of a valid metaType
- Object: An anonymous function that can be used to process data
Examples
Using A Passthrough Handler
In this example, the system can be expanded to accept geometry type data types by creating a new data type
/* * $db = MySQL connection assumed */ /* * First link the MySQL geometry type to a new metaType */ $ok = $db->setCustomActualType(255,'P'); /* * Now tell ADOdb how to handle the data in inserts and updates * see the entry for setCustomMetaType for an explanation */ $ok = $db->setCustomMetaType('P','POINT'); /* * Insert a record with a point column */ $ar = array(); $ar['geo_column'] = 'POINT(1,2)';
Using a closure
In this example all character fields are converted to lowercase by the anonymous function
/* * $db = MySQL connection assumed */ $callback = function($val) { return strtolower($val); }; $ok = $db->setCustomMetaType('C','CHAR',$callback);
Using The Custom Type In DataDict Functions
In this example, we use a custom definition to create a POINT column in a table under MySQL
/* * We must define the custom type before loading the data dictionary */ $ok = $db->setCustomActualType(255,'P'); $ok = $db->setCustomMetaType('P','POINT'); /* * Then create a data dictionary object, using this connection */ $dict = NewDataDictionary($db); $tabname = "mt_test"; $flds = " COL1 I NOTNULL AUTO PRIMARY, COL2 C(32) NOTNULL DEFAULT 'abc', COL3 N(12.2), COL4 P "; $sqlarray = $dict->createTableSQL($tabname, $flds); print_r($sqlarray); /* * Returns CREATE TABLE mt_test ( COL1 INTEGER NOT NULL AUTO_INCREMENT, COL2 VARCHAR(32) NOT NULL DEFAULT 'abc', COL3 NUMERIC(12,2), COL4 POINT, PRIMARY KEY (COL1) ) */