v5:reference:connection:setcustommetatype
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
v5:reference:connection:setcustommetatype [2021/01/06 02:37] – mnewnham | v5:reference:connection:setcustommetatype [2021/01/18 04:01] – mnewnham | ||
---|---|---|---|
Line 4: | Line 4: | ||
**From Version 5.22**\\ | **From Version 5.22**\\ | ||
==See Also== | ==See Also== | ||
- | [[v5: | + | [[v5: |
== Syntax == | == Syntax == | ||
bool setCustomMetaType( | bool setCustomMetaType( | ||
| | ||
| | ||
- | mixed $handler | + | string $dictionayType, |
+ | mixed $handleAsType=false, | ||
+ | mixed $callBack=false | ||
) | ) | ||
</ | </ | ||
===== Description ===== | ===== Description ===== | ||
- | The function '' | + | The function '' |
------------------------------------------------------- | ------------------------------------------------------- | ||
- | ===== Data Handler | + | ===== $metaType |
- | The handler can be of three types: | + | An existing or new type. The type definition should |
- | | + | |
- | - 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 | + | |
+ | ===== $actualType ===== | ||
+ | The physical data type as provided by the database, for example the POINT data type in the mySQL returns 255. | ||
+ | |||
+ | ===== $dictionaryType ===== | ||
+ | A Database specific field type, mapped to the metaType, e.g. **POINT**. This tells ADOdb how to handle the database will handle the record. | ||
+ | |||
+ | ===== $handleAsType ==== | ||
+ | One of the standard [[v5: | ||
+ | |||
+ | =====$callback ===== | ||
+ | |||
+ | The handler can be one of these types: | ||
+ | - Not set: No pre-processing of data prior to insertion of data. | ||
+ | - Object: An anonymous function that can be used to process data. | ||
+ | |||
+ | The callback function can be used to apply any changes to the data **prior** to the processing as type. | ||
===== Examples ===== | ===== Examples ===== | ||
==== Using A Passthrough Handler | ==== Using A Passthrough Handler | ||
Line 31: | Line 46: | ||
*/ | */ | ||
- | /* | ||
- | * First link the MySQL geometry type to a new metaType | ||
- | */ | ||
- | $ok = $db-> | ||
/* | /* | ||
- | * Now tell ADOdb how to handle the data in inserts and updates | + | * A type ' |
- | * see the entry for setCustomMetaType for an explanation | + | |
*/ | */ | ||
- | $ok = $db-> | + | $ok = $db-> |
/* | /* | ||
Line 51: | Line 61: | ||
==== Using a closure ==== | ==== Using a closure ==== | ||
- | In this example all character fields are converted to lowercase by the anonymous function | + | In this example all character fields are converted to lowercase by the anonymous function, and are then processed normally as character |
<code php> | <code php> | ||
Line 61: | Line 71: | ||
}; | }; | ||
- | $ok = $db-> | + | $ok = $db-> |
</ | </ | ||
===== Using The Custom Type In DataDict Functions ====== | ===== 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 | + | In this example, we use a custom definition to create a JSON column in a table under MySQL |
<code php> | <code php> | ||
/* | /* | ||
* We must define the custom type before loading the data dictionary | * We must define the custom type before loading the data dictionary | ||
*/ | */ | ||
- | $ok = $db-> | + | $ok = $db-> |
- | $ok = $db-> | + | |
/* | /* | ||
Line 77: | Line 86: | ||
*/ | */ | ||
$dict = NewDataDictionary($db); | $dict = NewDataDictionary($db); | ||
- | |||
$tabname = " | $tabname = " | ||
Line 84: | Line 92: | ||
COL2 C(32) NOTNULL DEFAULT ' | COL2 C(32) NOTNULL DEFAULT ' | ||
COL3 N(12.2), | COL3 N(12.2), | ||
- | | + | |
"; | "; | ||
Line 96: | Line 104: | ||
COL2 | COL2 | ||
COL3 | COL3 | ||
- | COL4 POINT, | + | COL4 JSON, |
| | ||
) | ) | ||
*/ | */ | ||
- | </ | + | </ |
+ |
v5/reference/connection/setcustommetatype.txt · Last modified: 2021/01/20 01:30 by mnewnham