⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adodb-xmlschema03.inc.php

📁 远程教育系统
💻 PHP
📖 第 1 页 / 共 5 页
字号:
	* @param string $opt ADOdb field option	* @param mixed $value Field option value	* @return array Field specifier array	*/	function addFieldOpt( $field, $opt, $value = NULL ) {		if( $this->currentPlatform ) {		if( !isset( $value ) ) {			$this->fields[$this->FieldID( $field )]['OPTS'][] = $opt;		// Add the option and value		} else {			$this->fields[$this->FieldID( $field )]['OPTS'][] = array( $opt => $value );		}	}	}		/**	* 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( $this->currentPlatform ) {		$this->opts[] = $opt;		}		return $this->opts;	}		/**	* 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();				// drop any existing indexes		if( is_array( $legacy_indexes = $xmls->dict->MetaIndexes( $this->name ) ) ) {			foreach( $legacy_indexes as $index => $index_details ) {				$sql[] = $xmls->dict->DropIndexSQL( $index, $this->name );			}		}				// remove fields to be dropped from table object		foreach( $this->drop_field as $field ) {			unset( $this->fields[$field] );		}				// if table exists		if( is_array( $legacy_fields = $xmls->dict->MetaColumns( $this->name ) ) ) {			// drop table			if( $this->drop_table ) {				$sql[] = $xmls->dict->DropTableSQL( $this->name );								return $sql;			}						// drop any existing fields not in schema			foreach( $legacy_fields as $field_id => $field ) {				if( !isset( $this->fields[$field_id] ) ) {					$sql[] = $xmls->dict->DropColumnSQL( $this->name, $field->name );				}			}		// if table doesn't exist		} else {			if( $this->drop_table ) {				return $sql;			}						$legacy_fields = array();		}				// Loop through the field specifier array, building the associative array for the field options		$fldarray = array();				foreach( $this->fields as $field_id => $finfo ) {			// Set an empty size if it isn't supplied			if( !isset( $finfo['SIZE'] ) ) {				$finfo['SIZE'] = '';			}						// Initialize the field array with the type and size			$fldarray[$field_id] = array(				'NAME' => $finfo['NAME'],				'TYPE' => $finfo['TYPE'],				'SIZE' => $finfo['SIZE']			);						// Loop through the options array and add the field options. 			if( isset( $finfo['OPTS'] ) ) {				foreach( $finfo['OPTS'] as $opt ) {					// Option has an argument.					if( is_array( $opt ) ) {						$key = key( $opt );						$value = $opt[key( $opt )];						@$fldarray[$field_id][$key] .= $value;					// Option doesn't have arguments					} else {						$fldarray[$field_id][$opt] = $opt;					}				}			}		}				if( empty( $legacy_fields ) ) {			// Create the new table			$sql[] = $xmls->dict->CreateTableSQL( $this->name, $fldarray, $this->opts );			logMsg( end( $sql ), 'Generated CreateTableSQL' );		} else {			// Upgrade an existing table			logMsg( "Upgrading {$this->name} using '{$xmls->upgrade}'" );			switch( $xmls->upgrade ) {				// Use ChangeTableSQL				case 'ALTER':					logMsg( 'Generated ChangeTableSQL (ALTERing table)' );					$sql[] = $xmls->dict->ChangeTableSQL( $this->name, $fldarray, $this->opts );					break;				case 'REPLACE':					logMsg( 'Doing upgrade REPLACE (testing)' );					$sql[] = $xmls->dict->DropTableSQL( $this->name );					$sql[] = $xmls->dict->CreateTableSQL( $this->name, $fldarray, $this->opts );					break;				// ignore table				default:					return array();			}		}				foreach( $this->indexes as $index ) {			$sql[] = $index->create( $xmls );		}				if( isset( $this->data ) ) {			$sql[] = $this->data->create( $xmls );		}				return $sql;	}		/**	* Marks a field or table for destruction	*/	function drop() {		if( isset( $this->current_field ) ) {			// Drop the current field			logMsg( "Dropping field '{$this->current_field}' from table '{$this->name}'" );			// $this->drop_field[$this->current_field] = $xmls->dict->DropColumnSQL( $this->name, $this->current_field );			$this->drop_field[$this->current_field] = $this->current_field;		} else {			// Drop the current table			logMsg( "Dropping table '{$this->name}'" );			// $this->drop_table = $xmls->dict->DropTableSQL( $this->name );			$this->drop_table = TRUE;		}	}}/*** 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 $name;		/**	* @var array	Index options: Index-level options	*/	var $opts = array();		/**	* @var array	Indexed fields: Table columns included in this index	*/	var $columns = array();		/**	* @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	*/	function dbIndex( &$parent, $attributes = NULL ) {		$this->parent =& $parent;				$this->name = $this->prefix ($attributes['NAME']);	}		/**	* 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 );				switch( $this->currentElement ) {			case 'DROP':				$this->drop();				break;			case 'CLUSTERED':			case 'BITMAP':			case 'UNIQUE':			case 'FULLTEXT':			case 'HASH':				// Add index Option				$this->addIndexOpt( $this->currentElement );				break;			default:				// print_r( array( $tag, $attributes ) );		}	}		/**	* XML Callback to process CDATA elements	*	* Processes XML cdata.	*	* @access private	*/	function _tag_cdata( &$parser, $cdata ) {		switch( $this->currentElement ) {			// Index field name			case 'COL':				$this->addField( $cdata );				break;			default:						}	}		/**	* XML Callback to process end elements	*	* @access private	*/	function _tag_close( &$parser, $tag ) {		$this->currentElement = '';				switch( strtoupper( $tag ) ) {			case 'INDEX':				xml_set_object( $parser, $this->parent );				break;		}	}		/**	* Adds a field to the index	*	* @param string $name Field name	* @return string Field list	*/	function addField( $name ) {		$this->columns[$this->FieldID( $name )] = $name;				// Return the field list		return $this->columns;	}		/**	* Adds options to the index	*	* @param string $opt Comma-separated list of index options.	* @return string Option list	*/	function addIndexOpt( $opt ) {		$this->opts[] = $opt;				// Return the options list		return $this->opts;	}		/**	* 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;		}				// eliminate any columns that aren't in the table		foreach( $this->columns as $id => $col ) {			if( !isset( $this->parent->fields[$id] ) ) {				unset( $this->columns[$id] );			}		}				return $xmls->dict->CreateIndexSQL( $this->name, $this->parent->name, $this->columns, $this->opts );	}		/**	* 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, and is called* when we need to load field data into a table.** @package axmls* @access private*/class dbData extends dbObject {		var $data = array();		var $row;		/**	* Initializes the new dbData object.	*	* @param object $parent Parent object	* @param array $attributes Attributes	*	* @internal	*/	function dbData( &$parent, $attributes = NULL ) {		$this->parent =& $parent;	}		/**	* XML Callback to process start elements	*	* Processes XML opening tags. 	* Elements currently processed are: ROW and F (field). 	*	* @access private	*/	function _tag_open( &$parser, $tag, $attributes ) {		$this->currentElement = strtoupper( $tag );				switch( $this->currentElement ) {			case 'ROW':				$this->row = count( $this->data );				$this->data[$this->row] = array();				break;			case 'F':				$this->addField($attributes);			default:				// print_r( array( $tag, $attributes ) );		}	}		/**	* XML Callback to process CDATA elements	*	* Processes XML cdata.	*	* @access private	*/	function _tag_cdata( &$parser, $cdata ) {		switch( $this->currentElement ) {			// Index field name			case 'F':				$this->addData( $cdata );				break;			default:						}	}		/**	* XML Callback to process end elements	*	* @access private	*/	function _tag_close( &$parser, $tag ) {		$this->currentElement = '';				switch( strtoupper( $tag ) ) {			case 'DATA':				xml_set_object( $parser, $this->parent );				break;		}	}		/**	* Adds a field to the insert	*	* @param string $name Field name	* @return string Field list	*/	function addField( $attributes ) {		// check we're in a valid row		if( !isset( $this->row ) || !isset( $this->data[$this->row] ) ) {			return;		}				// Set the field index so we know where we are		if( isset( $attributes['NAME'] ) ) {			$this->current_field = $this->FieldID( $attributes['NAME'] );		} else {			$this->current_field = count( $this->data[$this->row] );		}				// initialise data		if( !isset( $this->data[$this->row][$this->current_field] ) ) {			$this->data[$this->row][$this->current_field] = '';		}	}		/**	* Adds options to the index	*	* @param string $opt Comma-separated list of index options.	* @return string Option list	*/	function addData( $cdata ) {		// check we're in a valid field		if ( isset( $this->data[$this->row][$this->current_field] ) ) {			// add data to field			$this->data[$this->row][$this->current_field] .= $cdata;		}	}		/**	* Generates the SQL that will add/update the data 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);		$tables = $xmls->db->MetaTables(); 		$sql = array();				$ukeys = $xmls->db->MetaPrimaryKeys( $table );		if( !empty( $this->parent->indexes ) and !empty( $ukeys ) ) {			foreach( $this->parent->indexes as $indexObj ) {				if( !in_array( $indexObj->name, $ukeys ) ) $ukeys[] = $indexObj->name;			}		}				// eliminate any columns that aren't in the table		foreach( $this->data as $row ) {			$table_fields = $this->parent->fields;			$fields = array();			$rawfields = array(); // Need to keep some of the unprocessed data on hand.						foreach( $row as $field_id => $field_data ) {				if( !array_key_exists( $field_id, $table_fields ) ) {					if( is_numeric( $field_id ) ) {						$field_id = reset( array_keys( $table_fields ) );					} else {						continue;					}				}				

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -