fSchemaclassv1.0.0b31
Gets schema information for the selected database
| 1.0.0b31 | Fixed the creation of the default caching key for enableCaching() 3/2/10 |
|---|---|
| 1.0.0b30 | Fixed the class to work with lower privilege Oracle accounts and added detection of Oracle number columns 1/25/10 |
| 1.0.0b29 | Added on_delete and on_update elements to one-to-one relationship info retrieved by getRelationships() 12/16/09 |
| 1.0.0b28 | Fixed a bug with detecting some multi-column unique constraints in SQL Server databases 11/13/09 |
| 1.0.0b27 | Added a parameter to enableCaching() to provide a key token that will allow cached values to be shared between multiple databases with the same schema 10/28/09 |
| 1.0.0b26 | Added the placeholder element to the output of getColumnInfo(), added support for PostgreSQL, MSSQL and Oracle "schemas", added support for parsing quoted SQLite identifiers 10/22/09 |
| 1.0.0b25 | One-to-one relationships utilizing the primary key as a foreign key are now properly detected 9/22/09 |
| 1.0.0b24 | Fixed MSSQL support to work with ODBC database connections 9/18/09 |
| 1.0.0b23 | Fixed a bug where one-to-one relationships were being listed as many-to-one 7/21/09 |
| 1.0.0b22 | PostgreSQL UNIQUE constraints that are created as indexes and not table constraints are now properly detected 7/8/09 |
| 1.0.0b21 | Added support for the UUID data type in PostgreSQL 6/18/09 |
| 1.0.0b20 | Add caching of merged info, improved performance of getColumnInfo() 6/15/09 |
| 1.0.0b19 | Fixed a couple of bugs with setKeysOverride() 6/4/09 |
| 1.0.0b18 | Added missing support for MySQL mediumint columns 5/18/09 |
| 1.0.0b17 | Fixed a bug with clearCache() not properly reseting the tables and databases list 5/13/09 |
| 1.0.0b16 | Backwards Compatibility Break - setCacheFile() changed to enableCaching() and now requires an fCache object, flushInfo() renamed to clearCache(), added Oracle support 5/4/09 |
| 1.0.0b15 | Added support for the three different types of identifier quoting in SQLite 3/28/09 |
| 1.0.0b14 | Added support for MySQL column definitions containing the COLLATE keyword 3/28/09 |
| 1.0.0b13 | Fixed a bug with detecting PostgreSQL columns having both a CHECK constraint and a UNIQUE constraint 2/27/09 |
| 1.0.0b12 | Fixed detection of multi-column primary keys in MySQL 2/27/09 |
| 1.0.0b11 | Fixed an issue parsing MySQL tables with comments 2/25/09 |
| 1.0.0b10 | Added the getDatabases() method 2/24/09 |
| 1.0.0b9 | Now detects unsigned and zerofill MySQL data types that do not have a parenthetical part 2/16/09 |
| 1.0.0b8 | Mapped the MySQL data type 'set' to 'varchar', however valid values are not implemented yet 2/1/09 |
| 1.0.0b7 | Fixed a bug with detecting MySQL timestamp columns 1/28/09 |
| 1.0.0b6 | Fixed a bug with detecting MySQL columns that accept NULL 1/19/09 |
| 1.0.0b5 | setColumnInfo(): fixed a bug with not grabbing the real database schema first, made general improvements 1/19/09 |
| 1.0.0b4 | Added support for MySQL binary data types, numeric data type options unsigned and zerofill, and per-column character set definitions 1/17/09 |
| 1.0.0b3 | Fixed detection of the data type of MySQL timestamp columns, added support for dynamic default date/time values 1/11/09 |
| 1.0.0b2 | Fixed a bug with detecting multi-column unique keys in MySQL 1/3/09 |
| 1.0.0b | The initial implementation 9/25/07 |
Methods
->__construct() public
->__get() internal public
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
All requests that hit this method should be requests for callbacks
Signature
callback __get( string $method )
Parameters
| string | $method | The method to create a callback for |
Returns
The callback for the method requested
->clearCache() internal public
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Clears all of the schema info out of the object and, if set, the fCache object
Signature
void clearCache( )
->enableCaching() public
Sets the schema to be cached to the fCache object specified
Signature
void enableCaching( fCache $cache, string $key_token=NULL )
Parameters
->getColumnInfo() public
Returns column information for the table specified
If only a table is specified, column info is in the following format:
array(
(string) {column name} => array(
'type' => (string) {data type},
'placeholder' => (string) {fDatabase::escape() placeholder for this data type},
'not_null' => (boolean) {if value can't be null},
'default' => (mixed) {the default value},
'valid_values' => (array) {the valid values for a varchar field},
'max_length' => (integer) {the maximum length in a varchar field},
'decimal_places' => (integer) {the number of decimal places for a decimal/numeric/money/smallmoney field},
'auto_increment' => (boolean) {if the integer primary key column is a serial/autoincrement/auto_increment/indentity column}
), ...
)If a table and column are specified, column info is in the following format:
array(
'type' => (string) {data type},
'placeholder' => (string) {fDatabase::escape() placeholder for this data type},
'not_null' => (boolean) {if value can't be null},
'default' => (mixed) {the default value-may contain special strings CURRENT_TIMESTAMP, CURRENT_TIME or CURRENT_DATE},
'valid_values' => (array) {the valid values for a varchar field},
'max_length' => (integer) {the maximum length in a char/varchar field},
'decimal_places' => (integer) {the number of decimal places for a decimal/numeric/money/smallmoney field},
'auto_increment' => (boolean) {if the integer primary key column is a serial/autoincrement/auto_increment/indentity column}
)If a table, column and element are specified, returned value is the single element specified.
The 'type' element is homogenized to a value from the following list:
- 'varchar'
- 'char'
- 'text'
- 'integer'
- 'float'
- 'timestamp'
- 'date'
- 'time'
- 'boolean'
- 'blob'
Signature
mixed getColumnInfo( string $table, string $column=NULL, string $element=NULL )
Parameters
| string | $table | The table to get the column info for |
| string | $column | The column to get the info for |
| string | $element | The element to return: 'type', 'placeholder', 'not_null', 'default', 'valid_values', 'max_length', 'decimal_places', 'auto_increment' |
Returns
The column info for the table/column/element specified - see method description for format
->getDatabases() public
Returns the databases on the current server
Signature
array getDatabases( )
Returns
The databases on the current server
->getKeys() public
Returns a list of primary key, foreign key and unique key constraints for the table specified
The structure of the returned array is:
array(
'primary' => array(
{column name}, ...
),
'unique' => array(
array(
{column name}, ...
), ...
),
'foreign' => array(
array(
'column' => {column name},
'foreign_table' => {foreign table name},
'foreign_column' => {foreign column name},
'on_delete' => {the ON DELETE action: 'no_action', 'restrict', 'cascade', 'set_null', or 'set_default'},
'on_update' => {the ON UPDATE action: 'no_action', 'restrict', 'cascade', 'set_null', or 'set_default'}
), ...
)
)Signature
array getKeys( string $table, string $key_type=NULL )
Parameters
| string | $table | The table to return the keys for |
| string | $key_type | The type of key to return: 'primary', 'foreign', 'unique' |
Returns
An array of all keys, or just the type specified - see method description for format
->getRelationships() public
Returns a list of one-to-one, many-to-one, one-to-many and many-to-many relationships for the table specified
The structure of the returned array is:
array(
'one-to-one' => array(
array(
'table' => (string) {the name of the table this relationship is for},
'column' => (string) {the column in the specified table},
'related_table' => (string) {the related table},
'related_column' => (string) {the related column},
'on_delete' => (string) {the ON DELETE action: 'no_action', 'restrict', 'cascade', 'set_null', or 'set_default'},
'on_update' => (string) {the ON UPDATE action: 'no_action', 'restrict', 'cascade', 'set_null', or 'set_default'}
), ...
),
'many-to-one' => array(
array(
'table' => (string) {the name of the table this relationship is for},
'column' => (string) {the column in the specified table},
'related_table' => (string) {the related table},
'related_column' => (string) {the related column}
), ...
),
'one-to-many' => array(
array(
'table' => (string) {the name of the table this relationship is for},
'column' => (string) {the column in the specified table},
'related_table' => (string) {the related table},
'related_column' => (string) {the related column},
'on_delete' => (string) {the ON DELETE action: 'no_action', 'restrict', 'cascade', 'set_null', or 'set_default'},
'on_update' => (string) {the ON UPDATE action: 'no_action', 'restrict', 'cascade', 'set_null', or 'set_default'}
), ...
),
'many-to-many' => array(
array(
'table' => (string) {the name of the table this relationship is for},
'column' => (string) {the column in the specified table},
'related_table' => (string) {the related table},
'related_column' => (string) {the related column},
'join_table' => (string) {the table that joins the specified table to the related table},
'join_column' => (string) {the column in the join table that references 'column'},
'join_related_column' => (string) {the column in the join table that references 'related_column'},
'on_delete' => (string) {the ON DELETE action: 'no_action', 'restrict', 'cascade', 'set_null', or 'set_default'},
'on_update' => (string) {the ON UPDATE action: 'no_action', 'restrict', 'cascade', 'set_null', or 'set_default'}
), ...
)
)Signature
array getRelationships( string $table, string $relationship_type=NULL )
Parameters
| string | $table | The table to return the relationships for |
| string | $relationship_type | The type of relationship to return: 'one-to-one', 'many-to-one', 'one-to-many', 'many-to-many' |
Returns
An array of all relationships, or just the type specified - see method description for format
->getTables() public
Returns the tables in the current database
Signature
array getTables( )
Returns
The tables in the current database
->setColumnInfoOverride() public
Allows overriding of column info
Performs an array merge with the column info detected from the database.
To erase a whole table, set the $column_info to NULL. To erase a column, set the $column_info for that column to NULL.
If the $column_info parameter is not NULL, it should be an associative array containing one or more of the following keys. Please see getColumnInfo() for a description of each.
- 'type'
- 'placeholder'
- 'not_null'
- 'default'
- 'valid_values'
- 'max_length'
- 'decimal_places'
- 'auto_increment'
The following keys may be set to NULL:
- 'not_null'
- 'default'
- 'valid_values'
- 'max_length'
- 'decimal_places'
The key 'auto_increment' should be a boolean.
The 'type' key should be one of:
- 'blob'
- 'boolean'
- 'char'
- 'date'
- 'float'
- 'integer'
- 'text'
- 'time'
- 'timestamp'
- 'varchar'
Signature
void setColumnInfoOverride( array $column_info, string $table, string $column=NULL )
Parameters
| array | $column_info | The modified column info - see method description for format |
| string | $table | The table to override |
| string | $column | The column to override |
->setKeysOverride() public
Allows overriding of key info. Replaces existing info, so be sure to provide full key info for type selected or all types.
Signature
void setKeysOverride( array $keys, string $table, string $key_type=NULL )
Parameters
| array | $keys | The modified keys - see getKeys() for format |
| string | $table | The table to override |
| string | $key_type | The key type to override: 'primary', 'foreign', 'unique' |
