v5:dictionary:structure:introduction
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
v5:dictionary:structure:introduction [2016/04/09 19:33] – created mnewnham | v5:dictionary:structure:introduction [2021/08/26 10:11] (current) – typos peterdd | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Structured Schema Management ====== | ====== Structured Schema Management ====== | ||
- | <WRAP right box 400px> | + | ~~NOTOC~~ |
- | **From | + | <WRAP right box> |
+ | **From Version 5.21.0-beta-2** | ||
+ | == Reference == | ||
+ | [[v5: | ||
+ | [[v5: | ||
+ | [[v5: | ||
+ | [[v5: | ||
+ | [[v5: | ||
+ | [[v5: | ||
+ | [[v5: | ||
</ | </ | ||
===== Description ===== | ===== Description ===== | ||
From ADOdb Version 5.21, A new method of managing changes to the schema has been added. This method is called // | From ADOdb Version 5.21, A new method of managing changes to the schema has been added. This method is called // | ||
- | ===== Feature enhancements ===== | + | In Structured schema management, the elements that can be modified through the dictionary management routines such as [[v5: |
- | In Structured schema management, the elements that can be modified through the dictionary management routines such as [[v5: | + | |
These objects can then be easily stored through the use of technologies such as JSON, which can easily be manipulated through 3rd party tools and reprocessed. | These objects can then be easily stored through the use of technologies such as JSON, which can easily be manipulated through 3rd party tools and reprocessed. | ||
+ | |||
+ | Each table and element of a table (such as a column or index) is represented by a PHP object called a // | ||
+ | |||
+ | ===== Construction Of The Structure ===== | ||
+ | |||
+ | Every structure, no matter what the ultimate reason for its construction is, begins with construction of a table object. In this example, we are going to add a new column ' | ||
+ | |||
+ | <code php> | ||
+ | /* | ||
+ | * Assuming an established database object $db, a reference is made | ||
+ | * to the ADOdb dictionary class | ||
+ | */ | ||
+ | $dict = newDataDictionary($db); | ||
+ | |||
+ | /* | ||
+ | * Create the table object and pass the dictionary object | ||
+ | */ | ||
+ | $t = new metaObjectStructure($dict, | ||
+ | </ | ||
+ | |||
+ | The **// | ||
+ | |||
+ | ===== Processing The MetaObjectStructure ===== | ||
+ | |||
+ | The structure is not automatically sent to createTableSql, | ||
+ | |||
+ | In this example, we create a table ' | ||
+ | |||
+ | <code php> | ||
+ | $dict = newDataDictionary($db); | ||
+ | $t = new metaObjectStructure($dict, | ||
+ | /* | ||
+ | * Make sure the table is transactional in MySQL | ||
+ | */ | ||
+ | $t-> | ||
+ | |||
+ | /* | ||
+ | * Add the column | ||
+ | */ | ||
+ | $t-> | ||
+ | |||
+ | /* | ||
+ | * Now get the structure | ||
+ | */ | ||
+ | print_r($t); | ||
+ | </ | ||
+ | |||
+ | The following object is returned: | ||
+ | |||
+ | < | ||
+ | metaObjectStructure Object | ||
+ | ( | ||
+ | [type] => table | ||
+ | [value] => | ||
+ | [platform] => | ||
+ | [options] => Array | ||
+ | ( | ||
+ | ) | ||
+ | [attributes] => Array | ||
+ | ( | ||
+ | [0] => metaElementStructure Object | ||
+ | ( | ||
+ | [type] => table | ||
+ | [name] => test | ||
+ | [value] => ENGINE INNODB | ||
+ | [platform] => mysql | ||
+ | [action] => 0 | ||
+ | [attributes] => Array | ||
+ | ( | ||
+ | ) | ||
+ | ) | ||
+ | ) | ||
+ | [name] => test | ||
+ | [action] => 0 | ||
+ | [columns] => Array | ||
+ | ( | ||
+ | [COL1] => metaObjectStructure Object | ||
+ | ( | ||
+ | [type] => column | ||
+ | [value] => I | ||
+ | [platform] => | ||
+ | [options] => Array | ||
+ | ( | ||
+ | ) | ||
+ | [attributes] => Array | ||
+ | ( | ||
+ | ) | ||
+ | [name] => COL1 | ||
+ | [action] => 0 | ||
+ | ) | ||
+ | ) | ||
+ | ) | ||
+ | </ | ||
+ | |||
+ | We could JSON-encode it here and store it | ||
+ | |||
+ | <code php> | ||
+ | $j = json_encode($def) | ||
+ | /* | ||
+ | {" | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | */ | ||
+ | </ | ||
+ | ===== Processing The Structure ===== | ||
+ | A change to '' | ||
+ | |||
+ | <code php> | ||
+ | |||
+ | $sql = $dict-> | ||
+ | |||
+ | print_r($sql); | ||
+ | /* | ||
+ | * Returns: | ||
+ | Array | ||
+ | ( | ||
+ | [0] => CREATE TABLE test ( | ||
+ | COL1 I | ||
+ | )ENGINE INNODB | ||
+ | ) | ||
+ | */ | ||
+ | </ | ||
+ |
v5/dictionary/structure/introduction.1460223206.txt.gz · Last modified: 2017/04/21 11:29 (external edit)