v5:dictionary:structure:addattribute
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
v5:dictionary:structure:addattribute [2016/04/09 18:39] – mnewnham | v5:dictionary:structure:addattribute [2016/04/10 02:41] (current) – mnewnham | ||
---|---|---|---|
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 48: | 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.1460219943.txt.gz · Last modified: 2017/04/21 11:29 (external edit)