Skip to content

Commit

Permalink
adding support for some more options
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Sep 23, 2006
1 parent 8e895ae commit 1934b52
Showing 1 changed file with 208 additions and 1 deletion.
209 changes: 208 additions & 1 deletion admin/xmldb/actions/view_table_php/view_table_php.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@ function invoke() {
/// Calculate the popup of commands
$commands = array('add_field',
'drop_field',
'rename_field');
'rename_field (not imp!)',
'change_field_type (not imp!)',
'change_field_precision',
'change_field_unsigned',
'change_field_notnull',
'change_field_sequence (not imp!)',
'change_field_enum (not imp!)',
'change_field_default');
foreach ($commands as $command) {
$popcommands[$command] = str_replace('_', ' ', $command);
}
Expand Down Expand Up @@ -163,6 +170,18 @@ function invoke() {
case 'rename_field':
$o.= s($this->rename_field_php($structure, $tableparam, $fieldkeyindexparam));
break;
case 'change_field_precision':
$o.= s($this->change_field_precision_php($structure, $tableparam, $fieldkeyindexparam));
break;
case 'change_field_unsigned':
$o.= s($this->change_field_unsigned_php($structure, $tableparam, $fieldkeyindexparam));
break;
case 'change_field_notnull':
$o.= s($this->change_field_notnull_php($structure, $tableparam, $fieldkeyindexparam));
break;
case 'change_field_default':
$o.= s($this->change_field_default_php($structure, $tableparam, $fieldkeyindexparam));
break;
}
}
$o.= '</textarea></td></tr>';
Expand Down Expand Up @@ -309,5 +328,193 @@ function rename_field_php($structure, $table, $field) {
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 .= ' $status = $status && change_field_precision($table, $field);' . XMLDB_LINEFEED;

/// 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 .= ' $status = $status && change_field_unsigned($table, $field);' . XMLDB_LINEFEED;

/// 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 .= ' $status = $status && change_field_notnull($table, $field);' . XMLDB_LINEFEED;

/// 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) {

$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 default tip text
$default = $field->getDefault() === null ? 'drop it' : $field->getDefault();

/// Add the standard PHP header
$result .= XMLDB_PHP_HEADER;

/// Add contents
$result .= XMLDB_LINEFEED;
$result .= ' /// Changing the default of field ' . $field->getName() . ' on table ' . $table->getName() . ' to ' . $default . 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 default for field ' . $field->getName() . XMLDB_LINEFEED;
$result .= ' $status = $status && change_field_default($table, $field);' . XMLDB_LINEFEED;

/// Add standard PHP footer
$result .= XMLDB_PHP_FOOTER;

return $result;
}

}
?>

0 comments on commit 1934b52

Please sign in to comment.