moved PMA_generateFieldSpec() into PMA_Table
This commit is contained in:
@@ -11,6 +11,8 @@ $Source$
|
||||
* libraries/Table.class.php: *NEW* class PMA_Table
|
||||
* tbl_addfield.php, tbl_create.php:
|
||||
use Table.class.php
|
||||
* libraries/common.lib.php:
|
||||
moved PMA_generateFieldSpec() into PMA_Table
|
||||
|
||||
2006-02-20 Marc Delisle <lem9@users.sourceforge.net>
|
||||
### 2.8.0-rc1 released
|
||||
|
@@ -2505,75 +2505,6 @@ window.parent.updateTableTitle('<?php echo $uni_tbl; ?>', '<?php echo PMA_jsForm
|
||||
return $gotopage;
|
||||
} // end function
|
||||
|
||||
/**
|
||||
* @TODO add documentation
|
||||
*/
|
||||
function PMA_generateFieldSpec($name, $type, $length, $attribute,
|
||||
$collation, $null, $default, $default_current_timestamp, $extra,
|
||||
$comment='', &$field_primary, $index, $default_orig = false)
|
||||
{
|
||||
|
||||
// $default_current_timestamp has priority over $default
|
||||
// TODO: on the interface, some js to clear the default value
|
||||
// when the default current_timestamp is checked
|
||||
|
||||
$query = PMA_backquote($name) . ' ' . $type;
|
||||
|
||||
if ($length != ''
|
||||
&& !preg_match('@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT)$@i', $type)) {
|
||||
$query .= '(' . $length . ')';
|
||||
}
|
||||
|
||||
if ($attribute != '') {
|
||||
$query .= ' ' . $attribute;
|
||||
}
|
||||
|
||||
if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($collation)
|
||||
&& $collation != 'NULL'
|
||||
&& preg_match('@^(TINYTEXT|TEXT|MEDIUMTEXT|LONGTEXT|VARCHAR|CHAR|ENUM|SET)$@i', $type)) {
|
||||
$query .= PMA_generateCharsetQueryPart($collation);
|
||||
}
|
||||
|
||||
if (!($null === false)) {
|
||||
if (!empty($null)) {
|
||||
$query .= ' NOT NULL';
|
||||
} else {
|
||||
$query .= ' NULL';
|
||||
}
|
||||
}
|
||||
|
||||
if ($default_current_timestamp && strpos(' ' . strtoupper($type), 'TIMESTAMP') == 1) {
|
||||
$query .= ' DEFAULT CURRENT_TIMESTAMP';
|
||||
// 0 is empty in PHP
|
||||
// auto_increment field cannot have a default value
|
||||
} elseif ($extra !== 'AUTO_INCREMENT' && (!empty($default) || $default == '0' || $default != $default_orig)) {
|
||||
if (strtoupper($default) == 'NULL') {
|
||||
$query .= ' DEFAULT NULL';
|
||||
} else {
|
||||
$query .= ' DEFAULT \'' . PMA_sqlAddslashes($default) . '\'';
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($extra)) {
|
||||
$query .= ' ' . $extra;
|
||||
// An auto_increment field must be use as a primary key
|
||||
if ($extra == 'AUTO_INCREMENT' && isset($field_primary)) {
|
||||
$primary_cnt = count($field_primary);
|
||||
for ($j = 0; $j < $primary_cnt && $field_primary[$j] != $index; $j++) {
|
||||
// void
|
||||
} // end for
|
||||
if (isset($field_primary[$j]) && $field_primary[$j] == $index) {
|
||||
$query .= ' PRIMARY KEY';
|
||||
unset($field_primary[$j]);
|
||||
} // end if
|
||||
} // end if (auto_increment)
|
||||
}
|
||||
if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($comment)) {
|
||||
$query .= " COMMENT '" . PMA_sqlAddslashes($comment) . "'";
|
||||
}
|
||||
return $query;
|
||||
} // end function
|
||||
|
||||
/**
|
||||
* @TODO add documentation
|
||||
*/
|
||||
|
Reference in New Issue
Block a user