Allow index creating on multiple fields (RFE #990136).
This commit is contained in:
@@ -15,6 +15,8 @@ $Source$
|
||||
libraries/display_tbl.lib.php: New function PMA_buttonOrImage to display
|
||||
button or image to submit form and not to duplicate code on all places.
|
||||
* tbl_addfield.php: Display tabs.
|
||||
* mult_submits.inc.php, tbl_properties_structure.php: Allow index creating
|
||||
on multiple fields (RFE #990136).
|
||||
|
||||
2004-10-20 Marc Delisle <lem9@users.sourceforge.net>
|
||||
* libraries/common.lib.php: there was already a tip icon in our collection,
|
||||
|
@@ -56,10 +56,50 @@ if (!empty($submit_mult)
|
||||
}
|
||||
} else if (!empty($selected_fld)) {
|
||||
$selected = $selected_fld;
|
||||
if ($submit_mult == $strDrop) {
|
||||
$what = 'drop_fld';
|
||||
} else {
|
||||
require('./tbl_alter.php');
|
||||
switch ($submit_mult) {
|
||||
case $strDrop:
|
||||
$what = 'drop_fld';
|
||||
break;
|
||||
case $strPrimary:
|
||||
// Gets table primary key
|
||||
PMA_DBI_select_db($db);
|
||||
$result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
|
||||
$primary = '';
|
||||
while ($row = PMA_DBI_fetch_assoc($result)) {
|
||||
// Backups the list of primary keys
|
||||
if ($row['Key_name'] == 'PRIMARY') {
|
||||
$primary .= $row['Column_name'] . ', ';
|
||||
}
|
||||
} // end while
|
||||
PMA_DBI_free_result($result);
|
||||
if (empty($primary)) {
|
||||
// no primary key, so we can safely create new
|
||||
unset($submit_mult);
|
||||
$query_type = 'primary_fld';
|
||||
$mult_btn = $strYes;
|
||||
} else {
|
||||
// primary key exists, so lets as user
|
||||
$what = 'primary_fld';
|
||||
}
|
||||
break;
|
||||
case $strIndex:
|
||||
unset($submit_mult);
|
||||
$query_type = 'index_fld';
|
||||
$mult_btn = $strYes;
|
||||
break;
|
||||
case $strUnique:
|
||||
unset($submit_mult);
|
||||
$query_type = 'unique_fld';
|
||||
$mult_btn = $strYes;
|
||||
break;
|
||||
case $strIdxFulltext:
|
||||
unset($submit_mult);
|
||||
$query_type = 'fulltext_fld';
|
||||
$mult_btn = $strYes;
|
||||
break;
|
||||
case $strChange:
|
||||
require('./tbl_alter.php');
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$what = 'row_delete';
|
||||
@@ -115,6 +155,25 @@ if (!empty($submit_mult) && !empty($what)) {
|
||||
. ';<br />';
|
||||
break;
|
||||
|
||||
case 'primary_fld':
|
||||
if ($full_query == '') {
|
||||
$full_query .= 'ALTER TABLE '
|
||||
. PMA_backquote(htmlspecialchars($table))
|
||||
. '<br /> DROP PRIMARY KEY,'
|
||||
. '<br /> ADD PRIMARY KEY('
|
||||
. '<br /> '
|
||||
. PMA_backquote(htmlspecialchars(urldecode($sval)))
|
||||
. ',';
|
||||
} else {
|
||||
$full_query .= '<br /> '
|
||||
. PMA_backquote(htmlspecialchars(urldecode($sval)))
|
||||
. ',';
|
||||
}
|
||||
if ($i == $selected_cnt-1) {
|
||||
$full_query = preg_replace('@,$@', ');<br />', $full_query);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'drop_fld':
|
||||
if ($full_query == '') {
|
||||
$full_query .= 'ALTER TABLE '
|
||||
@@ -203,10 +262,28 @@ else if ($mult_btn == $strYes) {
|
||||
|
||||
$sql_query = '';
|
||||
$selected_cnt = count($selected);
|
||||
$run_parts = FALSE; // whether to run query after each pass
|
||||
$use_sql = FALSE; // whether to include sql.php at the end (to display results)
|
||||
|
||||
if ($query_type == 'primary_fld') {
|
||||
// Gets table primary key
|
||||
PMA_DBI_select_db($db);
|
||||
$result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
|
||||
$primary = '';
|
||||
while ($row = PMA_DBI_fetch_assoc($result)) {
|
||||
// Backups the list of primary keys
|
||||
if ($row['Key_name'] == 'PRIMARY') {
|
||||
$primary .= $row['Column_name'] . ', ';
|
||||
}
|
||||
} // end while
|
||||
PMA_DBI_free_result($result);
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $selected_cnt; $i++) {
|
||||
switch ($query_type) {
|
||||
case 'row_delete':
|
||||
$a_query = urldecode($selected[$i]);
|
||||
$run_parts = TRUE;
|
||||
break;
|
||||
|
||||
case 'drop_db':
|
||||
@@ -214,6 +291,7 @@ else if ($mult_btn == $strYes) {
|
||||
$a_query = 'DROP DATABASE '
|
||||
. PMA_backquote(urldecode($selected[$i]));
|
||||
$reload = 1;
|
||||
$run_parts = TRUE;
|
||||
break;
|
||||
|
||||
case 'drop_tbl':
|
||||
@@ -227,21 +305,25 @@ else if ($mult_btn == $strYes) {
|
||||
case 'check_tbl':
|
||||
$sql_query .= (empty($sql_query) ? 'CHECK TABLE ' : ', ')
|
||||
. PMA_backquote(urldecode($selected[$i]));
|
||||
$use_sql = TRUE;
|
||||
break;
|
||||
|
||||
case 'optimize_tbl':
|
||||
$sql_query .= (empty($sql_query) ? 'OPTIMIZE TABLE ' : ', ')
|
||||
. PMA_backquote(urldecode($selected[$i]));
|
||||
$use_sql = TRUE;
|
||||
break;
|
||||
|
||||
case 'analyze_tbl':
|
||||
$sql_query .= (empty($sql_query) ? 'ANALYZE TABLE ' : ', ')
|
||||
. PMA_backquote(urldecode($selected[$i]));
|
||||
$use_sql = TRUE;
|
||||
break;
|
||||
|
||||
case 'repair_tbl':
|
||||
$sql_query .= (empty($sql_query) ? 'REPAIR TABLE ' : ', ')
|
||||
. PMA_backquote(urldecode($selected[$i]));
|
||||
$use_sql = TRUE;
|
||||
break;
|
||||
|
||||
case 'empty_tbl':
|
||||
@@ -251,6 +333,7 @@ else if ($mult_btn == $strYes) {
|
||||
$a_query = 'DELETE FROM ';
|
||||
}
|
||||
$a_query .= PMA_backquote(htmlspecialchars(urldecode($selected[$i])));
|
||||
$run_parts = TRUE;
|
||||
break;
|
||||
|
||||
case 'drop_fld':
|
||||
@@ -259,17 +342,35 @@ else if ($mult_btn == $strYes) {
|
||||
. ' DROP ' . PMA_backquote(urldecode($selected[$i]))
|
||||
. (($i == $selected_cnt-1) ? ';' : '');
|
||||
break;
|
||||
|
||||
case 'primary_fld':
|
||||
$sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ( empty($primary) ? '' : ' DROP PRIMARY KEY,') . ' ADD PRIMARY KEY( ' : ', ')
|
||||
. PMA_backquote(urldecode($selected[$i]))
|
||||
. (($i == $selected_cnt-1) ? ');' : '');
|
||||
break;
|
||||
|
||||
case 'index_fld':
|
||||
$sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX( ' : ', ')
|
||||
. PMA_backquote(urldecode($selected[$i]))
|
||||
. (($i == $selected_cnt-1) ? ');' : '');
|
||||
break;
|
||||
|
||||
case 'unique_fld':
|
||||
$sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE( ' : ', ')
|
||||
. PMA_backquote(urldecode($selected[$i]))
|
||||
. (($i == $selected_cnt-1) ? ');' : '');
|
||||
break;
|
||||
|
||||
case 'fulltext_fld':
|
||||
$sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT( ' : ', ')
|
||||
. PMA_backquote(urldecode($selected[$i]))
|
||||
. (($i == $selected_cnt-1) ? ');' : '');
|
||||
break;
|
||||
} // end switch
|
||||
|
||||
// All "DROP TABLE","DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE"
|
||||
// statements will be run at once below
|
||||
if ($query_type != 'drop_tbl'
|
||||
&& $query_type != 'drop_fld'
|
||||
&& $query_type != 'repair_tbl'
|
||||
&& $query_type != 'analyze_tbl'
|
||||
&& $query_type != 'optimize_tbl'
|
||||
&& $query_type != 'check_tbl') {
|
||||
|
||||
if ($run_parts) {
|
||||
$sql_query .= $a_query . ';' . "\n";
|
||||
|
||||
if ($query_type != 'drop_db') {
|
||||
@@ -279,15 +380,11 @@ else if ($mult_btn == $strYes) {
|
||||
} // end if
|
||||
} // end for
|
||||
|
||||
if ($query_type == 'drop_tbl'
|
||||
|| $query_type == 'drop_fld') {
|
||||
if ($use_sql) {
|
||||
require('./sql.php');
|
||||
} else {
|
||||
PMA_DBI_select_db($db);
|
||||
$result = PMA_DBI_query($sql_query);
|
||||
} elseif ($query_type == 'repair_tbl'
|
||||
|| $query_type == 'analyze_tbl'
|
||||
|| $query_type == 'check_tbl'
|
||||
|| $query_type == 'optimize_tbl') {
|
||||
require('./sql.php');
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -13,9 +13,16 @@ require_once('./libraries/mysql_charsets.lib.php');
|
||||
// workaround for IE problem:
|
||||
if (isset($submit_mult_change_x)) {
|
||||
$submit_mult = $strChange;
|
||||
}
|
||||
if (isset($submit_mult_drop_x)) {
|
||||
} elseif (isset($submit_mult_drop_x)) {
|
||||
$submit_mult = $strDrop;
|
||||
} elseif (isset($submit_mult_primary_x)) {
|
||||
$submit_mult = $strPrimary;
|
||||
} elseif (isset($submit_mult_index_x)) {
|
||||
$submit_mult = $strIndex;
|
||||
} elseif (isset($submit_mult_unique_x)) {
|
||||
$submit_mult = $strUnique;
|
||||
} elseif (isset($submit_mult_fulltext_x)) {
|
||||
$submit_mult = $strIdxFulltext;
|
||||
}
|
||||
|
||||
if ((!empty($submit_mult) && isset($selected_fld))
|
||||
@@ -411,24 +418,34 @@ $checkall_url = 'tbl_properties_structure.php?' . PMA_generate_common_url($db,$t
|
||||
<td>
|
||||
<?php
|
||||
|
||||
/*
|
||||
$titles['Primary'] = $iconic_spacer . '<img hspace="2" width="16" height="16" src="' . $pmaThemeImage . 'b_primary.png" alt="' . $strPrimary . '" title="' . $strPrimary . '" border="0" />';
|
||||
$titles['Index'] = $iconic_spacer . '<img hspace="2" width="16" height="16" src="' . $pmaThemeImage . 'b_index.png" alt="' . $strIndex . '" title="' . $strIndex . '" border="0" />';
|
||||
$titles['Unique'] = $iconic_spacer . '<img hspace="2" width="16" height="16" src="' . $pmaThemeImage . 'b_unique.png" alt="' . $strUnique . '" title="' . $strUnique . '" border="0" />';
|
||||
$titles['IdxFulltext'] = $iconic_spacer . '<img hspace="2" width="16" height="16" src="' . $pmaThemeImage . 'b_ftext.png" alt="' . $strIdxFulltext . '" title="' . $strIdxFulltext . '" border="0" />';
|
||||
*/
|
||||
if ($cfg['PropertiesIconic']) {
|
||||
PMA_buttonOrImage('submit_mult', 'mult_submit', 'submin_mult_change', $strChange, 'b_edit.png');
|
||||
// Drop button if there is at least two fields
|
||||
if ($fields_cnt > 1) {
|
||||
PMA_buttonOrImage('submit_mult', 'mult_submit', 'submin_mult_drop', $strDrop, 'b_drop.png');
|
||||
}
|
||||
PMA_buttonOrImage('submit_mult', 'mult_submit', 'submin_mult_primary', $strPrimary, 'b_primary.png');
|
||||
PMA_buttonOrImage('submit_mult', 'mult_submit', 'submin_mult_index', $strIndex, 'b_index.png');
|
||||
PMA_buttonOrImage('submit_mult', 'mult_submit', 'submin_mult_unique', $strUnique, 'b_unique.png');
|
||||
if ((!empty($tbl_type) && $tbl_type == 'MYISAM')) {
|
||||
PMA_buttonOrImage('submit_mult', 'mult_submit', 'submin_mult_fulltext', $strIdxFulltext, 'b_ftext.png');
|
||||
}
|
||||
} else {
|
||||
echo ' <input type="submit" name="submit_mult" value="' . $strChange . '" title="' . $strChange . '" />' . "\n";
|
||||
echo '<input type="submit" name="submit_mult" value="' . $strChange . '" title="' . $strChange . '" />' . "\n";
|
||||
// Drop button if there is at least two fields
|
||||
if ($fields_cnt > 1) {
|
||||
echo ' <i>' . $strOr . '</i> ' . "\n"
|
||||
. ' <input type="submit" name="submit_mult" value="' . $strDrop . '" title="' . $strDrop . '" />' . "\n";
|
||||
echo ' <i>' . $strOr . '</i> ' . "\n"
|
||||
. '<input type="submit" name="submit_mult" value="' . $strDrop . '" title="' . $strDrop . '" />' . "\n";
|
||||
}
|
||||
echo ' <i>' . $strOr . '</i> ' . "\n"
|
||||
. '<input type="submit" name="submit_mult" value="' . $strPrimary . '" title="' . $strPrimary . '" />' . "\n";
|
||||
echo ' <i>' . $strOr . '</i> ' . "\n"
|
||||
. '<input type="submit" name="submit_mult" value="' . $strIndex . '" title="' . $strIndex . '" />' . "\n";
|
||||
echo ' <i>' . $strOr . '</i> ' . "\n"
|
||||
. '<input type="submit" name="submit_mult" value="' . $strUnique . '" title="' . $strUnique . '" />' . "\n";
|
||||
if ((!empty($tbl_type) && $tbl_type == 'MYISAM')) {
|
||||
echo ' <i>' . $strOr . '</i> ' . "\n"
|
||||
. '<input type="submit" name="submit_mult" value="' . $strIdxFulltext . '" title="' . $strIdxFulltext . '" />' . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user