view_table_php.class.php
来自「很棒的在线教学系统」· PHP 代码 · 共 1,064 行 · 第 1/3 页
PHP
1,064 行
* @param string table table name * @param string field field name to be dropped * @return string PHP code to be used to drop the field */ function drop_field_php($structure, $table, $field) { $result = ''; /// Validate if we can do it if (!$table = $structure->getTable($table)) { return false; } if (!$field = $table->getField($field)) { return false; } if ($table->getAllErrors()) { return false; } /// Add the standard PHP header $result .= XMLDB_PHP_HEADER; /// Add contents $result .= XMLDB_LINEFEED; $result .= ' /// Define field ' . $field->getName() . ' to be dropped from ' . $table->getName() . XMLDB_LINEFEED; $result .= ' $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= ' $field = new XMLDBField(' . "'" . $field->getName() . "'" . ');' . XMLDB_LINEFEED; /// Launch the proper DDL $result .= XMLDB_LINEFEED; $result .= ' /// Launch drop field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && drop_field($table, $field);' . XMLDB_LINEFEED; /// Add the proper upgrade_xxxx_savepoint call $result .= $this->upgrade_savepoint_php ($structure); /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; return $result; } /** * This function will generate all the PHP code needed to * rename one field using XMLDB objects and functions * * @param XMLDBStructure structure object containing all the info * @param string table table name * @param string field field name to be renamed * @return string PHP code to be used to rename the field */ function rename_field_php($structure, $table, $field) { $result = ''; /// Validate if we can do it if (!$table = $structure->getTable($table)) { return false; } if (!$field = $table->getField($field)) { return false; } if ($table->getAllErrors()) { return false; } /// Add the standard PHP header $result .= XMLDB_PHP_HEADER; /// Add contents $result .= XMLDB_LINEFEED; $result .= ' /// Rename field ' . $field->getName() . ' on table ' . $table->getName() . ' to NEWNAMEGOESHERE'. XMLDB_LINEFEED; $result .= ' $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= ' $field = new XMLDBField(' . "'" . $field->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= ' $field->setAttributes(' . $field->getPHP(true) . ');' . XMLDB_LINEFEED; /// Launch the proper DDL $result .= XMLDB_LINEFEED; $result .= ' /// Launch rename field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && rename_field($table, $field, ' . "'" . 'NEWNAMEGOESHERE' . "'" . ');' . XMLDB_LINEFEED; /// Add the proper upgrade_xxxx_savepoint call $result .= $this->upgrade_savepoint_php ($structure); /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; return $result; } /** * This function will generate all the PHP code needed to * change the type of one field using XMLDB objects and functions. * Currently these conversions are supported: * integer to char * char to integer * number to char * char to number * float to char * char to float * * @param XMLDBStructure structure object containing all the info * @param string table table name * @param string field field name to change precision */ function change_field_type_php($structure, $table, $field) { $result = ''; /// Validate if we can do it if (!$table = $structure->getTable($table)) { return false; } if (!$field = $table->getField($field)) { return false; } if ($table->getAllErrors()) { return false; } /// Calculate the type tip text $type = $field->getXMLDBTypeName($field->getType()); /// Add the standard PHP header $result .= XMLDB_PHP_HEADER; /// Add contents $result .= XMLDB_LINEFEED; $result .= ' /// Changing type of field ' . $field->getName() . ' on table ' . $table->getName() . ' to ' . $type . XMLDB_LINEFEED; $result .= ' $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= ' $field = new XMLDBField(' . "'" . $field->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= ' $field->setAttributes(' . $field->getPHP(true) . ');' . XMLDB_LINEFEED; /// Launch the proper DDL $result .= XMLDB_LINEFEED; $result .= ' /// Launch change of type for field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && change_field_type($table, $field);' . XMLDB_LINEFEED; /// Add the proper upgrade_xxxx_savepoint call $result .= $this->upgrade_savepoint_php ($structure); /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; return $result; } /** * This function will generate all the PHP code needed to * change the precision of one field using XMLDB objects and functions * * @param XMLDBStructure structure object containing all the info * @param string table table name * @param string field field name to change precision */ function change_field_precision_php($structure, $table, $field) { $result = ''; /// Validate if we can do it if (!$table = $structure->getTable($table)) { return false; } if (!$field = $table->getField($field)) { return false; } if ($table->getAllErrors()) { return false; } /// Calculate the precision tip text $precision = '(' . $field->getLength(); if ($field->getDecimals()) { $precision .= ', ' . $field->getDecimals(); } $precision .= ')'; /// Add the standard PHP header $result .= XMLDB_PHP_HEADER; /// Add contents $result .= XMLDB_LINEFEED; $result .= ' /// Changing precision of field ' . $field->getName() . ' on table ' . $table->getName() . ' to ' . $precision . XMLDB_LINEFEED; $result .= ' $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= ' $field = new XMLDBField(' . "'" . $field->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= ' $field->setAttributes(' . $field->getPHP(true) . ');' . XMLDB_LINEFEED; /// Launch the proper DDL $result .= XMLDB_LINEFEED; $result .= ' /// Launch change of precision for field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && change_field_precision($table, $field);' . XMLDB_LINEFEED; /// Add the proper upgrade_xxxx_savepoint call $result .= $this->upgrade_savepoint_php ($structure); /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; return $result; } /** * This function will generate all the PHP code needed to * change the unsigned/signed of one field using XMLDB objects and functions * * @param XMLDBStructure structure object containing all the info * @param string table table name * @param string field field name to change unsigned/signed */ function change_field_unsigned_php($structure, $table, $field) { $result = ''; /// Validate if we can do it if (!$table = $structure->getTable($table)) { return false; } if (!$field = $table->getField($field)) { return false; } if ($table->getAllErrors()) { return false; } /// Calculate the unsigned tip text $unsigned = $field->getUnsigned() ? 'unsigned' : 'signed'; /// Add the standard PHP header $result .= XMLDB_PHP_HEADER; /// Add contents $result .= XMLDB_LINEFEED; $result .= ' /// Changing sign of field ' . $field->getName() . ' on table ' . $table->getName() . ' to ' . $unsigned . XMLDB_LINEFEED; $result .= ' $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= ' $field = new XMLDBField(' . "'" . $field->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= ' $field->setAttributes(' . $field->getPHP(true) . ');' . XMLDB_LINEFEED; /// Launch the proper DDL $result .= XMLDB_LINEFEED; $result .= ' /// Launch change of sign for field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && change_field_unsigned($table, $field);' . XMLDB_LINEFEED; /// Add the proper upgrade_xxxx_savepoint call $result .= $this->upgrade_savepoint_php ($structure); /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; return $result; } /** * This function will generate all the PHP code needed to * change the nullability of one field using XMLDB objects and functions * * @param XMLDBStructure structure object containing all the info * @param string table table name * @param string field field name to change null/not null */ function change_field_notnull_php($structure, $table, $field) { $result = ''; /// Validate if we can do it if (!$table = $structure->getTable($table)) { return false; } if (!$field = $table->getField($field)) { return false; } if ($table->getAllErrors()) { return false; } /// Calculate the notnull tip text $notnull = $field->getNotnull() ? 'not null' : 'null'; /// Add the standard PHP header $result .= XMLDB_PHP_HEADER; /// Add contents $result .= XMLDB_LINEFEED; $result .= ' /// Changing nullability of field ' . $field->getName() . ' on table ' . $table->getName() . ' to ' . $notnull . XMLDB_LINEFEED; $result .= ' $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= ' $field = new XMLDBField(' . "'" . $field->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= ' $field->setAttributes(' . $field->getPHP(true) . ');' . XMLDB_LINEFEED; /// Launch the proper DDL $result .= XMLDB_LINEFEED; $result .= ' /// Launch change of nullability for field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && change_field_notnull($table, $field);' . XMLDB_LINEFEED; /// Add the proper upgrade_xxxx_savepoint call $result .= $this->upgrade_savepoint_php ($structure); /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; return $result; } /** * This function will generate all the PHP code needed to * change the enum values (check constraint) of one field * using XMLDB objects and functions * * @param XMLDBStructure structure object containing all the info * @param string table table name * @param string field field name to change its enum */ function change_field_enum_php($structure, $table, $field) { $result = ''; /// Validate if we can do it if (!$table = $structure->getTable($table)) { return false; } if (!$field = $table->getField($field)) { return false; } if ($table->getAllErrors()) { return false; } /// Calculate the enum tip text $enum = $field->getEnum() ? implode(', ', $field->getEnumValues()) : 'none'; /// Add the standard PHP header $result .= XMLDB_PHP_HEADER; /// Add contents $result .= XMLDB_LINEFEED; $result .= ' /// Changing list of values (enum) of field ' . $field->getName() . ' on table ' . $table->getName() . ' to ' . $enum . XMLDB_LINEFEED; $result .= ' $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= ' $field = new XMLDBField(' . "'" . $field->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= ' $field->setAttributes(' . $field->getPHP(true) . ');' . XMLDB_LINEFEED; /// Launch the proper DDL $result .= XMLDB_LINEFEED; $result .= ' /// Launch change of list of values for field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && change_field_enum($table, $field);' . XMLDB_LINEFEED; /// Add the proper upgrade_xxxx_savepoint call $result .= $this->upgrade_savepoint_php ($structure); /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; return $result; } /** * This function will generate all the PHP code needed to * change the default of one field using XMLDB objects and functions * * @param XMLDBStructure structure object containing all the info * @param string table table name * @param string field field name to change null/not null */ function change_field_default_php($structure, $table, $field) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?