dictionary:metacasing
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
dictionary:metacasing [2015/11/13 00:51] – [Overview] mnewnham | dictionary:metacasing [2015/12/19 17:21] (current) – removed mnewnham | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== MetaCasing ====== | ||
- | |||
- | ===== Description ===== | ||
- | |||
- | As of ADOdb version 6.0, **MetaCasing** provides a complete, separate method of controlling key/value casing alternative to the effects of [[reference: | ||
- | |||
- | * Consistent casing of keys in '' | ||
- | * Can be changed dynamically inside programs | ||
- | * Is consistently supported by all database drivers. | ||
- | * Improves performance when schema information is read multiple time, or used in the course of an update. For instance, when [[reference: | ||
- | * Separates the ' | ||
- | |||
- | <WRAP info> | ||
- | MetaCasing variables have no effect on the keys of retrieved recordsets. These are still controlled by [[reference: | ||
- | </ | ||
- | |||
- | ===== Overview ===== | ||
- | |||
- | Historically, | ||
- | * ADODB_ASSOC_CASE | ||
- | * ADODB_FORCE_QUOTES | ||
- | * The $nameQuote option on autoExecute() | ||
- | |||
- | The end result has been that schema information must be sometimes re-read multiple times in order to obtain the necessary consistent presentation layer values, whilst configuring the tables and columns differently for table updates. | ||
- | |||
- | MetaCasing attempts to eliminate most of the confusing conflicts, as well as providing performance enhancements by storing and re-using database schema information instead of reading the database multiple times. | ||
- | |||
- | ==== The MetaCache ==== | ||
- | |||
- | Each time an element of the schema - such as tables, columns and indexes - is read, the retrieved data is stored in the metaCache, so that any subsequent requests for that information, | ||
- | |||
- | The data in the metaCache is stored in ' | ||
- | |||
- | ===== Basic Usage ===== | ||
- | |||
- | Both metaCasing and MetaCaching is enabled by default in ADOdb versions 6.0 and higher. The configurations of either can be modified at any time after creation of the ADOdb class. Configuration is not predicated on having established a connection to the database **[what do you mean ?]**. In addition, configuration can be changed multiple times within a single procedure. | ||
- | * To disable metaCasing, call the method '' | ||
- | * To disable metaCaching, | ||
- | |||
- | ==== Configuring metaCasing === | ||
- | |||
- | MetaCasing is controlled by a single method [[dictionary: | ||
- | |||
- | ^ Constant | ||
- | | METACASE_LOWER | ||
- | | METACASE_UPPER | ||
- | | METACASE_NATIVE | ||
- | | METACASE_LEGACY | ||
- | |||
- | ==== Usage ==== | ||
- | <code php> | ||
- | $db-> | ||
- | print_r($db-> | ||
- | /* | ||
- | * Prints | ||
- | array( | ||
- | 0=> | ||
- | 1=> | ||
- | 2=ACTKWD | ||
- | ) | ||
- | */ | ||
- | $db-> | ||
- | print_r($db-> | ||
- | /* | ||
- | * Prints | ||
- | array( | ||
- | 0=> | ||
- | 1=> | ||
- | 2=actkwd | ||
- | ) | ||
- | */ | ||
- | </ | ||
- | |||
- | Note in the above example, the table name requested was provided in upper case, but the resulting column names were in lower case. One of the benefits of the metaCase system is that it is no longer necessary to know the correct casing of table or column names, they will be automatically converted to the correct values. | ||
- | |||
- | |||
- | ===== Available Public Methods ===== | ||
- | |||
- | ----------------------------- | ||
- | ==== setMetaCasing ==== | ||
- | <WRAP right box 350px> | ||
- | == Syntax == | ||
- | void setMetacasing( | ||
- | int $casing | ||
- | ) | ||
- | </ | ||
- | The method '' | ||
- | |||
- | ----------------------- | ||
- | ==== getMetaCasing ==== | ||
- | <WRAP right box 350px> | ||
- | == Syntax == | ||
- | int getMetacasing() | ||
- | </ | ||
- | The method '' | ||
- | |||
- | ------------------------ | ||
- | ==== clearMetaCache ==== | ||
- | <WRAP right box 350px> | ||
- | == Syntax == | ||
- | void clearMetaCache( | ||
- | optional string $tableName=false | ||
- | ) | ||
- | </ | ||
- | The method '' | ||
- | |||
- | ------------------------ | ||
- | ==== disableMetaCache ==== | ||
- | <WRAP right box 350px> | ||
- | == Syntax == | ||
- | void disableMetaCache() | ||
- | </ | ||
- | The method '' | ||
- | |||
- | ---------------------------- | ||
- | ==== enableMetaCache ==== | ||
- | <WRAP right box 350px> | ||
- | == Syntax == | ||
- | void enableMetaCache() | ||
- | </ | ||
- | The method '' | ||
- | |||
- | ---------------------------- | ||
- | |||
- | ==== buildMetaCache ==== | ||
- | <WRAP right box 350px> | ||
- | == Syntax == | ||
- | void buildMetaCache() | ||
- | </ | ||
- | The method '' | ||
- | | ||
- | ----------------------------------- | ||
- | |||
- | ===== How metaCasing affects specific functions ===== | ||
- | Metacasing rules are applied to all [[dictionary: | ||
- | |||
- | ==== autoExecute() ==== | ||
- | All of the above casing rules apply as above, plus another important change: If the metaCasing is set to METACASE_NATIVE, | ||
- | |||
- | ==== getInsertSql and getUpdateSql ==== | ||
- | Metacasing will now produce a more formal SQL statement in preparation for insertion of a record. | ||
- | * All tables and column names will be quoted, irrespective of their containing special characters | ||
- | * Table and column names will be correctly cased, based on how they are held in the database | ||
- | === Example === | ||
- | <code php> | ||
- | /* | ||
- | * Connection assumed | ||
- | */ | ||
- | |||
- | /* | ||
- | * Use legacy metacasing | ||
- | */ | ||
- | $db-> | ||
- | $table = ' | ||
- | $fields = array(' | ||
- | ' | ||
- | ' | ||
- | $sql = getInsertSql($table, | ||
- | |||
- | print_r($sql); | ||
- | /* | ||
- | * Keys are always upper cased | ||
- | * Prints INSERT INTO ACT (`ACT-NO`, | ||
- | */ | ||
- | |||
- | /* | ||
- | * Set metacasing to native | ||
- | */ | ||
- | $db-> | ||
- | $sql = getInsertSql($table, | ||
- | |||
- | print_r($sql); | ||
- | /* | ||
- | * Keys are used based on how they are held in the database | ||
- | * Prints INSERT INTO `act` (`act-no`, | ||
- | */ | ||
- | </ | ||
- | |||
- | ===== Schema Management Functions ===== | ||
- | Any meta function to manages tables, columns or indexes now has the object name in question managed by metaCasing. The same rules that are applied to getInsertSql() and getUpdateSql() are applied to these items. | ||
- | |||
- | |||
- | |||
- | |||
dictionary/metacasing.1447372293.txt.gz · Last modified: 2017/04/21 11:19 (external edit)