diff options
author | Marc Delisle <marc@infomarc.info> | 2005-04-01 01:54:36 +0400 |
---|---|---|
committer | Marc Delisle <marc@infomarc.info> | 2005-04-01 01:54:36 +0400 |
commit | 8ddcb6d302cd67140953fde166378240af2600e3 (patch) | |
tree | ce1b8088faf3251af9a9b79b03c9d59f27981fe6 | |
parent | 50b8a67ba4c4b53e809a0c75fe5949034d9ffe53 (diff) |
create table and TIMESTAMP options
-rwxr-xr-x | ChangeLog | 6 | ||||
-rw-r--r-- | libraries/relation.lib.php | 33 | ||||
-rw-r--r-- | tbl_alter.php | 1 | ||||
-rw-r--r-- | tbl_create.php | 7 |
4 files changed, 42 insertions, 5 deletions
@@ -10,9 +10,9 @@ $Source$ Firefox when the Tabbrowser Extensions plugin is installed * tbl_properties.inc.php: TIMESTAMP options improved looks, thanks to Garvin * tbl_properties.inc.php: TIMESTAMP default CURRENT_TIMESTAMP checkbox - made dynamic, depending on the field's type. - TODO: (work in progress) support those options in tbl_create and - tbl_addfield + made dynamic, depending on the field's type + * tbl_create.php, libraries/relation.lib.php: TIMESTAMP options support + TODO: (work in progress) support those options in tbl_addfield 2005-03-30 Alexander M. Turek <me@derrabus.de> * server_databases.php: Bug #1172782 (Don't allow to drop diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index 0c49ed3572..42138b6e62 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -561,6 +561,26 @@ function PMA_setComment($db, $table, $col, $comment, $removekey = '', $mode='aut // native mode is only for column comments so we need a table name if ($mode == 'native' && !empty($table)) { $fields = PMA_DBI_get_fields($db, $table); + + + // Get more complete field information + // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options + // but later, if the analyser returns more information, it + // could be executed for any MySQL version and replace + // the info given by SHOW FULL FIELDS FROM. + // TODO: put this code into a require() + // or maybe make it part of PMA_DBI_get_fields(); + + if (PMA_MYSQL_INT_VERSION >= 40102) { + $show_create_table_query = 'SHOW CREATE TABLE ' + . PMA_backquote($db) . '.' . PMA_backquote($table); + $show_create_table_res = PMA_DBI_query($show_create_table_query); + list(,$show_create_table) = PMA_DBI_fetch_row($show_create_table_res); + PMA_DBI_free_result($show_create_table_res); + unset($show_create_table_res, $show_create_table_query); + $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table)); + } + // TODO: get directly the information of $col foreach($fields as $key=>$field) { $tmp_col = $field['Field']; @@ -569,6 +589,17 @@ function PMA_setComment($db, $table, $col, $comment, $removekey = '', $mode='aut $nulls[$tmp_col] = $field['Null']; $defaults[$tmp_col] = $field['Default']; $extras[$tmp_col] = $field['Extra']; + + if (PMA_MYSQL_INT_VERSION >= 40102 && isset($analyzed_sql[0]['create_table_fields'][$tmp_col]['on_update_current_timestamp'])) { + $extras[$tmp_col] = 'ON UPDATE CURRENT_TIMESTAMP'; + } + + if (PMA_MYSQL_INT_VERSION >= 40102 && isset($analyzed_sql[0]['create_table_fields'][$tmp_col]['default_current_timestamp'])) { + $default_current_timestamps[$tmp_col] = TRUE; + } else { + $default_current_timestamps[$tmp_col] = FALSE; + } + if ($tmp_col == $col) { break; } @@ -580,7 +611,7 @@ function PMA_setComment($db, $table, $col, $comment, $removekey = '', $mode='aut } $query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' - . PMA_generateAlterTable($col, $col, $types[$col], $collations[$col], $nulls[$col], $defaults[$col], $extras[$col], $comment); + . PMA_generateAlterTable($col, $col, $types[$col], $collations[$col], $nulls[$col], $defaults[$col], $default_current_timestamps[$col], $extras[$col], $comment); PMA_DBI_try_query($query, NULL, PMA_DBI_QUERY_STORE); return TRUE; diff --git a/tbl_alter.php b/tbl_alter.php index 22dafd2c97..7dc3776212 100644 --- a/tbl_alter.php +++ b/tbl_alter.php @@ -187,6 +187,7 @@ if ($abort == FALSE) { // could be executed for any MySQL version and replace // the info given by SHOW FULL FIELDS FROM. // TODO: put this code into a require() + // or maybe make it part of PMA_DBI_get_fields(); if (PMA_MYSQL_INT_VERSION >= 40102) { $show_create_table_query = 'SHOW CREATE TABLE ' diff --git a/tbl_create.php b/tbl_create.php index 1832368429..deb88ac9a0 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -58,6 +58,9 @@ if (isset($submit_num_fields)) { if (empty($field_name[$i]) && $field_name[$i] != '0') { continue; } + // TODO: maybe move this logic and the one of PMA_generateAlterTable() + // to a central place + $query = PMA_backquote($field_name[$i]) . ' ' . $field_type[$i]; if ($field_length[$i] != '' && !preg_match('@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT)$@i', $field_type[$i])) { @@ -68,7 +71,9 @@ if (isset($submit_num_fields)) { } else if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($field_collation[$i])) { $query .= PMA_generateCharsetQueryPart($field_collation[$i]); } - if ($field_default[$i] != '') { + if (isset($field_default_current_timestamp[$i]) && $field_default_current_timestamp[$i]) { + $query .= ' DEFAULT CURRENT_TIMESTAMP'; + } elseif ($field_default[$i] != '') { if (strtoupper($field_default[$i]) == 'NULL') { $query .= ' DEFAULT NULL'; } else { |