diff options
| author | Damien Regad <dregad@mantisbt.org> | 2021-10-25 18:16:12 +0200 |
|---|---|---|
| committer | Damien Regad <dregad@mantisbt.org> | 2021-10-25 18:16:12 +0200 |
| commit | a1433fedb37baaa1487ba0a7e533c8cc8d99bb14 (patch) | |
| tree | 69b17af3c2c7d04207a1ec6d2edd9438e1f6817c /adodb-xmlschema.inc.php | |
| parent | 197cef7e17f093aca53dd681758770bc7b2d1542 (diff) | |
| download | adodb-a1433fedb37baaa1487ba0a7e533c8cc8d99bb14.tar.gz adodb-a1433fedb37baaa1487ba0a7e533c8cc8d99bb14.tar.bz2 adodb-a1433fedb37baaa1487ba0a7e533c8cc8d99bb14.zip | |
Fix PHPDoc blocks
Diffstat (limited to 'adodb-xmlschema.inc.php')
| -rw-r--r-- | adodb-xmlschema.inc.php | 1277 |
1 files changed, 641 insertions, 636 deletions
diff --git a/adodb-xmlschema.inc.php b/adodb-xmlschema.inc.php index 7c4901df..7b0916ab 100644 --- a/adodb-xmlschema.inc.php +++ b/adodb-xmlschema.inc.php @@ -27,118 +27,118 @@ */ /** -* Debug on or off -*/ + * Debug on or off + */ if( !defined( 'XMLS_DEBUG' ) ) { define( 'XMLS_DEBUG', FALSE ); } /** -* Default prefix key -*/ + * Default prefix key + */ if( !defined( 'XMLS_PREFIX' ) ) { define( 'XMLS_PREFIX', '%%P' ); } /** -* Maximum length allowed for object prefix -*/ + * Maximum length allowed for object prefix + */ if( !defined( 'XMLS_PREFIX_MAXLEN' ) ) { define( 'XMLS_PREFIX_MAXLEN', 10 ); } /** -* Execute SQL inline as it is generated -*/ + * Execute SQL inline as it is generated + */ if( !defined( 'XMLS_EXECUTE_INLINE' ) ) { define( 'XMLS_EXECUTE_INLINE', FALSE ); } /** -* Continue SQL Execution if an error occurs? -*/ + * Continue SQL Execution if an error occurs? + */ if( !defined( 'XMLS_CONTINUE_ON_ERROR' ) ) { define( 'XMLS_CONTINUE_ON_ERROR', FALSE ); } /** -* Current Schema Version -*/ + * Current Schema Version + */ if( !defined( 'XMLS_SCHEMA_VERSION' ) ) { define( 'XMLS_SCHEMA_VERSION', '0.2' ); } /** -* Default Schema Version. Used for Schemas without an explicit version set. -*/ + * Default Schema Version. Used for Schemas without an explicit version set. + */ if( !defined( 'XMLS_DEFAULT_SCHEMA_VERSION' ) ) { define( 'XMLS_DEFAULT_SCHEMA_VERSION', '0.1' ); } /** -* Default Schema Version. Used for Schemas without an explicit version set. -*/ + * Default Schema Version. Used for Schemas without an explicit version set. + */ if( !defined( 'XMLS_DEFAULT_UPGRADE_METHOD' ) ) { define( 'XMLS_DEFAULT_UPGRADE_METHOD', 'ALTER' ); } /** -* Include the main ADODB library -*/ + * Include the main ADODB library + */ if( !defined( '_ADODB_LAYER' ) ) { require( 'adodb.inc.php' ); require( 'adodb-datadict.inc.php' ); } /** -* Abstract DB Object. This class provides basic methods for database objects, such -* as tables and indexes. -* -* @package axmls -* @access private -*/ + * Abstract DB Object. This class provides basic methods for database objects, such + * as tables and indexes. + * + * @package axmls + * @access private + */ class dbObject { /** - * var object Parent - */ + * var object Parent + */ var $parent; /** - * var string current element - */ + * var string current element + */ var $currentElement; /** - * NOP - */ + * NOP + */ function __construct( $parent, $attributes = NULL ) { $this->parent = $parent; } /** - * XML Callback to process start elements - * - * @access private - */ + * XML Callback to process start elements + * + * @access private + */ function _tag_open( &$parser, $tag, $attributes ) { } /** - * XML Callback to process CDATA elements - * - * @access private - */ + * XML Callback to process CDATA elements + * + * @access private + */ function _tag_cdata( &$parser, $cdata ) { } /** - * XML Callback to process end elements - * - * @access private - */ + * XML Callback to process end elements + * + * @access private + */ function _tag_close( &$parser, $tag ) { } @@ -148,110 +148,110 @@ class dbObject { } /** - * Destroys the object - */ + * Destroys the object + */ function destroy() { } /** - * Checks whether the specified RDBMS is supported by the current - * database object or its ranking ancestor. - * - * @param string $platform RDBMS platform name (from ADODB platform list). - * @return boolean TRUE if RDBMS is supported; otherwise returns FALSE. - */ + * Checks whether the specified RDBMS is supported by the current + * database object or its ranking ancestor. + * + * @param string $platform RDBMS platform name (from ADODB platform list). + * @return boolean TRUE if RDBMS is supported; otherwise returns FALSE. + */ function supportedPlatform( $platform = NULL ) { return is_object( $this->parent ) ? $this->parent->supportedPlatform( $platform ) : TRUE; } /** - * Returns the prefix set by the ranking ancestor of the database object. - * - * @param string $name Prefix string. - * @return string Prefix. - */ + * Returns the prefix set by the ranking ancestor of the database object. + * + * @param string $name Prefix string. + * @return string Prefix. + */ function prefix( $name = '' ) { return is_object( $this->parent ) ? $this->parent->prefix( $name ) : $name; } /** - * Extracts a field ID from the specified field. - * - * @param string $field Field. - * @return string Field ID. - */ + * Extracts a field ID from the specified field. + * + * @param string $field Field. + * @return string Field ID. + */ function FieldID( $field ) { return strtoupper( preg_replace( '/^`(.+)`$/', '$1', $field ) ); } } /** -* Creates a table object in ADOdb's datadict format -* -* This class stores information about a database table. As charactaristics -* of the table are loaded from the external source, methods and properties -* of this class are used to build up the table description in ADOdb's -* datadict format. -* -* @package axmls -* @access private -*/ + * Creates a table object in ADOdb's datadict format + * + * This class stores information about a database table. As charactaristics + * of the table are loaded from the external source, methods and properties + * of this class are used to build up the table description in ADOdb's + * datadict format. + * + * @package axmls + * @access private + */ class dbTable extends dbObject { /** - * @var string Table name - */ + * @var string Table name + */ var $name; /** - * @var array Field specifier: Meta-information about each field - */ + * @var array Field specifier: Meta-information about each field + */ var $fields = array(); /** - * @var array List of table indexes. - */ + * @var array List of table indexes. + */ var $indexes = array(); /** - * @var array Table options: Table-level options - */ + * @var array Table options: Table-level options + */ var $opts = array(); /** - * @var string Field index: Keeps track of which field is currently being processed - */ + * @var string Field index: Keeps track of which field is currently being processed + */ var $current_field; /** - * @var boolean Mark table for destruction - * @access private - */ + * @var boolean Mark table for destruction + * @access private + */ var $drop_table; /** - * @var boolean Mark field for destruction (not yet implemented) - * @access private - */ + * @var boolean Mark field for destruction (not yet implemented) + * @access private + */ var $drop_field = array(); /** - * Iniitializes a new table object. - * - * @param string $prefix DB Object prefix - * @param array $attributes Array of table attributes. - */ + * Iniitializes a new table object. + * + * @param string $prefix DB Object prefix + * @param array $attributes Array of table attributes. + */ function __construct( $parent, $attributes = NULL ) { $this->parent = $parent; $this->name = $this->prefix($attributes['NAME']); } /** - * XML Callback to process start elements. Elements currently - * processed are: INDEX, DROP, FIELD, KEY, NOTNULL, AUTOINCREMENT & DEFAULT. - * - * @access private - */ + * XML Callback to process start elements. Elements currently + * processed are: INDEX, DROP, FIELD, KEY, NOTNULL, AUTOINCREMENT & DEFAULT. + * + * @access private + */ function _tag_open( &$parser, $tag, $attributes ) { $this->currentElement = strtoupper( $tag ); @@ -307,10 +307,10 @@ class dbTable extends dbObject { } /** - * XML Callback to process CDATA elements - * - * @access private - */ + * XML Callback to process CDATA elements + * + * @access private + */ function _tag_cdata( &$parser, $cdata ) { switch( $this->currentElement ) { // Table constraint @@ -331,10 +331,10 @@ class dbTable extends dbObject { } /** - * XML Callback to process end elements - * - * @access private - */ + * XML Callback to process end elements + * + * @access private + */ function _tag_close( &$parser, $tag ) { $this->currentElement = ''; @@ -352,11 +352,11 @@ class dbTable extends dbObject { } /** - * Adds an index to a table object - * - * @param array $attributes Index attributes - * @return object dbIndex object - */ + * Adds an index to a table object + * + * @param array $attributes Index attributes + * @return object dbIndex object + */ function addIndex( $attributes ) { $name = strtoupper( $attributes['NAME'] ); $this->indexes[$name] = new dbIndex( $this, $attributes ); @@ -364,11 +364,11 @@ class dbTable extends dbObject { } /** - * Adds data to a table object - * - * @param array $attributes Data attributes - * @return object dbData object - */ + * Adds data to a table object + * + * @param array $attributes Data attributes + * @return object dbData object + */ function addData( $attributes ) { if( !isset( $this->data ) ) { $this->data = new dbData( $this, $attributes ); @@ -377,34 +377,34 @@ class dbTable extends dbObject { } /** - * Adds a field to a table object - * - * $name is the name of the table to which the field should be added. - * $type is an ADODB datadict field type. The following field types - * are supported as of ADODB 3.40: - * - C: varchar - * - X: CLOB (character large object) or largest varchar size - * if CLOB is not supported - * - C2: Multibyte varchar - * - X2: Multibyte CLOB - * - B: BLOB (binary large object) - * - D: Date (some databases do not support this, and we return a datetime type) - * - T: Datetime or Timestamp - * - L: Integer field suitable for storing booleans (0 or 1) - * - I: Integer (mapped to I4) - * - I1: 1-byte integer - * - I2: 2-byte integer - * - I4: 4-byte integer - * - I8: 8-byte integer - * - F: Floating point number - * - N: Numeric or decimal number - * - * @param string $name Name of the table to which the field will be added. - * @param string $type ADODB datadict field type. - * @param string $size Field size - * @param array $opts Field options array - * @return array Field specifier array - */ + * Adds a field to a table object + * + * $name is the name of the table to which the field should be added. + * $type is an ADODB datadict field type. The following field types + * are supported as of ADODB 3.40: + * - C: varchar + * - X: CLOB (character large object) or largest varchar size + * if CLOB is not supported + * - C2: Multibyte varchar + * - X2: Multibyte CLOB + * - B: BLOB (binary large object) + * - D: Date (some databases do not support this, and we return a datetime type) + * - T: Datetime or Timestamp + * - L: Integer field suitable for storing booleans (0 or 1) + * - I: Integer (mapped to I4) + * - I1: 1-byte integer + * - I2: 2-byte integer + * - I4: 4-byte integer + * - I8: 8-byte integer + * - F: Floating point number + * - N: Numeric or decimal number + * + * @param string $name Name of the table to which the field will be added. + * @param string $type ADODB datadict field type. + * @param string $size Field size + * @param array $opts Field options array + * @return array Field specifier array + */ function addField( $name, $type, $size = NULL, $opts = NULL ) { $field_id = $this->FieldID( $name ); @@ -429,16 +429,16 @@ class dbTable extends dbObject { } /** - * Adds a field option to the current field specifier - * - * This method adds a field option allowed by the ADOdb datadict - * and appends it to the given field. - * - * @param string $field Field name - * @param string $opt ADOdb field option - * @param mixed $value Field option value - * @return array Field specifier array - */ + * Adds a field option to the current field specifier + * + * This method adds a field option allowed by the ADOdb datadict + * and appends it to the given field. + * + * @param string $field Field name + * @param string $opt ADOdb field option + * @param mixed $value Field option value + * @return array Field specifier array + */ function addFieldOpt( $field, $opt, $value = NULL ) { if( !isset( $value ) ) { $this->fields[$this->FieldID( $field )]['OPTS'][] = $opt; @@ -449,14 +449,14 @@ class dbTable extends dbObject { } /** - * Adds an option to the table - * - * This method takes a comma-separated list of table-level options - * and appends them to the table object. - * - * @param string $opt Table option - * @return array Options - */ + * Adds an option to the table + * + * This method takes a comma-separated list of table-level options + * and appends them to the table object. + * + * @param string $opt Table option + * @return array Options + */ function addTableOpt( $opt ) { if(isset($this->currentPlatform)) { $this->opts[$this->parent->db->databaseType] = $opt; @@ -466,11 +466,11 @@ class dbTable extends dbObject { /** - * Generates the SQL that will create the table in the database - * - * @param object $xmls adoSchema object - * @return array Array containing table creation SQL - */ + * Generates the SQL that will create the table in the database + * + * @param object $xmls adoSchema object + * @return array Array containing table creation SQL + */ function create( &$xmls ) { $sql = array(); @@ -578,8 +578,8 @@ class dbTable extends dbObject { } /** - * Marks a field or table for destruction - */ + * Marks a field or table for destruction + */ function drop() { if( isset( $this->current_field ) ) { // Drop the current field @@ -596,47 +596,47 @@ class dbTable extends dbObject { } /** -* Creates an index object in ADOdb's datadict format -* -* This class stores information about a database index. As charactaristics -* of the index are loaded from the external source, methods and properties -* of this class are used to build up the index description in ADOdb's -* datadict format. -* -* @package axmls -* @access private -*/ + * Creates an index object in ADOdb's datadict format + * + * This class stores information about a database index. As charactaristics + * of the index are loaded from the external source, methods and properties + * of this class are used to build up the index description in ADOdb's + * datadict format. + * + * @package axmls + * @access private + */ class dbIndex extends dbObject { /** - * @var string Index name - */ + * @var string Index name + */ var $name; /** - * @var array Index options: Index-level options - */ + * @var array Index options: Index-level options + */ var $opts = array(); /** - * @var array Indexed fields: Table columns included in this index - */ + * @var array Indexed fields: Table columns included in this index + */ var $columns = array(); /** - * @var boolean Mark index for destruction - * @access private - */ + * @var boolean Mark index for destruction + * @access private + */ var $drop = FALSE; /** - * Initializes the new dbIndex object. - * - * @param object $parent Parent object - * @param array $attributes Attributes - * - * @internal - */ + * Initializes the new dbIndex object. + * + * @param object $parent Parent object + * @param array $attributes Attributes + * + * @internal + */ function __construct( $parent, $attributes = NULL ) { $this->parent = $parent; @@ -644,13 +644,13 @@ class dbIndex extends dbObject { } /** - * XML Callback to process start elements - * - * Processes XML opening tags. - * Elements currently processed are: DROP, CLUSTERED, BITMAP, UNIQUE, FULLTEXT & HASH. - * - * @access private - */ + * XML Callback to process start elements + * + * Processes XML opening tags. + * Elements currently processed are: DROP, CLUSTERED, BITMAP, UNIQUE, FULLTEXT & HASH. + * + * @access private + */ function _tag_open( &$parser, $tag, $attributes ) { $this->currentElement = strtoupper( $tag ); @@ -672,12 +672,12 @@ class dbIndex extends dbObject { } /** - * XML Callback to process CDATA elements - * - * Processes XML cdata. - * - * @access private - */ + * XML Callback to process CDATA elements + * + * Processes XML cdata. + * + * @access private + */ function _tag_cdata( &$parser, $cdata ) { switch( $this->currentElement ) { // Index field name @@ -690,10 +690,10 @@ class dbIndex extends dbObject { } /** - * XML Callback to process end elements - * - * @access private - */ + * XML Callback to process end elements + * + * @access private + */ function _tag_close( &$parser, $tag ) { $this->currentElement = ''; @@ -705,11 +705,11 @@ class dbIndex extends dbObject { } /** - * Adds a field to the index - * - * @param string $name Field name - * @return string Field list - */ + * Adds a field to the index + * + * @param string $name Field name + * @return string Field list + */ function addField( $name ) { $this->columns[$this->FieldID( $name )] = $name; @@ -718,11 +718,11 @@ class dbIndex extends dbObject { } /** - * Adds options to the index - * - * @param string $opt Comma-separated list of index options. - * @return string Option list - */ + * Adds options to the index + * + * @param string $opt Comma-separated list of index options. + * @return string Option list + */ function addIndexOpt( $opt ) { $this->opts[] = $opt; @@ -731,11 +731,11 @@ class dbIndex extends dbObject { } /** - * Generates the SQL that will create the index in the database - * - * @param object $xmls adoSchema object - * @return array Array containing index creation SQL - */ + * Generates the SQL that will create the index in the database + * + * @param object $xmls adoSchema object + * @return array Array containing index creation SQL + */ function create( &$xmls ) { if( $this->drop ) { return NULL; @@ -752,21 +752,21 @@ class dbIndex extends dbObject { } /** - * Marks an index for destruction - */ + * Marks an index for destruction + */ function drop() { $this->drop = TRUE; } } /** -* Creates a data object in ADOdb's datadict format -* -* This class stores information about table data. -* -* @package axmls -* @access private -*/ + * Creates a data object in ADOdb's datadict format + * + * This class stores information about table data. + * + * @package axmls + * @access private + */ class dbData extends dbObject { var $data = array(); @@ -774,25 +774,25 @@ class dbData extends dbObject { var $row; /** - * Initializes the new dbIndex object. - * - * @param object $parent Parent object - * @param array $attributes Attributes - * - * @internal - */ + * Initializes the new dbIndex object. + * + * @param object $parent Parent object + * @param array $attributes Attributes + * + * @internal + */ function __construct( $parent, $attributes = NULL ) { $this->parent = $parent; } /** - * XML Callback to process start elements - * - * Processes XML opening tags. - * Elements currently processed are: DROP, CLUSTERED, BITMAP, UNIQUE, FULLTEXT & HASH. - * - * @access private - */ + * XML Callback to process start elements + * + * Processes XML opening tags. + * Elements currently processed are: DROP, CLUSTERED, BITMAP, UNIQUE, FULLTEXT & HASH. + * + * @access private + */ function _tag_open( &$parser, $tag, $attributes ) { $this->currentElement = strtoupper( $tag ); @@ -809,12 +809,12 @@ class dbData extends dbObject { } /** - * XML Callback to process CDATA elements - * - * Processes XML cdata. - * - * @access private - */ + * XML Callback to process CDATA elements + * + * Processes XML cdata. + * + * @access private + */ function _tag_cdata( &$parser, $cdata ) { switch( $this->currentElement ) { // Index field name @@ -827,10 +827,10 @@ class dbData extends dbObject { } /** - * XML Callback to process end elements - * - * @access private - */ + * XML Callback to process end elements + * + * @access private + */ function _tag_close( &$parser, $tag ) { $this->currentElement = ''; @@ -842,11 +842,11 @@ class dbData extends dbObject { } /** - * Adds a field to the index - * - * @param string $name Field name - * @return string Field list - */ + * Adds a field to the index + * + * @param string $name Field name + * @return string Field list + */ function addField( $attributes ) { if( isset( $attributes['NAME'] ) ) { $name = $attributes['NAME']; @@ -859,11 +859,11 @@ class dbData extends dbObject { } /** - * Adds options to the index - * - * @param string $opt Comma-separated list of index options. - * @return string Option list - */ + * Adds options to the index + * + * @param string $opt Comma-separated list of index options. + * @return string Option list + */ function addData( $cdata ) { if( !isset( $this->data[$this->row] ) ) { $this->data[$this->row] = array(); @@ -877,11 +877,11 @@ class dbData extends dbObject { } /** - * Generates the SQL that will create the index in the database - * - * @param object $xmls adoSchema object - * @return array Array containing index creation SQL - */ + * Generates the SQL that will create the index in the database + * + * @param object $xmls adoSchema object + * @return array Array containing index creation SQL + */ function create( &$xmls ) { $table = $xmls->dict->TableName($this->parent->name); $table_field_count = count($this->parent->fields); @@ -947,39 +947,39 @@ class dbData extends dbObject { } /** -* Creates the SQL to execute a list of provided SQL queries -* -* @package axmls -* @access private -*/ + * Creates the SQL to execute a list of provided SQL queries + * + * @package axmls + * @access private + */ class dbQuerySet extends dbObject { /** - * @var array List of SQL queries - */ + * @var array List of SQL queries + */ var $queries = array(); /** - * @var string String used to build of a query line by line - */ + * @var string String used to build of a query line by line + */ var $query; /** - * @var string Query prefix key - */ + * @var string Query prefix key + */ var $prefixKey = ''; /** - * @var boolean Auto prefix enable (TRUE) - */ + * @var boolean Auto prefix enable (TRUE) + */ var $prefixMethod = 'AUTO'; /** - * Initializes the query set. - * - * @param object $parent Parent object - * @param array $attributes Attributes - */ + * Initializes the query set. + * + * @param object $parent Parent object + * @param array $attributes Attributes + */ function __construct( $parent, $attributes = NULL ) { $this->parent = $parent; @@ -1005,11 +1005,11 @@ class dbQuerySet extends dbObject { } /** - * XML Callback to process start elements. Elements currently - * processed are: QUERY. - * - * @access private - */ + * XML Callback to process start elements. Elements currently + * processed are: QUERY. + * + * @access private + */ function _tag_open( &$parser, $tag, $attributes ) { $this->currentElement = strtoupper( $tag ); @@ -1030,8 +1030,8 @@ class dbQuerySet extends dbObject { } /** - * XML Callback to process CDATA elements - */ + * XML Callback to process CDATA elements + */ function _tag_cdata( &$parser, $cdata ) { switch( $this->currentElement ) { // Line of queryset SQL data @@ -1044,10 +1044,10 @@ class dbQuerySet extends dbObject { } /** - * XML Callback to process end elements - * - * @access private - */ + * XML Callback to process end elements + * + * @access private + */ function _tag_close( &$parser, $tag ) { $this->currentElement = ''; @@ -1067,10 +1067,10 @@ class dbQuerySet extends dbObject { } /** - * Re-initializes the query. - * - * @return boolean TRUE - */ + * Re-initializes the query. + * + * @return boolean TRUE + */ function newQuery() { $this->query = ''; @@ -1078,10 +1078,10 @@ class dbQuerySet extends dbObject { } /** - * Discards the existing query. - * - * @return boolean TRUE - */ + * Discards the existing query. + * + * @return boolean TRUE + */ function discardQuery() { unset( $this->query ); @@ -1089,11 +1089,11 @@ class dbQuerySet extends dbObject { } /** - * Appends a line to a query that is being built line by line - * - * @param string $data Line of SQL data or NULL to initialize a new query - * @return string SQL query string. - */ + * Appends a line to a query that is being built line by line + * + * @param string $data Line of SQL data or NULL to initialize a new query + * @return string SQL query string. + */ function buildQuery( $sql = NULL ) { if( !isset( $this->query ) OR empty( $sql ) ) { return FALSE; @@ -1105,10 +1105,10 @@ class dbQuerySet extends dbObject { } /** - * Adds a completed query to the query list - * - * @return string SQL of added query - */ + * Adds a completed query to the query list + * + * @return string SQL of added query + */ function addQuery() { if( !isset( $this->query ) ) { return FALSE; @@ -1122,11 +1122,11 @@ class dbQuerySet extends dbObject { } /** - * Creates and returns the current query set - * - * @param object $xmls adoSchema object - * @return array Query set - */ + * Creates and returns the current query set + * + * @param object $xmls adoSchema object + * @return array Query set + */ function create( &$xmls ) { foreach( $this->queries as $id => $query ) { switch( $this->prefixMethod ) { @@ -1162,13 +1162,13 @@ class dbQuerySet extends dbObject { } /** - * Rebuilds the query with the prefix attached to any objects - * - * @param string $regex Regex used to add prefix - * @param string $query SQL query string - * @param string $prefix Prefix to be appended to tables, indices, etc. - * @return string Prefixed SQL query string. - */ + * Rebuilds the query with the prefix attached to any objects + * + * @param string $regex Regex used to add prefix + * @param string $query SQL query string + * @param string $prefix Prefix to be appended to tables, indices, etc. + * @return string Prefixed SQL query string. + */ function prefixQuery( $regex, $query, $prefix = NULL ) { if( !isset( $prefix ) ) { return $query; @@ -1198,98 +1198,98 @@ class dbQuerySet extends dbObject { } /** -* Loads and parses an XML file, creating an array of "ready-to-run" SQL statements -* -* This class is used to load and parse the XML file, to create an array of SQL statements -* that can be used to build a database, and to build the database using the SQL array. -* -* @tutorial getting_started.pkg -* -* @author Richard Tango-Lowy & Dan Cech -* @version $Revision: 1.12 $ -* -* @package axmls -*/ + * Loads and parses an XML file, creating an array of "ready-to-run" SQL statements + * + * This class is used to load and parse the XML file, to create an array of SQL statements + * that can be used to build a database, and to build the database using the SQL array. + * + * @tutorial getting_started.pkg + * + * @author Richard Tango-Lowy & Dan Cech + * @version $Revision: 1.12 $ + * + * @package axmls + */ class adoSchema { /** - * @var array Array containing SQL queries to generate all objects - * @access private - */ + * @var array Array containing SQL queries to generate all objects + * @access private + */ var $sqlArray; /** - * @var object ADOdb connection object - * @access private - */ + * @var object ADOdb connection object + * @access private + */ var $db; /** - * @var object ADOdb Data Dictionary - * @access private - */ + * @var object ADOdb Data Dictionary + * @access private + */ var $dict; /** - * @var string Current XML element - * @access private - */ + * @var string Current XML element + * @access private + */ var $currentElement = ''; /** - * @var string If set (to 'ALTER' or 'REPLACE'), upgrade an existing database - * @access private - */ + * @var string If set (to 'ALTER' or 'REPLACE'), upgrade an existing database + * @access private + */ var $upgrade = ''; /** - * @var string Optional object prefix - * @access private - */ + * @var string Optional object prefix + * @access private + */ var $objectPrefix = ''; /** - * @var long System debug - * @access private - */ + * @var long System debug + * @access private + */ var $debug; /** - * @var string Regular expression to find schema version - * @access private - */ + * @var string Regular expression to find schema version + * @access private + */ var $versionRegex = '/<schema.*?( version="([^"]*)")?.*?>/'; /** - * @var string Current schema version - * @access private - */ + * @var string Current schema version + * @access private + */ var $schemaVersion; /** - * @var int Success of last Schema execution - */ + * @var int Success of last Schema execution + */ var $success; /** - * @var bool Execute SQL inline as it is generated - */ + * @var bool Execute SQL inline as it is generated + */ var $executeInline; /** - * @var bool Continue SQL execution if errors occur - */ + * @var bool Continue SQL execution if errors occur + */ var $continueOnError; /** - * Creates an adoSchema object - * - * Creating an adoSchema object is the first step in processing an XML schema. - * The only parameter is an ADOdb database connection object, which must already - * have been created. - * - * @param object $db ADOdb database connection object. - */ + * Creates an adoSchema object + * + * Creating an adoSchema object is the first step in processing an XML schema. + * The only parameter is an ADOdb database connection object, which must already + * have been created. + * + * @param object $db ADOdb database connection object. + */ function __construct( $db ) { $this->db = $db; $this->debug = $this->db->debug; @@ -1302,21 +1302,21 @@ class adoSchema { } /** - * Sets the method to be used for upgrading an existing database - * - * Use this method to specify how existing database objects should be upgraded. - * The method option can be set to ALTER, REPLACE, BEST, or NONE. ALTER attempts to - * alter each database object directly, REPLACE attempts to rebuild each object - * from scratch, BEST attempts to determine the best upgrade method for each - * object, and NONE disables upgrading. - * - * This method is not yet used by AXMLS, but exists for backward compatibility. - * The ALTER method is automatically assumed when the adoSchema object is - * instantiated; other upgrade methods are not currently supported. - * - * @param string $method Upgrade method (ALTER|REPLACE|BEST|NONE) - * @returns string Upgrade method used - */ + * Sets the method to be used for upgrading an existing database + * + * Use this method to specify how existing database objects should be upgraded. + * The method option can be set to ALTER, REPLACE, BEST, or NONE. ALTER attempts to + * alter each database object directly, REPLACE attempts to rebuild each object + * from scratch, BEST attempts to determine the best upgrade method for each + * object, and NONE disables upgrading. + * + * This method is not yet used by AXMLS, but exists for backward compatibility. + * The ALTER method is automatically assumed when the adoSchema object is + * instantiated; other upgrade methods are not currently supported. + * + * @param string $method Upgrade method (ALTER|REPLACE|BEST|NONE) + * @returns string Upgrade method used + */ function SetUpgradeMethod( $method = '' ) { if( !is_string( $method ) ) { return FALSE; @@ -1347,18 +1347,19 @@ class adoSchema { } /** - * Enables/disables inline SQL execution. - * - * Call this method to enable or disable inline execution of the schema. If the mode is set to TRUE (inline execution), - * AXMLS applies the SQL to the database immediately as each schema entity is parsed. If the mode - * is set to FALSE (post execution), AXMLS parses the entire schema and you will need to call adoSchema::ExecuteSchema() - * to apply the schema to the database. - * - * @param bool $mode execute - * @return bool current execution mode - * - * @see ParseSchema(), ExecuteSchema() - */ + * Enables/disables inline SQL execution. + * + * Call this method to enable or disable inline execution of the schema. If the mode is set to TRUE (inline execution), + * AXMLS applies the SQL to the database immediately as each schema entity is parsed. If the mode + * is set to FALSE (post execution), AXMLS parses the entire schema and you will need to call adoSchema::ExecuteSchema() + * to apply the schema to the database. + * + * @param bool $mode execute + * @return bool current execution mode + * + * @see ParseSchema() + * @see ExecuteSchema() + */ function ExecuteInline( $mode = NULL ) { if( is_bool( $mode ) ) { $this->executeInline = $mode; @@ -1368,18 +1369,19 @@ class adoSchema { } /** - * Enables/disables SQL continue on error. - * - * Call this method to enable or disable continuation of SQL execution if an error occurs. - * If the mode is set to TRUE (continue), AXMLS will continue to apply SQL to the database, even if an error occurs. - * If the mode is set to FALSE (halt), AXMLS will halt execution of generated sql if an error occurs, though parsing - * of the schema will continue. - * - * @param bool $mode execute - * @return bool current continueOnError mode - * - * @see addSQL(), ExecuteSchema() - */ + * Enables/disables SQL continue on error. + * + * Call this method to enable or disable continuation of SQL execution if an error occurs. + * If the mode is set to TRUE (continue), AXMLS will continue to apply SQL to the database, even if an error occurs. + * If the mode is set to FALSE (halt), AXMLS will halt execution of generated sql if an error occurs, though parsing + * of the schema will continue. + * + * @param bool $mode execute + * @return bool current continueOnError mode + * + * @see addSQL() + * @see ExecuteSchema() + */ function ContinueOnError( $mode = NULL ) { if( is_bool( $mode ) ) { $this->continueOnError = $mode; @@ -1389,33 +1391,34 @@ class adoSchema { } /** - * Loads an XML schema from a file and converts it to SQL. - * - * Call this method to load the specified schema (see the DTD for the proper format) from - * the filesystem and generate the SQL necessary to create the database described. - * @see ParseSchemaString() - * - * @param string $file Name of XML schema file. - * @param bool $returnSchema Return schema rather than parsing. - * @return array Array of SQL queries, ready to execute - */ + * Loads an XML schema from a file and converts it to SQL. + * + * Call this method to load the specified schema (see the DTD for the proper format) from + * the filesystem and generate the SQL necessary to create the database described. + * @see ParseSchemaString() + * + * @param string $file Name of XML schema file. + * @param bool $returnSchema Return schema rather than parsing. + * @return array Array of SQL queries, ready to execute + */ function ParseSchema( $filename, $returnSchema = FALSE ) { return $this->ParseSchemaString( $this->ConvertSchemaFile( $filename ), $returnSchema ); } /** - * Loads an XML schema from a file and converts it to SQL. - * - * Call this method to load the specified schema from a file (see the DTD for the proper format) - * and generate the SQL necessary to create the database described by the schema. - * - * @param string $file Name of XML schema file. - * @param bool $returnSchema Return schema rather than parsing. - * @return array Array of SQL queries, ready to execute. - * - * @deprecated Replaced by adoSchema::ParseSchema() and adoSchema::ParseSchemaString() - * @see ParseSchema(), ParseSchemaString() - */ + * Loads an XML schema from a file and converts it to SQL. + * + * Call this method to load the specified schema from a file (see the DTD for the proper format) + * and generate the SQL necessary to create the database described by the schema. + * + * @param string $file Name of XML schema file. + * @param bool $returnSchema Return schema rather than parsing. + * @return array Array of SQL queries, ready to execute. + * + * @deprecated Replaced by adoSchema::ParseSchema() and adoSchema::ParseSchemaString() + * @see ParseSchema() + * @see ParseSchemaString() + */ function ParseSchemaFile( $filename, $returnSchema = FALSE ) { // Open the file if( !($fp = fopen( $filename, 'r' )) ) { @@ -1458,16 +1461,16 @@ class adoSchema { } /** - * Converts an XML schema string to SQL. - * - * Call this method to parse a string containing an XML schema (see the DTD for the proper format) - * and generate the SQL necessary to create the database described by the schema. - * @see ParseSchema() - * - * @param string $xmlstring XML schema string. - * @param bool $returnSchema Return schema rather than parsing. - * @return array Array of SQL queries, ready to execute. - */ + * Converts an XML schema string to SQL. + * + * Call this method to parse a string containing an XML schema (see the DTD for the proper format) + * and generate the SQL necessary to create the database described by the schema. + * @see ParseSchema() + * + * @param string $xmlstring XML schema string. + * @param bool $returnSchema Return schema rather than parsing. + * @return array Array of SQL queries, ready to execute. + */ function ParseSchemaString( $xmlstring, $returnSchema = FALSE ) { if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) { return FALSE; @@ -1501,31 +1504,31 @@ class adoSchema { } /** - * Loads an XML schema from a file and converts it to uninstallation SQL. - * - * Call this method to load the specified schema (see the DTD for the proper format) from - * the filesystem and generate the SQL necessary to remove the database described. - * @see RemoveSchemaString() - * - * @param string $file Name of XML schema file. - * @param bool $returnSchema Return schema rather than parsing. - * @return array Array of SQL queries, ready to execute - */ + * Loads an XML schema from a file and converts it to uninstallation SQL. + * + * Call this method to load the specified schema (see the DTD for the proper format) from + * the filesystem and generate the SQL necessary to remove the database described. + * @see RemoveSchemaString() + * + * @param string $file Name of XML schema file. + * @param bool $returnSchema Return schema rather than parsing. + * @return array Array of SQL queries, ready to execute + */ function RemoveSchema( $filename, $returnSchema = FALSE ) { return $this->RemoveSchemaString( $this->ConvertSchemaFile( $filename ), $returnSchema ); } /** - * Converts an XML schema string to uninstallation SQL. - * - * Call this method to parse a string containing an XML schema (see the DTD for the proper format) - * and generate the SQL necessary to uninstall the database described by the schema. - * @see RemoveSchema() - * - * @param string $schema XML schema string. - * @param bool $returnSchema Return schema rather than parsing. - * @return array Array of SQL queries, ready to execute. - */ + * Converts an XML schema string to uninstallation SQL. + * + * Call this method to parse a string containing an XML schema (see the DTD for the proper format) + * and generate the SQL necessary to uninstall the database described by the schema. + * @see RemoveSchema() + * + * @param string $schema XML schema string. + * @param bool $returnSchema Return schema rather than parsing. + * @return array Array of SQL queries, ready to execute. + */ function RemoveSchemaString( $schema, $returnSchema = FALSE ) { // grab current version @@ -1537,18 +1540,20 @@ class adoSchema { } /** - * Applies the current XML schema to the database (post execution). - * - * Call this method to apply the current schema (generally created by calling - * ParseSchema() or ParseSchemaString() ) to the database (creating the tables, indexes, - * and executing other SQL specified in the schema) after parsing. - * @see ParseSchema(), ParseSchemaString(), ExecuteInline() - * - * @param array $sqlArray Array of SQL statements that will be applied rather than - * the current schema. - * @param boolean $continueOnErr Continue to apply the schema even if an error occurs. - * @returns integer 0 if failure, 1 if errors, 2 if successful. - */ + * Applies the current XML schema to the database (post execution). + * + * Call this method to apply the current schema (generally created by calling + * ParseSchema() or ParseSchemaString() ) to the database (creating the tables, indexes, + * and executing other SQL specified in the schema) after parsing. + * @see ParseSchema() + * @see ParseSchemaString() + * @see ExecuteInline() + * + * @param array $sqlArray Array of SQL statements that will be applied rather than + * the current schema. + * @param boolean $continueOnErr Continue to apply the schema even if an error occurs. + * @returns integer 0 if failure, 1 if errors, 2 if successful. + */ function ExecuteSchema( $sqlArray = NULL, $continueOnErr = NULL ) { if( !is_bool( $continueOnErr ) ) { $continueOnErr = $this->ContinueOnError(); @@ -1568,28 +1573,28 @@ class adoSchema { } /** - * Returns the current SQL array. - * - * Call this method to fetch the array of SQL queries resulting from - * ParseSchema() or ParseSchemaString(). - * - * @param string $format Format: HTML, TEXT, or NONE (PHP array) - * @return array Array of SQL statements or FALSE if an error occurs - */ + * Returns the current SQL array. + * + * Call this method to fetch the array of SQL queries resulting from + * ParseSchema() or ParseSchemaString(). + * + * @param string $format Format: HTML, TEXT, or NONE (PHP array) + * @return array Array of SQL statements or FALSE if an error occurs + */ function PrintSQL( $format = 'NONE' ) { $sqlArray = null; return $this->getSQL( $format, $sqlArray ); } /** - * Saves the current SQL array to the local filesystem as a list of SQL queries. - * - * Call this method to save the array of SQL queries (generally resulting from a - * parsed XML schema) to the filesystem. - * - * @param string $filename Path and name where the file should be saved. - * @return boolean TRUE if save is successful, else FALSE. - */ + * Saves the current SQL array to the local filesystem as a list of SQL queries. + * + * Call this method to save the array of SQL queries (generally resulting from a + * parsed XML schema) to the filesystem. + * + * @param string $filename Path and name where the file should be saved. + * @return boolean TRUE if save is successful, else FALSE. + */ function SaveSQL( $filename = './schema.sql' ) { if( !isset( $sqlArray ) ) { @@ -1608,12 +1613,12 @@ class adoSchema { } /** - * Create an xml parser - * - * @return object PHP XML parser object - * - * @access private - */ + * Create an xml parser + * + * @return object PHP XML parser object + * + * @access private + */ function create_parser() { // Create the parser $xmlParser = xml_parser_create(); @@ -1627,10 +1632,10 @@ class adoSchema { } /** - * XML Callback to process start elements - * - * @access private - */ + * XML Callback to process start elements + * + * @access private + */ function _tag_open( &$parser, $tag, $attributes ) { switch( strtoupper( $tag ) ) { case 'TABLE': @@ -1650,39 +1655,39 @@ class adoSchema { } /** - * XML Callback to process CDATA elements - * - * @access private - */ + * XML Callback to process CDATA elements + * + * @access private + */ function _tag_cdata( &$parser, $cdata ) { } /** - * XML Callback to process end elements - * - * @access private - * @internal - */ + * XML Callback to process end elements + * + * @access private + * @internal + */ function _tag_close( &$parser, $tag ) { } /** - * Converts an XML schema string to the specified DTD version. - * - * Call this method to convert a string containing an XML schema to a different AXMLS - * DTD version. For instance, to convert a schema created for an pre-1.0 version for - * AXMLS (DTD version 0.1) to a newer version of the DTD (e.g. 0.2). If no DTD version - * parameter is specified, the schema will be converted to the current DTD version. - * If the newFile parameter is provided, the converted schema will be written to the specified - * file. - * @see ConvertSchemaFile() - * - * @param string $schema String containing XML schema that will be converted. - * @param string $newVersion DTD version to convert to. - * @param string $newFile File name of (converted) output file. - * @return string Converted XML schema or FALSE if an error occurs. - */ + * Converts an XML schema string to the specified DTD version. + * + * Call this method to convert a string containing an XML schema to a different AXMLS + * DTD version. For instance, to convert a schema created for an pre-1.0 version for + * AXMLS (DTD version 0.1) to a newer version of the DTD (e.g. 0.2). If no DTD version + * parameter is specified, the schema will be converted to the current DTD version. + * If the newFile parameter is provided, the converted schema will be written to the specified + * file. + * @see ConvertSchemaFile() + * + * @param string $schema String containing XML schema that will be converted. + * @param string $newVersion DTD version to convert to. + * @param string $newFile File name of (converted) output file. + * @return string Converted XML schema or FALSE if an error occurs. + */ function ConvertSchemaString( $schema, $newVersion = NULL, $newFile = NULL ) { // grab current version @@ -1709,21 +1714,21 @@ class adoSchema { } /** - * Converts an XML schema file to the specified DTD version. - * - * Call this method to convert the specified XML schema file to a different AXMLS - * DTD version. For instance, to convert a schema created for an pre-1.0 version for - * AXMLS (DTD version 0.1) to a newer version of the DTD (e.g. 0.2). If no DTD version - * parameter is specified, the schema will be converted to the current DTD version. - * If the newFile parameter is provided, the converted schema will be written to the specified - * file. - * @see ConvertSchemaString() - * - * @param string $filename Name of XML schema file that will be converted. - * @param string $newVersion DTD version to convert to. - * @param string $newFile File name of (converted) output file. - * @return string Converted XML schema or FALSE if an error occurs. - */ + * Converts an XML schema file to the specified DTD version. + * + * Call this method to convert the specified XML schema file to a different AXMLS + * DTD version. For instance, to convert a schema created for an pre-1.0 version for + * AXMLS (DTD version 0.1) to a newer version of the DTD (e.g. 0.2). If no DTD version + * parameter is specified, the schema will be converted to the current DTD version. + * If the newFile parameter is provided, the converted schema will be written to the specified + * file. + * @see ConvertSchemaString() + * + * @param string $filename Name of XML schema file that will be converted. + * @param string $newVersion DTD version to convert to. + * @param string $newFile File name of (converted) output file. + * @return string Converted XML schema or FALSE if an error occurs. + */ function ConvertSchemaFile( $filename, $newVersion = NULL, $newFile = NULL ) { // grab current version @@ -1804,15 +1809,15 @@ class adoSchema { } /** - * Processes XSLT transformation errors - * - * @param object $parser XML parser object - * @param integer $errno Error number - * @param integer $level Error level - * @param array $fields Error information fields - * - * @access private - */ + * Processes XSLT transformation errors + * + * @param object $parser XML parser object + * @param integer $errno Error number + * @param integer $level Error level + * @param array $fields Error information fields + * + * @access private + */ function xslt_error_handler( $parser, $errno, $level, $fields ) { if( is_array( $fields ) ) { $msg = array( @@ -1857,14 +1862,14 @@ class adoSchema { } /** - * Returns the AXMLS Schema Version of the requested XML schema file. - * - * Call this method to obtain the AXMLS DTD version of the requested XML schema file. - * @see SchemaStringVersion() - * - * @param string $filename AXMLS schema file - * @return string Schema version number or FALSE on error - */ + * Returns the AXMLS Schema Version of the requested XML schema file. + * + * Call this method to obtain the AXMLS DTD version of the requested XML schema file. + * @see SchemaStringVersion() + * + * @param string $filename AXMLS schema file + * @return string Schema version number or FALSE on error + */ function SchemaFileVersion( $filename ) { // Open the file if( !($fp = fopen( $filename, 'r' )) ) { @@ -1883,14 +1888,14 @@ class adoSchema { } /** - * Returns the AXMLS Schema Version of the provided XML schema string. - * - * Call this method to obtain the AXMLS DTD version of the provided XML schema string. - * @see SchemaFileVersion() - * - * @param string $xmlstring XML schema string - * @return string Schema version number or FALSE on error - */ + * Returns the AXMLS Schema Version of the provided XML schema string. + * + * Call this method to obtain the AXMLS DTD version of the provided XML schema string. + * @see SchemaFileVersion() + * + * @param string $xmlstring XML schema string + * @return string Schema version number or FALSE on error + */ function SchemaStringVersion( $xmlstring ) { if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) { return FALSE; @@ -1904,15 +1909,15 @@ class adoSchema { } /** - * Extracts an XML schema from an existing database. - * - * Call this method to create an XML schema string from an existing database. - * If the data parameter is set to TRUE, AXMLS will include the data from the database - * in the schema. - * - * @param boolean $data Include data in schema dump - * @return string Generated XML schema - */ + * Extracts an XML schema from an existing database. + * + * Call this method to create an XML schema string from an existing database. + * If the data parameter is set to TRUE, AXMLS will include the data from the database + * in the schema. + * + * @param boolean $data Include data in schema dump + * @return string Generated XML schema + */ function ExtractSchema( $data = FALSE ) { $old_mode = $this->db->SetFetchMode( ADODB_FETCH_NUM ); @@ -2011,15 +2016,15 @@ class adoSchema { } /** - * Sets a prefix for database objects - * - * Call this method to set a standard prefix that will be prepended to all database tables - * and indices when the schema is parsed. Calling setPrefix with no arguments clears the prefix. - * - * @param string $prefix Prefix that will be prepended. - * @param boolean $underscore If TRUE, automatically append an underscore character to the prefix. - * @return boolean TRUE if successful, else FALSE - */ + * Sets a prefix for database objects + * + * Call this method to set a standard prefix that will be prepended to all database tables + * and indices when the schema is parsed. Calling setPrefix with no arguments clears the prefix. + * + * @param string $prefix Prefix that will be prepended. + * @param boolean $underscore If TRUE, automatically append an underscore character to the prefix. + * @return boolean TRUE if successful, else FALSE + */ function SetPrefix( $prefix = '', $underscore = TRUE ) { switch( TRUE ) { // clear prefix @@ -2046,13 +2051,13 @@ class adoSchema { } /** - * Returns an object name with the current prefix prepended. - * - * @param string $name Name - * @return string Prefixed name - * - * @access private - */ + * Returns an object name with the current prefix prepended. + * + * @param string $name Name + * @return string Prefixed name + * + * @access private + */ function prefix( $name = '' ) { // if prefix is set if( !empty( $this->objectPrefix ) ) { @@ -2066,13 +2071,13 @@ class adoSchema { } /** - * Checks if element references a specific platform - * - * @param string $platform Requested platform - * @returns boolean TRUE if platform check succeeds - * - * @access private - */ + * Checks if element references a specific platform + * + * @param string $platform Requested platform + * @returns boolean TRUE if platform check succeeds + * + * @access private + */ function supportedPlatform( $platform = NULL ) { $regex = '/^(\w*\|)*' . $this->db->databaseType . '(\|\w*)*$/'; @@ -2086,22 +2091,22 @@ class adoSchema { } /** - * Clears the array of generated SQL. - * - * @access private - */ + * Clears the array of generated SQL. + * + * @access private + */ function clearSQL() { $this->sqlArray = array(); } /** - * Adds SQL into the SQL array. - * - * @param mixed $sql SQL to Add - * @return boolean TRUE if successful, else FALSE. - * - * @access private - */ + * Adds SQL into the SQL array. + * + * @param mixed $sql SQL to Add + * @return boolean TRUE if successful, else FALSE. + * + * @access private + */ function addSQL( $sql = NULL ) { if( is_array( $sql ) ) { foreach( $sql as $line ) { @@ -2137,13 +2142,13 @@ class adoSchema { } /** - * Gets the SQL array in the specified format. - * - * @param string $format Format - * @return mixed SQL - * - * @access private - */ + * Gets the SQL array in the specified format. + * + * @param string $format Format + * @return mixed SQL + * + * @access private + */ function getSQL( $format = NULL, $sqlArray = NULL ) { if( !is_array( $sqlArray ) ) { $sqlArray = $this->sqlArray; @@ -2165,19 +2170,19 @@ class adoSchema { } /** - * Destroys an adoSchema object. - * - * Call this method to clean up after an adoSchema object that is no longer in use. - * @deprecated adoSchema now cleans up automatically. - */ + * Destroys an adoSchema object. + * + * Call this method to clean up after an adoSchema object that is no longer in use. + * @deprecated adoSchema now cleans up automatically. + */ function Destroy() {} } /** -* Message logging function -* -* @access private -*/ + * Message logging function + * + * @access private + */ function logMsg( $msg, $title = NULL, $force = FALSE ) { if( XMLS_DEBUG or $force ) { echo '<pre>'; |
