v5:reference:connection:setcustommetatype
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
v5:reference:connection:setcustommetatype [2021/01/17 00:37] – [Data Handler] mnewnham | v5:reference:connection:setcustommetatype [2021/01/20 01:30] (current) – 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 '' |
------------------------------------------------------- | ------------------------------------------------------- | ||
- | ===== MetaType | + | ===== $metaType |
- | An existing or new type. | + | An existing or new type. The type definition should be an uppercase alpha-numeric value, e.g. **P** |
- | ===== ActualType | + | |
- | A Database specific field type, mapped to the metaType | + | ===== $actualType ===== |
- | ===== Data Handler | + | 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: | The handler can be one of these types: | ||
- | - Not set: No post processing of data prior to insertion of data. | + | - Not set: No pre-processing of data prior to insertion of data. |
- Object: An anonymous function that can be used to process 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 34: | Line 46: | ||
*/ | */ | ||
- | /* | ||
- | * First link the MySQL geometry type to a new metaType | ||
- | */ | ||
- | $ok = $db-> | ||
/* | /* | ||
- | * Now tell ADOdb how to handle the data in inserts | + | * A type ' |
- | * see the entry for setCustomMetaType for an explanation | + | * and we describe it as ' |
+ | * any changes to the input value, we do not define any processing rules | ||
*/ | */ | ||
- | $ok = $db-> | + | $ok = $db-> |
/* | /* | ||
Line 54: | Line 63: | ||
==== 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 64: | Line 73: | ||
}; | }; | ||
- | $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 86: | Line 94: | ||
COL2 C(32) NOTNULL DEFAULT ' | COL2 C(32) NOTNULL DEFAULT ' | ||
COL3 N(12.2), | COL3 N(12.2), | ||
- | | + | |
"; | "; | ||
Line 98: | Line 106: | ||
COL2 | COL2 | ||
COL3 | COL3 | ||
- | COL4 POINT, | + | COL4 JSON, |
| | ||
) | ) | ||
*/ | */ | ||
</ | </ | ||
+ | |||
+ |
v5/reference/connection/setcustommetatype.1610840265.txt.gz · Last modified: 2021/01/17 00:37 by mnewnham