
Gets schema information for the selected database
1.0.0b51 | Fixed handling of getting tables in table creation order when a table references itself, fixed default value detection for the last column in a MySQL table 1/12/12 |
---|---|
1.0.0b50 | Fixed detection of explicitly named SQLite foreign key constraints 8/23/11 |
1.0.0b49 | Added support for spatial/geometric data types in MySQL and PostgreSQL 5/26/11 |
1.0.0b48 | Fixed a bug with getTables() not working on MySQL 4.x, fixed getKeys() to always return a reset array 5/24/11 |
1.0.0b47 | Backwards Compatibility Break - getTables(), getColumnInfo(), getDatabases(), getKeys() and getRelationships() now return database, schema, table and column names in lowercase, added the $creation_order parameter to getTables(), fixed bugs with getting column and key information from MSSQL, Oracle and SQLite 5/9/11 |
1.0.0b46 | Enhanced SQLite schema detection to cover situations where UNIQUE constraints are defined separately from the table and when comments are used in CREATE TABLE statements 2/6/11 |
1.0.0b45 | Fixed Oracle auto incrementing detection to work with INSERT OR UPDATE triggers, fixed detection of dynamic default date/time/timestamp values for DB2 and Oracle 12/4/10 |
1.0.0b44 | Fixed the list of valid elements for getColumnInfo() 11/28/10 |
1.0.0b43 | Added the comment element to the information returned by getColumnInfo() 11/28/10 |
1.0.0b42 | Fixed a bug with MySQL detecting default ON DELETE clauses 10/19/10 |
1.0.0b41 | Fixed handling MySQL table names that require quoting 8/24/10 |
1.0.0b40 | Fixed bugs in the documentation and error message of getColumnInfo() about what are valid elements 7/21/10 |
1.0.0b39 | Fixed a regression where key detection SQL was not compatible with PostgreSQL 8.1 4/13/10 |
1.0.0b38 | Added Oracle support to getDatabases() 4/13/10 |
1.0.0b37 | Fixed getDatabases() for MSSQL 4/9/10 |
1.0.0b36 | Fixed PostgreSQL to properly report explicit NULL default values via getColumnInfo() 3/30/10 |
1.0.0b35 | Added max_length values for various text and blob data types across all databases 3/29/10 |
1.0.0b34 | Added min_value and max_value attributes to getColumnInfo() to specify the valid range for numeric columns 3/16/10 |
1.0.0b33 | Changed it so that PostgreSQL unique indexes containing functions are ignored since they can't be properly detected at this point 3/14/10 |
1.0.0b32 | Fixed getTables() to not include views for MySQL 3/14/10 |
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 |
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
callback __get( string $method )
string | $method | The method to create a callback for |
The callback for the method requested
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
void clearCache( )
Sets the schema to be cached to the fCache object specified
void enableCaching( fCache $cache, string $key_token=NULL )
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},
'min_value' => (numeric) {the minimum value for an integer/float field},
'max_value' => (numeric) {the maximum value for an integer/float 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},
'comment' => (string) {the SQL comment/description for the 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},
'min_value' => (fNumber) {the minimum value for an integer/float field},
'max_value' => (fNumber) {the maximum value for an integer/float 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},
'comment' => (string) {the SQL comment/description for the 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:
Please note that MySQL reports boolean data types as tinyint(1), so all tinyint(1) columns will be listed as boolean. This can be fixed by calling:
$schema->setColumnInfoOverride(
array(
'type' => 'integer',
'placeholder' => '%i',
'default' => {default integer},
'min_value' => new fNumber(-128),
'max_value' => new fNumber(127)
),
'{table name}',
'{column name}'
);
The 'comment' element pulls from the database's column comment facility with the exception of MSSQL and SQLite.
For MSSQL, the comment is pulled from the MS_Description extended property, which can be added via the Description field in SQL Server Management Studio, or via the sp_addextendedproperty stored procedure.
For SQLite, the comment is extracted from any SQL comment that is placed at the end of the line on which the column is defined:
CREATE TABLE users (
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(200) NOT NULL -- This is the full name
);
For the SQLite users table defined above, the name column will have the comment This is the full name.
mixed getColumnInfo( string $table, string $column=NULL, string $element=NULL )
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', 'min_value', 'max_value', 'decimal_places', 'auto_increment', 'comment' |
The column info for the table/column/element specified - see method description for format
Returns the databases on the current server
array getDatabases( )
The databases on the current server
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'}
), ...
)
)
array getKeys( string $table, string $key_type=NULL )
string | $table | The table to return the keys for |
string | $key_type | The type of key to return: 'primary', 'foreign', 'unique' |
An array of all keys, or just the type specified - see method description for format
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'}
), ...
)
)
array getRelationships( string $table, string $relationship_type=NULL )
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' |
An array of all relationships, or just the type specified - see method description for format
Returns the tables in the current database
array getTables( boolean|string $creation_order=NULL )
boolean|string | $creation_order | TRUE to return in a valid table creation order, or a table name to return that table and any tables that depend on it, in table creation order |
The tables in the current database, all converted to lowercase
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.
The following keys may be set to NULL:
The key 'auto_increment' should be a boolean.
The 'type' key should be one of:
void setColumnInfoOverride( array $column_info, string $table, string $column=NULL )
array | $column_info | The modified column info - see method description for format |
string | $table | The table to override |
string | $column | The column to override |
Allows overriding of key info. Replaces existing info, so be sure to provide full key info for type selected or all types.
void setKeysOverride( array $keys, string $table, string $key_type=NULL )
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' |