Merge remote-tracking branch 'origin/master'

This commit is contained in:
Michal Čihař 2012-05-29 16:52:10 +02:00
commit 70c5c825c6

View File

@ -26,10 +26,11 @@ if (! defined('PHPMYADMIN')) {
* @return nothing
*/
function PMA_getMatchingTables($trg_tables, $src_tables, &$matching_tables,
&$uncommon_source_tables) {
for ($k=0; $k< sizeof($src_tables); $k++) {
&$uncommon_source_tables
) {
for ($k=0; $k< count($src_tables); $k++) {
$present_in_target = false;
for ($l=0; $l < sizeof($trg_tables); $l++) {
for ($l=0; $l < count($trg_tables); $l++) {
if ($src_tables[$k] === $trg_tables[$l]) {
$present_in_target = true;
$matching_tables[] = $src_tables[$k];
@ -54,10 +55,11 @@ function PMA_getMatchingTables($trg_tables, $src_tables, &$matching_tables,
* @return nothing
*/
function PMA_getNonMatchingTargetTables($trg_tables, $matching_tables,
&$uncommon_target_tables) {
for ($c=0; $c<sizeof($trg_tables); $c++) {
&$uncommon_target_tables
) {
for ($c=0; $c<count($trg_tables); $c++) {
$match = false;
for ($d=0; $d < sizeof($matching_tables); $d++) {
for ($d=0; $d < count($matching_tables); $d++) {
if ($trg_tables[$c] === $matching_tables[$d]) {
$match=true;
}
@ -123,13 +125,13 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link,
}
}
$matching_tables_fields[$matching_table_index] = $fld;
$fields_num[$matching_table_index] = sizeof($fld);
$fields_num[$matching_table_index] = count($fld);
$matching_tables_keys[$matching_table_index] = $is_key;
$source_result_set = PMA_getColumnValues(
$src_db, $matching_table[$matching_table_index], $is_key, $src_link
);
$source_size = sizeof($source_result_set);
$source_size = count($source_result_set);
$trg_fld_results = PMA_DBI_get_columns(
$trg_db, $matching_table[$matching_table_index], null, true, $trg_link
@ -158,57 +160,72 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link,
// Query the target server to see which rows already exist
$trg_select_query = "SELECT * FROM " . PMA_backquote($trg_db) . "."
. PMA_backquote($matching_table[$matching_table_index]) . " WHERE ";
. PMA_backquote($matching_table[$matching_table_index])
. " WHERE ";
if (sizeof($is_key) == 1) {
$trg_select_query .= PMA_backquote($is_key[0]). "='" . $source_result_set[$j] . "'";
} elseif (sizeof($is_key) > 1) {
for ($k=0; $k < sizeof($is_key); $k++) {
if (count($is_key) == 1) {
$trg_select_query .= PMA_backquote($is_key[0])
. "='" . $source_result_set[$j] . "'";
} elseif (count($is_key) > 1) {
for ($k=0; $k < count($is_key); $k++) {
$trg_select_query .= PMA_backquote($is_key[$k])
. "='" . $source_result_set[$j][$is_key[$k]] . "'";
if ($k < (sizeof($is_key)-1)) {
if ($k < (count($is_key)-1)) {
$trg_select_query .= " AND ";
}
}
}
$target_result_set = PMA_DBI_fetch_result($trg_select_query, null, null, $trg_link);
$target_result_set = PMA_DBI_fetch_result(
$trg_select_query,
null,
null,
$trg_link
);
if ($target_result_set) {
// Fetch the row from the source server to do a comparison
$src_select_query = "SELECT * FROM " . PMA_backquote($src_db) . "."
. PMA_backquote($matching_table[$matching_table_index]) . " WHERE ";
$src_select_query = "SELECT * FROM "
. PMA_backquote($src_db) . "."
. PMA_backquote($matching_table[$matching_table_index])
. " WHERE ";
if (sizeof($is_key) == 1) {
if (count($is_key) == 1) {
$src_select_query .= PMA_backquote($is_key[0])
. "='" . $source_result_set[$j] . "'";
} elseif (sizeof($is_key) > 1) {
for ($k=0; $k< sizeof($is_key); $k++) {
} elseif (count($is_key) > 1) {
for ($k=0; $k< count($is_key); $k++) {
$src_select_query .= PMA_backquote($is_key[$k])
. "='" . $source_result_set[$j][$is_key[$k]] . "'";
if ($k < (sizeof($is_key) - 1)) {
if ($k < (count($is_key) - 1)) {
$src_select_query .= " AND ";
}
}
}
$src_result_set = PMA_DBI_fetch_result($src_select_query, null, null, $src_link);
$src_result_set = PMA_DBI_fetch_result(
$src_select_query,
null,
null,
$src_link
);
/**
* Comparing each corresponding field of the source and target matching rows.
* Placing the primary key, value of primary key, field to be updated, and the
* new value of field to be updated in each row of the update array.
* Comparing each corresponding field of the source and target
* matching rows. Placing the primary key, value of primary
* key, field to be updated, and the new value of field to
* be updated in each row of the update array.
*/
for ($m = 0; ($m < $fields_num[$matching_table_index]) && ($starting_index == 0) ; $m++) {
if (isset($src_result_set[0][$fld[$m]])) {
if (isset($target_result_set[0][$fld[$m]])) {
if (($src_result_set[0][$fld[$m]] != $target_result_set[0][$fld[$m]]) && (! (in_array($fld[$m], $is_key)))) {
if (sizeof($is_key) == 1) {
if (count($is_key) == 1) {
if ($source_result_set[$j]) {
$update_array[$matching_table_index][$update_row][$is_key[0]] = $source_result_set[$j];
}
} elseif (sizeof($is_key) > 1) {
for ($n=0; $n < sizeof($is_key); $n++) {
} elseif (count($is_key) > 1) {
for ($n=0; $n < count($is_key); $n++) {
if (isset($src_result_set[0][$is_key[$n]])) {
$update_array[$matching_table_index][$update_row][$is_key[$n]] = $src_result_set[0][$is_key[$n]];
}
@ -226,12 +243,12 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link,
$update_row++;
}
} else {
if (sizeof($is_key) == 1) {
if (count($is_key) == 1) {
if ($source_result_set[$j]) {
$update_array[$matching_table_index][$update_row][$is_key[0]] = $source_result_set[$j];
}
} elseif (sizeof($is_key) > 1) {
for ($n = 0; $n < sizeof($is_key); $n++) {
} elseif (count($is_key) > 1) {
for ($n = 0; $n < count($is_key); $n++) {
if (isset($src_result_set[0][$is_key[$n]])) {
$update_array[$matching_table_index][$update_row][$is_key[$n]] = $src_result_set[0][$is_key[$n]];
}
@ -277,14 +294,15 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link,
}
} else {
/**
* Placing the primary key, and the value of primary key of the row that is to be inserted in the target table
* Placing the primary key, and the value of primary key of the
* row that is to be inserted in the target table
*/
if (sizeof($is_key) == 1) {
if (count($is_key) == 1) {
if (isset($source_result_set[$j])) {
$insert_array[$matching_table_index][$insert_row][$is_key[0]] = $source_result_set[$j];
}
} elseif (sizeof($is_key) > 1) {
for ($l = 0; $l < sizeof($is_key); $l++) {
} elseif (count($is_key) > 1) {
for ($l = 0; $l < count($is_key); $l++) {
if (isset($source_result_set[$j][$matching_tables_fields[$matching_table_index][$l]])) {
$insert_array[$matching_table_index][$insert_row][$is_key[$l]] = $source_result_set[$j][$matching_tables_fields[$matching_table_index][$l]];
}
@ -294,15 +312,17 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link,
}
} else {
/**
* Placing the primary key, and the value of primary key of the row that is to be inserted in the target table
* This condition is met when there is an additional column in the source table
* Placing the primary key, and the value of primary key of the
* row that is to be inserted in the target table. This
* condition is met when there is an additional column in the
* source table
*/
if (sizeof($is_key) == 1) {
if (count($is_key) == 1) {
if (isset($source_result_set[$j])) {
$insert_array[$matching_table_index][$insert_row][$is_key[0]] = $source_result_set[$j];
}
} elseif (sizeof($is_key) > 1) {
for ($l = 0; $l < sizeof($is_key); $l++) {
} elseif (count($is_key) > 1) {
for ($l = 0; $l < count($is_key); $l++) {
if (isset($source_result_set[$j][$matching_tables_fields[$matching_table_index][$l]])) {
$insert_array[$matching_table_index][$insert_row][$is_key[$l]] = $source_result_set[$j][$matching_tables_fields[$matching_table_index][$l]];
}
@ -339,7 +359,7 @@ function PMA_findDeleteRowsFromTargetTables(&$delete_array, $matching_table,
$source_key_values = PMA_getColumnValues($src_db, $matching_table[$matching_table_index], $src_keys[$matching_table_index], $src_link);
}
$all_keys_match = 1;
for ($a = 0; $a < sizeof($trg_keys[$matching_table_index]); $a++) {
for ($a = 0; $a < count($trg_keys[$matching_table_index]); $a++) {
if (isset($trg_keys[$matching_table_index][$a])) {
if (! (in_array($trg_keys[$matching_table_index][$a], $src_keys[$matching_table_index]))) {
$all_keys_match = 0;
@ -352,24 +372,24 @@ function PMA_findDeleteRowsFromTargetTables(&$delete_array, $matching_table,
}
}
if (isset($trg_keys[$matching_table_index])) {
if ((sizeof($trg_keys[$matching_table_index]) == 1) && $all_keys_match) {
if ((count($trg_keys[$matching_table_index]) == 1) && $all_keys_match) {
$row = 0;
if (isset($target_key_values)) {
for ($i = 0; $i < sizeof($target_key_values); $i++) {
for ($i = 0; $i < count($target_key_values); $i++) {
if (! (in_array($target_key_values[$i], $source_key_values))) {
$delete_array[$matching_table_index][$row] = $target_key_values[$i];
$row++;
}
}
}
} elseif ((sizeof($trg_keys[$matching_table_index]) > 1) && $all_keys_match) {
} elseif ((count($trg_keys[$matching_table_index]) > 1) && $all_keys_match) {
$row = 0;
if (isset($target_key_values)) {
for ($i = 0; $i < sizeof($target_key_values); $i++) {
for ($i = 0; $i < count($target_key_values); $i++) {
$is_present = false;
for ($j = 0; $j < sizeof($source_key_values) && ($is_present == false) ; $j++) {
for ($j = 0; $j < count($source_key_values) && ($is_present == false) ; $j++) {
$check = true;
for ($k = 0; $k < sizeof($trg_keys[$matching_table_index]); $k++) {
for ($k = 0; $k < count($trg_keys[$matching_table_index]); $k++) {
if ($target_key_values[$i][$trg_keys[$matching_table_index][$k]] != $source_key_values[$j][$trg_keys[$matching_table_index][$k]]) {
$check = false;
}
@ -379,7 +399,7 @@ function PMA_findDeleteRowsFromTargetTables(&$delete_array, $matching_table,
}
}
if (! ($is_present)) {
for ($l = 0; $l < sizeof($trg_keys[$matching_table_index]); $l++) {
for ($l = 0; $l < count($trg_keys[$matching_table_index]); $l++) {
$delete_array[$matching_table_index][$row][$trg_keys[$matching_table_index][$l]] = $target_key_values[$i][$trg_keys[$matching_table_index][$l]];
}
$row++;
@ -405,7 +425,8 @@ function PMA_findDeleteRowsFromTargetTables(&$delete_array, $matching_table,
*/
function PMA_dataDiffInUncommonTables($source_tables_uncommon, $src_db, $src_link, $index, &$row_count)
{
$query = "SELECT COUNT(*) FROM " . PMA_backquote($src_db) . "." . PMA_backquote($source_tables_uncommon[$index]);
$query = "SELECT COUNT(*) FROM " . PMA_backquote($src_db) . "."
. PMA_backquote($source_tables_uncommon[$index]);
$rows = PMA_DBI_fetch_result($query, null, null, $src_link);
$row_count[$index] = $rows[0];
}
@ -414,17 +435,17 @@ function PMA_dataDiffInUncommonTables($source_tables_uncommon, $src_db, $src_lin
* PMA_updateTargetTables() sets the updated field values to
* target table rows using $update_array[$matching_table_index]
*
* @param array $table Matching tables' names
* @param array $update_array A three dimensional array containing field
* value updates required for each matching
* table
* @param string $src_db Name of source database
* @param string $trg_db Name of target database
* @param mixed $trg_link Connection established with target server
* @param int $matching_table_index index of matching table in
* matching_table_array
* @param array $matching_table_keys matching keys for table
* @param bool $display whether to display query
* @param array $table Matching tables' names
* @param array $update_array A three dimensional array containing field
* value updates required for each matching
* table
* @param string $src_db Name of source database
* @param string $trg_db Name of target database
* @param mixed $trg_link Connection established with target server
* @param int $matching_table_index index of matching table in
* matching_table_array
* @param array $matching_table_keys matching keys for table
* @param bool $display whether to display query
*
* @return nothing
*/
@ -433,12 +454,12 @@ function PMA_updateTargetTables(
$trg_link, $matching_table_index, $matching_table_keys, $display
) {
if (isset($update_array[$matching_table_index])) {
if (sizeof($update_array[$matching_table_index])) {
if (count($update_array[$matching_table_index])) {
for ($update_row = 0; $update_row < sizeof($update_array[$matching_table_index]); $update_row++) {
for ($update_row = 0; $update_row < count($update_array[$matching_table_index]); $update_row++) {
if (isset($update_array[$matching_table_index][$update_row])) {
$update_fields_num = sizeof($update_array[$matching_table_index][$update_row])-sizeof($matching_table_keys[$matching_table_index]);
$update_fields_num = count($update_array[$matching_table_index][$update_row])-count($matching_table_keys[$matching_table_index]);
if ($update_fields_num > 0) {
$query = "UPDATE " . PMA_backquote($trg_db) . "." .PMA_backquote($table[$matching_table_index]) . " SET ";
@ -452,11 +473,11 @@ function PMA_updateTargetTables(
}
$query .= " WHERE ";
if (isset($matching_table_keys[$matching_table_index])) {
for ($key = 0; $key < sizeof($matching_table_keys[$matching_table_index]); $key++) {
for ($key = 0; $key < count($matching_table_keys[$matching_table_index]); $key++) {
if (isset($matching_table_keys[$matching_table_index][$key])) {
$query .= PMA_backquote($matching_table_keys[$matching_table_index][$key]) . "='" . $update_array[$matching_table_index][$update_row][$matching_table_keys[$matching_table_index][$key]] . "'";
}
if ($key < (sizeof($matching_table_keys[$matching_table_index]) - 1)) {
if ($key < (count($matching_table_keys[$matching_table_index]) - 1)) {
$query .= " AND ";
}
}
@ -488,20 +509,32 @@ function PMA_updateTargetTables(
* @param mixed $trg_link connection established with target server
* @param array $table_fields field names of a table
* @param array &$array_insert
* @param int $matching_table_index index of matching table in matching_table_array
* @param array $matching_tables_keys field names that are keys in the matching table
* @param int $matching_table_index index of matching table in
* matching_table_array
* @param array $matching_tables_keys field names that are keys in the matching
* table
* @param array $source_columns source column information
* @param array &$add_column_array column names that are to be added in target table
* @param array $criteria criteria like type, null, collation, default etc
* @param array $target_tables_keys field names that are keys in the target table
* @param array $uncommon_tables table names that are present in source db but not in targt db
* @param array &$add_column_array column names that are to be added in
* target table
* @param array $criteria criteria like type, null, collation,
* default etc
* @param array $target_tables_keys field names that are keys in the target
* table
* @param array $uncommon_tables table names that are present in source db
* but not in targt db
* @param array &$uncommon_tables_fields field names of the uncommon tables
* @param array $uncommon_cols column names that are present in target table and not in source table
* @param array $uncommon_cols column names that are present in target
* table and not in source table
* @param array &$alter_str_array column names that are to be altered
* @param array &$source_indexes column names on which indexes are made in source table
* @param array &$target_indexes column names on which indexes are made in target table
* @param array &$add_indexes_array column names on which index is to be added in target table
* @param array &$alter_indexes_array column names whose indexes are to be altered. Only index name and uniqueness of an index can be changed
* @param array &$source_indexes column names on which indexes are made
* in source table
* @param array &$target_indexes column names on which indexes are made
* in target table
* @param array &$add_indexes_array column names on which index is to be
* added in target table
* @param array &$alter_indexes_array column names whose indexes are to be
* altered. Only index name and uniqueness
* of an index can be changed
* @param array &$delete_array rows that are to be deleted
* @param array &$update_array rows that are to be updated in target
* @param bool $display whether to display query
@ -516,16 +549,16 @@ function PMA_insertIntoTargetTable($matching_table, $src_db, $trg_db, $src_link,
&$alter_indexes_array, &$delete_array, &$update_array, $display
) {
if (isset($array_insert[$matching_table_index])) {
if (sizeof($array_insert[$matching_table_index])) {
for ($insert_row = 0; $insert_row< sizeof($array_insert[$matching_table_index]); $insert_row++) {
if (count($array_insert[$matching_table_index])) {
for ($insert_row = 0; $insert_row< count($array_insert[$matching_table_index]); $insert_row++) {
if (isset($array_insert[$matching_table_index][$insert_row][$matching_tables_keys[$matching_table_index][0]])) {
$select_query = "SELECT * FROM " . PMA_backquote($src_db) . "." . PMA_backquote($matching_table[$matching_table_index]) . " WHERE ";
for ($i = 0; $i < sizeof($matching_tables_keys[$matching_table_index]); $i++) {
for ($i = 0; $i < count($matching_tables_keys[$matching_table_index]); $i++) {
$select_query .= $matching_tables_keys[$matching_table_index][$i] . "='";
$select_query .= $array_insert[$matching_table_index][$insert_row][$matching_tables_keys[$matching_table_index][$i]] . "'" ;
if ($i < (sizeof($matching_tables_keys[$matching_table_index]) - 1)) {
if ($i < (count($matching_tables_keys[$matching_table_index]) - 1)) {
$select_query.= " AND ";
}
}
@ -533,7 +566,7 @@ function PMA_insertIntoTargetTable($matching_table, $src_db, $trg_db, $src_link,
$result = PMA_DBI_fetch_result($select_query, null, null, $src_link);
$insert_query = "INSERT INTO " . PMA_backquote($trg_db) . "." . PMA_backquote($matching_table[$matching_table_index]) ." (";
for ($field_index = 0; $field_index < sizeof($table_fields[$matching_table_index]); $field_index++) {
for ($field_index = 0; $field_index < count($table_fields[$matching_table_index]); $field_index++) {
$insert_query .= PMA_backquote($table_fields[$matching_table_index][$field_index]);
$is_fk_query = "SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = '" . $trg_db ."'
@ -541,35 +574,52 @@ function PMA_insertIntoTargetTable($matching_table, $src_db, $trg_db, $src_link,
$table_fields[$matching_table_index][$field_index] . "' AND TABLE_NAME <> REFERENCED_TABLE_NAME;" ;
$is_fk_result = PMA_DBI_fetch_result($is_fk_query, null, null, $trg_link);
if (sizeof($is_fk_result) > 0) {
for ($j = 0; $j < sizeof($is_fk_result); $j++) {
if (count($is_fk_result) > 0) {
for ($j = 0; $j < count($is_fk_result); $j++) {
$table_index = array_keys($matching_table, $is_fk_result[$j]['REFERENCED_TABLE_NAME']);
if (isset($alter_str_array[$table_index[0]])) {
PMA_alterTargetTableStructure(
$trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
$criteria, $matching_tables_keys, $target_tables_keys, $table_index[0], $display
$trg_db, $trg_link, $matching_tables,
$source_columns, $alter_str_array,
$matching_tables_fields,
$criteria, $matching_tables_keys,
$target_tables_keys, $table_index[0],
$display
);
unset($alter_str_array[$table_index[0]]);
}
if (isset($uncommon_columns[$table_index[0]])) {
PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $table_index[0], $display);
PMA_removeColumnsFromTargetTable(
$trg_db, $trg_link, $matching_tables,
$uncommon_columns, $table_index[0], $display
);
unset($uncommon_columns[$table_index[0]]);
}
if (isset($add_column_array[$table_index[0]])) {
PMA_findDeleteRowsFromTargetTables(
$delete_array, $matching_tables, $table_index[0], $target_tables_keys,
$matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link
$delete_array, $matching_tables,
$table_index[0], $target_tables_keys,
$matching_tables_keys, $trg_db,
$trg_link, $src_db, $src_link
);
if (isset($delete_array[$table_index[0]])) {
PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $table_index[0], $target_tables_keys, $delete_array, $display);
PMA_deleteFromTargetTable(
$trg_db, $trg_link, $matching_tables,
$table_index[0], $target_tables_keys,
$delete_array, $display
);
unset($delete_array[$table_index[0]]);
}
PMA_addColumnsInTargetTable(
$src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $add_column_array,
$matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,
$uncommon_tables_fields, $table_index[0], $uncommon_cols, $display
$src_db, $trg_db, $src_link, $trg_link,
$matching_tables, $source_columns,
$add_column_array, $matching_tables_fields,
$criteria, $matching_tables_keys,
$target_tables_keys, $uncommon_tables,
$uncommon_tables_fields, $table_index[0],
$uncommon_cols, $display
);
unset($add_column_array[$table_index[0]]);
}
@ -578,8 +628,11 @@ function PMA_insertIntoTargetTable($matching_table, $src_db, $trg_db, $src_link,
|| isset($alter_indexes_array[$table_index[0]])
) {
PMA_applyIndexesDiff(
$trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array,
$alter_indexes_array, $remove_indexes_array, $table_index[0], $display
$trg_db, $trg_link, $matching_tables,
$source_indexes, $target_indexes,
$add_indexes_array, $alter_indexes_array,
$remove_indexes_array, $table_index[0],
$display
);
unset($add_indexes_array[$table_index[0]]);
@ -588,37 +641,46 @@ function PMA_insertIntoTargetTable($matching_table, $src_db, $trg_db, $src_link,
}
if (isset($update_array[$table_index[0]])) {
PMA_updateTargetTables(
$matching_tables, $update_array, $src_db, $trg_db, $trg_link,
$table_index[0], $matching_table_keys, $display
$matching_tables, $update_array,
$src_db, $trg_db, $trg_link,
$table_index[0], $matching_table_keys,
$display
);
unset($update_array[$table_index[0]]);
}
if (isset($array_insert[$table_index[0]])) {
PMA_insertIntoTargetTable(
$matching_table, $src_db, $trg_db, $src_link, $trg_link, $table_fields, $array_insert, $table_index[0],
$matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys, $uncommon_tables,
$uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes, $target_indexes, $add_indexes_array,
$alter_indexes_array, $delete_array, $update_array, $display
$matching_table, $src_db, $trg_db,
$src_link, $trg_link, $table_fields,
$array_insert, $table_index[0],
$matching_tables_keys, $source_columns,
$add_column_array, $criteria,
$target_tables_keys, $uncommon_tables,
$uncommon_tables_fields, $uncommon_cols,
$alter_str_array, $source_indexes,
$target_indexes, $add_indexes_array,
$alter_indexes_array, $delete_array,
$update_array, $display
);
unset($array_insert[$table_index[0]]);
}
}
}
if ($field_index < sizeof($table_fields[$matching_table_index])-1) {
if ($field_index < count($table_fields[$matching_table_index])-1) {
$insert_query .= ", ";
}
}
$insert_query .= ") VALUES(";
if (sizeof($table_fields[$matching_table_index]) == 1) {
if (count($table_fields[$matching_table_index]) == 1) {
$insert_query .= "'" . PMA_sqlAddSlashes($result[0]) . "'";
} else {
for ($field_index = 0; $field_index < sizeof($table_fields[$matching_table_index]); $field_index++) {
for ($field_index = 0; $field_index < count($table_fields[$matching_table_index]); $field_index++) {
if (isset($result[0][$table_fields[$matching_table_index][$field_index]])) {
$insert_query .= "'" . PMA_sqlAddSlashes($result[0][$table_fields[$matching_table_index][$field_index]]) . "'";
} else {
$insert_query .= "'NULL'";
}
if ($field_index < (sizeof($table_fields[$matching_table_index])) - 1) {
if ($field_index < (count($table_fields[$matching_table_index])) - 1) {
$insert_query .= " ," ;
}
}
@ -654,7 +716,13 @@ function PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link,
&$uncommon_tables, $table_index, &$uncommon_tables_fields, $display
) {
if (isset($uncommon_tables[$table_index])) {
$fields_result = PMA_DBI_get_columns($src_db, $uncommon_tables[$table_index], null, true, $src_link);
$fields_result = PMA_DBI_get_columns(
$src_db,
$uncommon_tables[$table_index],
null,
true,
$src_link
);
$fields = array();
foreach ($fields_result as $each_field) {
$field_name = $each_field['Field'];
@ -662,7 +730,13 @@ function PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link,
}
$uncommon_tables_fields[$table_index] = $fields;
$Create_Query = PMA_DBI_fetch_value("SHOW CREATE TABLE " . PMA_backquote($src_db) . '.' . PMA_backquote($uncommon_tables[$table_index]), 0, 1, $src_link);
$Create_Query = PMA_DBI_fetch_value(
"SHOW CREATE TABLE " . PMA_backquote($src_db) . '.'
. PMA_backquote($uncommon_tables[$table_index]),
0,
1,
$src_link
);
// Replace the src table name with a `dbname`.`tablename`
$Create_Table_Query = preg_replace(
@ -676,8 +750,8 @@ function PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link,
AND TABLE_NAME = '" . $uncommon_tables[$table_index] . "' AND TABLE_NAME <> REFERENCED_TABLE_NAME;" ;
$is_fk_result = PMA_DBI_fetch_result($is_fk_query, null, null, $src_link);
if (sizeof($is_fk_result) > 0) {
for ($j = 0; $j < sizeof($is_fk_result); $j++) {
if (count($is_fk_result) > 0) {
for ($j = 0; $j < count($is_fk_result); $j++) {
if (in_array($is_fk_result[$j]['REFERENCED_TABLE_NAME'], $uncommon_tables)) {
$table_index = array_keys($uncommon_tables, $is_fk_result[$j]['REFERENCED_TABLE_NAME']);
PMA_createTargetTables($src_db, $trg_db, $trg_link, $src_link, $uncommon_tables, $table_index[0], $uncommon_tables_fields, $display);
@ -713,10 +787,17 @@ function PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link,
function PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link,
$uncommon_tables, $table_index, $uncommon_tables_fields, $display
) {
$display = false; // todo: maybe display some of the queries if they are not too numerous
$unbuffered_result = PMA_DBI_try_query('SELECT * FROM ' . PMA_backquote($src_db) . '.' . PMA_backquote($uncommon_tables[$table_index]), $src_link, PMA_DBI_QUERY_UNBUFFERED);
// @todo: maybe display some of the queries if they are not too numerous
$display = false;
$unbuffered_result = PMA_DBI_try_query(
'SELECT * FROM ' . PMA_backquote($src_db) . '.'
. PMA_backquote($uncommon_tables[$table_index]),
$src_link,
PMA_DBI_QUERY_UNBUFFERED
);
if (false !== $unbuffered_result) {
$insert_query = 'INSERT INTO ' . PMA_backquote($trg_db) . '.' .PMA_backquote($uncommon_tables[$table_index]) . ' VALUES';
$insert_query = 'INSERT INTO ' . PMA_backquote($trg_db) . '.'
. PMA_backquote($uncommon_tables[$table_index]) . ' VALUES';
while ($one_row = PMA_DBI_fetch_row($unbuffered_result)) {
$insert_query .= '(';
$key_of_last_value = count($one_row) - 1;
@ -750,21 +831,21 @@ function PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link,
*
* @return nothing
*/
function PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $table_index,
$target_tables_keys, $delete_array, $display
function PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables,
$table_index, $target_tables_keys, $delete_array, $display
) {
for ($i = 0; $i < sizeof($delete_array[$table_index]); $i++) {
for ($i = 0; $i < count($delete_array[$table_index]); $i++) {
if (isset($target_tables_keys[$table_index])) {
$delete_query = 'DELETE FROM ' . PMA_backquote($trg_db) . '.' .PMA_backquote($matching_tables[$table_index]) . ' WHERE ';
for ($y = 0; $y < sizeof($target_tables_keys[$table_index]); $y++) {
for ($y = 0; $y < count($target_tables_keys[$table_index]); $y++) {
$delete_query .= PMA_backquote($target_tables_keys[$table_index][$y]) . " = '";
if (sizeof($target_tables_keys[$table_index]) == 1) {
if (count($target_tables_keys[$table_index]) == 1) {
$delete_query .= $delete_array[$table_index][$i] . "'";
} elseif (sizeof($target_tables_keys[$table_index]) > 1) {
} elseif (count($target_tables_keys[$table_index]) > 1) {
$delete_query .= $delete_array[$table_index][$i][$target_tables_keys[$table_index][$y]] . "'";
}
if ($y < (sizeof($target_tables_keys[$table_index]) - 1)) {
if ($y < (count($target_tables_keys[$table_index]) - 1)) {
$delete_query .= ' AND ';
}
$pk_query = "SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = '" . $trg_db . "'
@ -772,11 +853,17 @@ function PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $table_
. $target_tables_keys[$table_index][$y] . "' AND TABLE_NAME <> REFERENCED_TABLE_NAME;";
$pk_query_result = PMA_DBI_fetch_result($pk_query, null, null, $trg_link);
$result_size = sizeof($pk_query_result);
$result_size = count($pk_query_result);
if ($result_size > 0) {
for ($b = 0; $b < $result_size; $b++) {
$drop_pk_query = "DELETE FROM " . PMA_backquote($pk_query_result[$b]['TABLE_SCHEMA']) . "." . PMA_backquote($pk_query_result[$b]['TABLE_NAME']) . " WHERE " . PMA_backquote($pk_query_result[$b]['COLUMN_NAME']) . " = " . $target_tables_keys[$table_index][$y] . ";";
$drop_pk_query = "DELETE FROM "
. PMA_backquote($pk_query_result[$b]['TABLE_SCHEMA'])
. "."
. PMA_backquote($pk_query_result[$b]['TABLE_NAME'])
. " WHERE "
. PMA_backquote($pk_query_result[$b]['COLUMN_NAME'])
. " = " . $target_tables_keys[$table_index][$y] . ";";
PMA_DBI_try_query($drop_pk_query, $trg_link, 0);
}
}
@ -829,6 +916,8 @@ function PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $table_
* target table
* @param array &$target_tables_keys field names which is key in the target table
* @param int $matching_table_index number of the matching table
*
* @return nothing
*/
function PMA_structureDiffInTables($src_db, $trg_db, $src_link, $trg_link,
$matching_tables, &$source_columns, &$target_columns, &$alter_str_array,
@ -836,12 +925,23 @@ function PMA_structureDiffInTables($src_db, $trg_db, $src_link, $trg_link,
$matching_table_index
) {
//Gets column information for source and target table
$source_columns[$matching_table_index] = PMA_DBI_get_columns_full($src_db, $matching_tables[$matching_table_index], null, $src_link);
$target_columns[$matching_table_index] = PMA_DBI_get_columns_full($trg_db, $matching_tables[$matching_table_index], null, $trg_link);
$source_columns[$matching_table_index] = PMA_DBI_get_columns_full(
$src_db,
$matching_tables[$matching_table_index],
null,
$src_link
);
$target_columns[$matching_table_index] = PMA_DBI_get_columns_full(
$trg_db,
$matching_tables[$matching_table_index],
null,
$trg_link
);
foreach ($source_columns[$matching_table_index] as $column_name => $each_column) {
if (isset($target_columns[$matching_table_index][$column_name]['Field'])) {
//If column exists in target table then matches criteria like type, null, collation, key, default, comment of the column
for ($i = 0; $i < sizeof($criteria); $i++) {
//If column exists in target table then matches criteria like type,
// null, collation, key, default, comment of the column
for ($i = 0; $i < count($criteria); $i++) {
if ($source_columns[$matching_table_index][$column_name][$criteria[$i]] != $target_columns[$matching_table_index][$column_name][$criteria[$i]]) {
if (($criteria[$i] == 'Default') && ($source_columns[$matching_table_index][$column_name][$criteria[$i]] == '' )) {
$alter_str_array[$matching_table_index][$column_name][$criteria[$i]] = 'None';
@ -907,7 +1007,7 @@ function PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link,
$criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,
&$uncommon_tables_fields, $table_counter, $uncommon_cols, $display
) {
for ($i = 0; $i < sizeof($matching_tables_fields[$table_counter]); $i++) {
for ($i = 0; $i < count($matching_tables_fields[$table_counter]); $i++) {
if (isset($add_column_array[$table_counter][$matching_tables_fields[$table_counter][$i]])) {
$query = "ALTER TABLE " . PMA_backquote($trg_db) . '.' . PMA_backquote($matching_tables[$table_counter]). " ADD COLUMN " .
PMA_backquote($add_column_array[$table_counter][$matching_tables_fields[$table_counter][$i]]) . " " . $source_columns[$table_counter][$matching_tables_fields[$table_counter][$i]]['Type'];
@ -927,7 +1027,7 @@ function PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link,
$query .= " COMMENT " . $source_columns[$table_counter][$matching_tables_fields[$table_counter][$i]]['Comment'];
}
if ($source_columns[$table_counter][$matching_tables_fields[$table_counter][$i]]['Key'] == 'PRI' ) {
$trg_key_size = sizeof($target_tables_keys[$table_counter]);
$trg_key_size = count($target_tables_keys[$table_counter]);
if ($trg_key_size) {
$check = true;
for ($a = 0; ($a < $trg_key_size) && ($check); $a++) {
@ -940,9 +1040,9 @@ function PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link,
}
}
$query .= " , ADD PRIMARY KEY (";
for ($t = 0; $t < sizeof($matching_tables_keys[$table_counter]); $t++) {
for ($t = 0; $t < count($matching_tables_keys[$table_counter]); $t++) {
$query .= PMA_backquote($matching_tables_keys[$table_counter][$t]);
if ($t < (sizeof($matching_tables_keys[$table_counter]) - 1)) {
if ($t < (count($matching_tables_keys[$table_counter]) - 1)) {
$query .= " , " ;
}
}
@ -955,15 +1055,16 @@ function PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link,
}
PMA_DBI_try_query($query, $trg_link, 0);
//Checks if column to be added is a foreign key or not
// Checks if column to be added is a foreign key or not
$is_fk_query = "SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = '" . $trg_db . "' AND TABLE_NAME = '"
. $matching_tables[$table_counter] . "' AND COLUMN_NAME ='" . $add_column_array[$table_counter][$matching_tables_fields[$table_counter][$i]] .
"' AND TABLE_NAME <> REFERENCED_TABLE_NAME;";
$is_fk_result = PMA_DBI_fetch_result($is_fk_query, null, null, $src_link);
//If column is a foreign key then it is checked that referenced table exist in target db. If referenced table does not exist in target db then
//it is created first.
// If column is a foreign key then it is checked that referenced table
// exist in target db. If referenced table does not exist in target
// db then it is created first.
if (isset($is_fk_result)) {
if (in_array($is_fk_result[0]['REFERENCED_TABLE_NAME'], $uncommon_tables)) {
$table_index = array_keys($uncommon_tables, $is_fk_result[0]['REFERENCED_TABLE_NAME']);
@ -1004,8 +1105,8 @@ function PMA_checkForeignKeys($src_db, $src_link, $trg_db, $trg_link,
AND TABLE_NAME = '" . $referenced_table . "' AND TABLE_NAME <> REFERENCED_TABLE_NAME;";
$is_fk_result = PMA_DBI_fetch_result($is_fk_query, null, null, $src_link);
if (sizeof($is_fk_result) > 0) {
for ($j = 0; $j < sizeof($is_fk_result); $j++) {
if (count($is_fk_result) > 0) {
for ($j = 0; $j < count($is_fk_result); $j++) {
if (in_array($is_fk_result[$j]['REFERENCED_TABLE_NAME'], $uncommon_tables)) {
$table_index = array_keys($uncommon_tables, $is_fk_result[$j]['REFERENCED_TABLE_NAME']);
PMA_checkForeignKeys(
@ -1029,8 +1130,10 @@ function PMA_checkForeignKeys($src_db, $src_link, $trg_db, $trg_link,
* altered for the targert table
* @param array $matching_tables_fields name of the fields for the matching table
* @param array $criteria criteria
* @param array &$matching_tables_keys field names which is key in the source table
* @param array &$target_tables_keys field names which is key in the target table
* @param array &$matching_tables_keys field names which is key in the source
* table
* @param array &$target_tables_keys field names which is key in the target
* table
* @param int $matching_table_index number of the matching table
* @param bool $display whether to display query
*
@ -1045,7 +1148,7 @@ function PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables,
$found = false;
//Checks if the criteria to be altered is primary key
for ($v = 0; $v < sizeof($matching_tables_fields[$matching_table_index]); $v++) {
for ($v = 0; $v < count($matching_tables_fields[$matching_table_index]); $v++) {
if (isset($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$v]]['Key'])) {
if ($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$v]]['Key'] == 'PRI' ) {
$check = false;
@ -1056,13 +1159,13 @@ function PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables,
$pri_query = null;
if (! $check) {
$pri_query = "ALTER TABLE " . PMA_backquote($trg_db) . '.' . PMA_backquote($matching_tables[$matching_table_index]);
if (sizeof($target_tables_keys[$matching_table_index]) > 0) {
if (count($target_tables_keys[$matching_table_index]) > 0) {
$pri_query .= " DROP PRIMARY KEY ," ;
}
$pri_query .= " ADD PRIMARY KEY (";
for ($z = 0; $z < sizeof($matching_tables_keys[$matching_table_index]); $z++) {
for ($z = 0; $z < count($matching_tables_keys[$matching_table_index]); $z++) {
$pri_query .= PMA_backquote($matching_tables_keys[$matching_table_index][$z]);
if ($z < (sizeof($matching_tables_keys[$matching_table_index]) - 1)) {
if ($z < (count($matching_tables_keys[$matching_table_index]) - 1)) {
$pri_query .= " , " ;
}
}
@ -1075,12 +1178,12 @@ function PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables,
}
PMA_DBI_try_query($pri_query, $trg_link, 0);
}
for ($t = 0; $t < sizeof($matching_tables_fields[$matching_table_index]); $t++) {
if ((isset($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$t]])) && (sizeof($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$t]]) > 0)) {
for ($t = 0; $t < count($matching_tables_fields[$matching_table_index]); $t++) {
if ((isset($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$t]])) && (count($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$t]]) > 0)) {
$sql_query = 'ALTER TABLE ' . PMA_backquote($trg_db) . '.' . PMA_backquote($matching_tables[$matching_table_index]) . ' MODIFY ' .
PMA_backquote($matching_tables_fields[$matching_table_index][$t]) . ' ' . $source_columns[$matching_table_index][$matching_tables_fields[$matching_table_index][$t]]['Type'];
$found = false;
for ($i = 0; $i < sizeof($criteria); $i++) {
for ($i = 0; $i < count($criteria); $i++) {
if (isset($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$t]][$criteria[$i]]) && $criteria[$i] != 'Key') {
$found = true;
if (($criteria[$i] == 'Type') && (! isset($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$t]][$criteria[$i+1]]))) {
@ -1137,13 +1240,14 @@ function PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables,
}
}
$check = false;
$query = "ALTER TABLE " . PMA_backquote($trg_db) . '.' . PMA_backquote($matching_tables[$matching_table_index]);
for ($p = 0; $p < sizeof($matching_tables_keys[$matching_table_index]); $p++) {
$query = "ALTER TABLE " . PMA_backquote($trg_db) . '.'
. PMA_backquote($matching_tables[$matching_table_index]);
for ($p = 0; $p < count($matching_tables_keys[$matching_table_index]); $p++) {
if ((isset($alter_str_array[$matching_table_index][$matching_tables_keys[$matching_table_index][$p]]['Key']))) {
$check = true;
$query .= ' MODIFY ' . PMA_backquote($matching_tables_keys[$matching_table_index][$p]) . ' '
. $source_columns[$matching_table_index][$matching_tables_fields[$matching_table_index][$p]]['Type'] . ' Not Null ';
if ($p < (sizeof($matching_tables_keys[$matching_table_index]) - 1)) {
if ($p < (count($matching_tables_keys[$matching_table_index]) - 1)) {
$query .= ', ';
}
}
@ -1163,8 +1267,10 @@ function PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables,
* @param string $trg_db name of target database
* @param mixed $trg_link connection established with target server
* @param array $matching_tables names of matching tables
* @param array $uncommon_columns array containing the names of the column which are to be dropped from the target table
* @param int $table_counter index of the matching table as in $matchiing_tables array
* @param array $uncommon_columns array containing the names of the column which
* are to be dropped from the target table
* @param int $table_counter index of the matching table as in
* $matchiing_tables array
* @param bool $display whether to display query
*
* @return nothing
@ -1173,15 +1279,16 @@ function PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables,
$uncommon_columns, $table_counter, $display
) {
if (isset($uncommon_columns[$table_counter])) {
$drop_query = "ALTER TABLE " . PMA_backquote($trg_db) . "." . PMA_backquote($matching_tables[$table_counter]);
for ($a = 0; $a < sizeof($uncommon_columns[$table_counter]); $a++) {
$drop_query = "ALTER TABLE " . PMA_backquote($trg_db) . "."
. PMA_backquote($matching_tables[$table_counter]);
for ($a = 0; $a < count($uncommon_columns[$table_counter]); $a++) {
//Checks if column to be removed is a foreign key in any table
$pk_query = "SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = '" . $trg_db . "'
AND REFERENCED_TABLE_NAME = '" . $matching_tables[$table_counter]."' AND REFERENCED_COLUMN_NAME = '"
. $uncommon_columns[$table_counter][$a] . "' AND TABLE_NAME <> REFERENCED_TABLE_NAME;";
$pk_query_result = PMA_DBI_fetch_result($pk_query, null, null, $trg_link);
$result_size = sizeof($pk_query_result);
$result_size = count($pk_query_result);
if ($result_size > 0) {
for ($b = 0; $b < $result_size; $b++) {
@ -1196,11 +1303,11 @@ function PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables,
$result = PMA_DBI_fetch_result($query, null, null, $trg_link);
if (sizeof($result) > 0) {
if (count($result) > 0) {
$drop_query .= " DROP FOREIGN KEY " . PMA_backquote($result[0]['CONSTRAINT_NAME']) . ",";
}
$drop_query .= " DROP COLUMN " . PMA_backquote($uncommon_columns[$table_counter][$a]);
if ($a < (sizeof($uncommon_columns[$table_counter]) - 1)) {
if ($a < (count($uncommon_columns[$table_counter]) - 1)) {
$drop_query .= " , " ;
}
}
@ -1214,9 +1321,11 @@ function PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables,
}
/**
* PMA_indexesDiffInTables() compares the source table indexes with target table indexes and keep the indexes to be added in target table in $add_indexes_array
* indexes to be altered in $alter_indexes_array and indexes to be removed from target table in $remove_indexes_array.
* Only keyname and uniqueness characteristic of the indexes are altered.
* PMA_indexesDiffInTables() compares the source table indexes with target
* table indexes and keep the indexes to be added in target table in
* $add_indexes_array indexes to be altered in $alter_indexes_array and indexes
* to be removed from target table in $remove_indexes_array. Only keyname and
* uniqueness characteristic of the indexes are altered.
*
* @param string $src_db name of source database
* @param string $trg_db name of target database
@ -1241,14 +1350,14 @@ function PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link,
//Gets indexes information for source and target table
$source_indexes[$table_counter] = PMA_DBI_get_table_indexes($src_db, $matching_tables[$table_counter], $src_link);
$target_indexes[$table_counter] = PMA_DBI_get_table_indexes($trg_db, $matching_tables[$table_counter], $trg_link);
for ($a = 0; $a < sizeof($source_indexes[$table_counter]); $a++) {
for ($a = 0; $a < count($source_indexes[$table_counter]); $a++) {
$found = false;
$z = 0;
//Compares key name and non_unique characteristic of source indexes with target indexes
/*
* @todo compare the length of each sub part
*/
while (($z <= sizeof($target_indexes[$table_counter])) && ($found == false)) {
while (($z <= count($target_indexes[$table_counter])) && ($found == false)) {
if (isset($source_indexes[$table_counter][$a]) && isset($target_indexes[$table_counter][$z]) && $source_indexes[$table_counter][$a]['Key_name'] == $target_indexes[$table_counter][$z]['Key_name']) {
$found = true;
if (($source_indexes[$table_counter][$a]['Column_name'] != $target_indexes[$table_counter][$z]['Column_name']) || ($source_indexes[$table_counter][$a]['Non_unique'] != $target_indexes[$table_counter][$z]['Non_unique'])) {
@ -1267,10 +1376,10 @@ function PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link,
}
//Finds indexes that exist on target table but not on source table
for ($b = 0; $b < sizeof($target_indexes[$table_counter]); $b++) {
for ($b = 0; $b < count($target_indexes[$table_counter]); $b++) {
$found = false;
$c = 0;
while (($c <= sizeof($source_indexes[$table_counter])) && ($found == false)) {
while (($c <= count($source_indexes[$table_counter])) && ($found == false)) {
if ($target_indexes[$table_counter][$b]['Column_name'] == $source_indexes[$table_counter][$c]['Column_name']) {
$found = true;
}
@ -1290,9 +1399,12 @@ function PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link,
* @param array $matching_tables matching tables name
* @param array $source_indexes indexes of the source table
* @param array $target_indexes indexes of the target table
* @param array $add_indexes_array column names on which indexes are to be created in target table
* @param array $alter_indexes_array column names for which indexes are to be altered
* @param array $remove_indexes_array key name of the indexes which are to be removed from the target table
* @param array $add_indexes_array column names on which indexes are to be
* created in target table
* @param array $alter_indexes_array column names for which indexes are to be
* altered
* @param array $remove_indexes_array key name of the indexes which are to be
* removed from the target table
* @param int $table_counter number of the matching table
* @param bool $display whether to display query
*
@ -1305,9 +1417,9 @@ function PMA_applyIndexesDiff($trg_db, $trg_link, $matching_tables, $source_inde
//Adds indexes on target table
if (isset($add_indexes_array[$table_counter])) {
$sql = "ALTER TABLE " . PMA_backquote($trg_db) . "." . PMA_backquote($matching_tables[$table_counter]) . " ADD" ;
for ($a = 0; $a < sizeof($source_indexes[$table_counter]); $a++) {
for ($a = 0; $a < count($source_indexes[$table_counter]); $a++) {
if (isset($add_indexes_array[$table_counter][$a])) {
for ($b = 0; $b < sizeof($source_indexes[$table_counter]); $b++) {
for ($b = 0; $b < count($source_indexes[$table_counter]); $b++) {
if ($source_indexes[$table_counter][$b]['Column_name'] == $add_indexes_array[$table_counter][$a]) {
if ($source_indexes[$table_counter][$b]['Non_unique'] == '0') {
$sql .= " UNIQUE ";
@ -1326,11 +1438,11 @@ function PMA_applyIndexesDiff($trg_db, $trg_link, $matching_tables, $source_inde
if (isset($alter_indexes_array[$table_counter])) {
$query = "ALTER TABLE " . PMA_backquote($trg_db) . "." . PMA_backquote($matching_tables[$table_counter]);
for ($a = 0; $a < sizeof($alter_indexes_array[$table_counter]); $a++) {
for ($a = 0; $a < count($alter_indexes_array[$table_counter]); $a++) {
if (isset($alter_indexes_array[$table_counter][$a])) {
$query .= ' DROP INDEX ' . PMA_backquote($alter_indexes_array[$table_counter][$a]) . " , ADD ";
$got_first_index_column = false;
for ($z = 0; $z < sizeof($source_indexes[$table_counter]); $z++) {
for ($z = 0; $z < count($source_indexes[$table_counter]); $z++) {
if ($source_indexes[$table_counter][$z]['Key_name'] == $alter_indexes_array[$table_counter][$a]) {
if (! $got_first_index_column) {
if ($source_indexes[$table_counter][$z]['Non_unique'] == '0') {
@ -1356,11 +1468,11 @@ function PMA_applyIndexesDiff($trg_db, $trg_link, $matching_tables, $source_inde
//Removes indexes from target table
if (isset($remove_indexes_array[$table_counter])) {
$drop_index_query = "ALTER TABLE " . PMA_backquote($trg_db) . "." . PMA_backquote($matching_tables[$table_counter]);
for ($a = 0; $a < sizeof($target_indexes[$table_counter]); $a++) {
for ($a = 0; $a < count($target_indexes[$table_counter]); $a++) {
if (isset($remove_indexes_array[$table_counter][$a])) {
$drop_index_query .= " DROP INDEX " . PMA_backquote($remove_indexes_array[$table_counter][$a]);
}
if ($a < (sizeof($remove_indexes_array[$table_counter]) - 1)) {
if ($a < (count($remove_indexes_array[$table_counter]) - 1)) {
$drop_index_query .= " , " ;
}
}
@ -1402,19 +1514,23 @@ function PMA_syncDisplayHeaderCompare($src_db, $trg_db)
echo '<table class="data">';
echo '<tr>';
echo '<th>' . __('Source database') . ': ' . htmlspecialchars($src_db) . '<br />(';
echo '<th>' . __('Source database') . ': '
. htmlspecialchars($src_db) . '<br />(';
if ('cur' == $_SESSION['src_type']) {
echo __('Current server');
} else {
echo __('Remote server') . ' ' . htmlspecialchars($_SESSION['src_server']['host']);
echo __('Remote server') . ' '
. htmlspecialchars($_SESSION['src_server']['host']);
}
echo ')</th>';
echo '<th>' . __('Difference') . '</th>';
echo '<th>' . __('Target database') . ': '. htmlspecialchars($trg_db) . '<br />(';
echo '<th>' . __('Target database') . ': '
. htmlspecialchars($trg_db) . '<br />(';
if ('cur' == $_SESSION['trg_type']) {
echo __('Current server');
} else {
echo __('Remote server') . ' ' . htmlspecialchars($_SESSION['trg_server']['host']);
echo __('Remote server') . ' '
. htmlspecialchars($_SESSION['trg_server']['host']);
}
echo ')</th>';
echo '</tr>';
@ -1479,9 +1595,9 @@ function PMA_syncDisplayDataCompare($rows)
function PMA_getColumnValues($database, $table, $column, $link = null)
{
$query = 'SELECT ';
for ($i=0; $i< sizeof($column); $i++) {
for ($i = 0; $i < count($column); $i++) {
$query.= PMA_backquote($column[$i]);
if ($i < (sizeof($column)-1)) {
if ($i < (count($column)-1)) {
$query.= ', ';
}
}