Пример #1
0
require './libraries/tbl_info.inc.php';
$reread_info = false;

/**
 * Updates if required
 */
if (isset($_REQUEST['submitoptions'])) {
    $_message = '';
    $warning_messages = array();

    if (isset($_REQUEST['new_name'])) {
        if ($pma_table->rename($_REQUEST['new_name'], null, $is_view = true)) {
            $_message .= $pma_table->getLastMessage();
            $result = true;
            $GLOBALS['table'] = $pma_table->getName();
            $reread_info = true;
            $reload = true;
        } else {
            $_message .= $pma_table->getLastError();
            $result = false;
        }
    }
}

if (isset($result)) {
    // set to success by default, because result set could be empty
    // (for example, a table rename)
    $_type = 'success';
    if (empty($_message)) {
        $_message = $result ? __('Your SQL query has been executed successfully') : __('Error');
Пример #2
0
/**
 * If the table has to be maintained
 */
if (isset($_REQUEST['table_maintenance'])) {
    include_once 'sql.php';
    unset($result);
}
/**
 * Updates table comment, type and options if required
 */
if (isset($_REQUEST['submitoptions'])) {
    $_message = '';
    $warning_messages = array();
    if (isset($_REQUEST['new_name'])) {
        // Get original names before rename operation
        $oldTable = $pma_table->getName();
        $oldDb = $pma_table->getDbName();
        if ($pma_table->rename($_REQUEST['new_name'])) {
            if (isset($_REQUEST['adjust_privileges']) && !empty($_REQUEST['adjust_privileges'])) {
                PMA_AdjustPrivileges_renameOrMoveTable($oldDb, $oldTable, $_REQUEST['db'], $_REQUEST['new_name']);
            }
            // Reselect the original DB
            $GLOBALS['db'] = $oldDb;
            $GLOBALS['dbi']->selectDb($oldDb);
            $_message .= $pma_table->getLastMessage();
            $result = true;
            $GLOBALS['table'] = $pma_table->getName();
            $reread_info = true;
            $reload = true;
        } else {
            $_message .= $pma_table->getLastError();
Пример #3
0
 /**
  * Test getName & getDbName
  *
  * @return void
  */
 public function testGetName()
 {
     $table = new PMA_Table('table1', 'pma_test');
     $this->assertEquals("table1", $table->getName());
     $this->assertEquals("`table1`", $table->getName(true));
     $this->assertEquals("pma_test", $table->getDbName());
     $this->assertEquals("`pma_test`", $table->getDbName(true));
 }
Пример #4
0
 /**
  * renames table
  *
  * @param   string  new table name
  * @param   string  new database name
  * @param   boolean is this for a VIEW rename?
  * @return  boolean success
  */
 function rename($new_name, $new_db = null, $is_view = false)
 {
     if (null !== $new_db && $new_db !== $this->getDbName()) {
         // Ensure the target is valid
         if (!$GLOBALS['pma']->databases->exists($new_db)) {
             $this->errors[] = __('Invalid database') . ': ' . $new_db;
             return false;
         }
     } else {
         $new_db = $this->getDbName();
     }
     $new_table = new PMA_Table($new_name, $new_db);
     if ($this->getFullName() === $new_table->getFullName()) {
         return true;
     }
     if (!PMA_Table::isValidName($new_name)) {
         $this->errors[] = __('Invalid table name') . ': ' . $new_table->getFullName();
         return false;
     }
     if (!$is_view) {
         $GLOBALS['sql_query'] = '
             ALTER TABLE ' . $this->getName(true) . '
             RENAME TO ' . $new_table->getName(true);
     } else {
         $GLOBALS['sql_query'] = '
             ALTER TABLE ' . $this->getFullName(true) . '
             RENAME ' . $new_table->getFullName(true) . ';';
     }
     // I don't think a specific error message for views is necessary
     if (!PMA_DBI_query($GLOBALS['sql_query'])) {
         $this->errors[] = sprintf(__('Error renaming table %1$s to %2$s'), $this->getFullName(), $new_table->getFullName());
         return false;
     }
     $old_name = $this->getName();
     $old_db = $this->getDbName();
     $this->setName($new_name);
     $this->setDbName($new_db);
     /**
      * @todo move into extra function PMA_Relation::renameTable($new_name, $old_name, $new_db, $old_db)
      */
     // Move old entries from comments to new table
     $GLOBALS['cfgRelation'] = PMA_getRelationsParam();
     if ($GLOBALS['cfgRelation']['commwork']) {
         $remove_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . '
                SET `db_name`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_controluser($remove_query);
         unset($remove_query);
     }
     if ($GLOBALS['cfgRelation']['displaywork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . '
                SET `db_name`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['relwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . '
                SET `foreign_db`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `foreign_table` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `foreign_db`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `foreign_table` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . '
                SET `master_db`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `master_table` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `master_db`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `master_table` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['pdfwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . '
                SET `db_name`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['designerwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . '
                SET `db_name`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         unset($table_query);
     }
     $this->messages[] = sprintf(__('Table %s has been renamed to %s'), htmlspecialchars($old_name), htmlspecialchars($new_name));
     return true;
 }