v5:dictionary:structure:addattribute
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| v5:dictionary:structure:addattribute [2016/04/07 02:01] – created mnewnham | v5:dictionary:structure:addattribute [2016/04/10 02:41] (current) – mnewnham | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| ~~NOTOC~~ | ~~NOTOC~~ | ||
| <WRAP right box> | <WRAP right box> | ||
| - | **From Version 5.21.0** | + | **From Version 5.21.0-beta-2** |
| == See Also == | == See Also == | ||
| [[v5: | [[v5: | ||
| Line 13: | Line 13: | ||
| ) | ) | ||
| </ | </ | ||
| - | The method '' | + | The method '' |
| An attribute can be added to any of the available structure types, table, | An attribute can be added to any of the available structure types, table, | ||
| Line 25: | Line 25: | ||
| The priority parameter can optionally force the system to process the attributes in a specific order. If not provided, the attributes are processed in the order provided. | The priority parameter can optionally force the system to process the attributes in a specific order. If not provided, the attributes are processed in the order provided. | ||
| + | ===== Usage ===== | ||
| + | In the following example, a table **// | ||
| + | - Under **MySQL**, an engine type needs to be specified. | ||
| + | - Under **IBM DB2**, | ||
| <code php> | <code php> | ||
| Line 44: | Line 48: | ||
| -> | -> | ||
| </ | </ | ||
| - | <WRAP clear /> | + | ===== Understanding Attributes ===== |
| + | ==== Portable Attributes ==== | ||
| + | Portable attributes are comparable to the options available to the original [[v5: | ||
| + | |||
| + | * If a feature is **portable**, | ||
| + | * Portable options may have a **// | ||
| + | |||
| + | ==== Non-Portable (Custom) Attributes ==== | ||
| + | A custom attribute is one that must be defined fully in order to be handled correctly by the DBMS. In principle, any option not all ready defined as portable in the [[v5: | ||
| + | |||
| + | In the following example, we create a column, and add 3 attributes to it. 1 attribute is portable and 2 are custom. | ||
| + | |||
| + | <code php> | ||
| + | /* | ||
| + | * We define a metaObjectStructure, | ||
| + | * the table ' | ||
| + | */ | ||
| + | |||
| + | $dict = NewDataDictionary($db); | ||
| + | $t = new metaObjectStructure($dict,' | ||
| + | |||
| + | /* | ||
| + | * We now add an object representing the column, ' | ||
| + | */ | ||
| + | $c = $t-> | ||
| + | |||
| + | /* | ||
| + | * now add a portable attribute DEFAULT | ||
| + | * This could also be passed as a string " | ||
| + | */ | ||
| + | $c-> | ||
| + | |||
| + | /* | ||
| + | * now add a custom attribute to column, applicable to all platforms | ||
| + | */ | ||
| + | $c-> | ||
| + | |||
| + | /* | ||
| + | * Now add another attribute, which is only used if the database type is SQL Server | ||
| + | */ | ||
| + | $c-> | ||
| + | |||
| + | |||
| + | /* | ||
| + | * This object is now passed to the addColumnSql method | ||
| + | */ | ||
| + | $sql = $dict-> | ||
| + | </code> | ||
| + | |||
| + | If ADOdb was attached to a MySQL database, the sql returned would be: | ||
| + | |||
| + | ALTER TABLE employees ADD somecolumn VARCHAR(32) | ||
| + | | ||
| + | | ||
| + | |||
| + | but if attached to a SQL Server database, it would appear as: | ||
| + | |||
| + | ALTER TABLE employees ADD somecolumn VARCHAR(32) | ||
| + | DEFAULT "SOME VALUE" | ||
| + | CHARACTER SET " | ||
| + | | ||
v5/dictionary/structure/addattribute.1459987291.txt.gz · Last modified: (external edit)
