Merge pull request #14446 from aswaniprakash/PMA_14404
Drop view and or replace added to exporting view #14404
This commit is contained in:
commit
cd752ad149
@ -14,6 +14,7 @@ phpMyAdmin - ChangeLog
|
||||
- issue #14330 New features for csv import plugin
|
||||
- issue #14417 Automatically add index while editing an existing row and setting auto increment
|
||||
- issue #13057 Add export option to drop user security definers from views
|
||||
- issue #14404 Drop view and or replace added to exporting view
|
||||
|
||||
4.8.4 (not yet released)
|
||||
- issue #14452 Remove hash param in edit query URL
|
||||
|
||||
@ -139,6 +139,7 @@ $post_params = [
|
||||
'sql_create_trigger',
|
||||
'sql_view_current_user',
|
||||
'sql_if_not_exists',
|
||||
'sql_or_replace_view',
|
||||
'sql_auto_increment',
|
||||
'sql_backquotes',
|
||||
'sql_truncate',
|
||||
|
||||
@ -253,6 +253,7 @@ class Descriptions
|
||||
. ' table creation)'
|
||||
),
|
||||
'Export_sql_view_current_user' => __('Exclude definition of current user'),
|
||||
'Export_sql_or_replace_view_name' => sprintf(__('%s view'), 'OR REPLACE'),
|
||||
'Export_sql_ignore_name' => __('Use ignore inserts'),
|
||||
'Export_sql_include_comments_name' => __('Comments'),
|
||||
'Export_sql_insert_syntax_name' => __('Syntax to use when inserting data'),
|
||||
|
||||
@ -65,6 +65,7 @@ class ExportForm extends BaseForm
|
||||
':group:end',
|
||||
'Export/sql_create_view' => ':group',
|
||||
'Export/sql_view_current_user',
|
||||
'Export/sql_or_replace_view',
|
||||
':group:end',
|
||||
'Export/sql_procedure_function',
|
||||
'Export/sql_create_trigger',
|
||||
|
||||
@ -311,11 +311,19 @@ class ExportSql extends ExportPlugin
|
||||
sprintf(__('Add %s statement'), '<code>CREATE VIEW</code>')
|
||||
);
|
||||
$subgroup_create_view->setSubgroupHeader($leaf);
|
||||
|
||||
$leaf = new BoolPropertyItem(
|
||||
'view_current_user',
|
||||
__('Exclude definition of current user')
|
||||
);
|
||||
$subgroup_create_view->addProperty($leaf);
|
||||
|
||||
$leaf = new BoolPropertyItem(
|
||||
'or_replace_view',
|
||||
sprintf(__('%s view'), '<code>OR REPLACE</code>')
|
||||
);
|
||||
$subgroup_create_view->addProperty($leaf);
|
||||
|
||||
$subgroup->addProperty($subgroup_create_view);
|
||||
|
||||
$leaf = new BoolPropertyItem(
|
||||
@ -1469,6 +1477,14 @@ class ExportSql extends ExportPlugin
|
||||
|
||||
$schema_create .= $new_crlf;
|
||||
|
||||
if (!empty($sql_drop_table)
|
||||
&& $GLOBALS['dbi']->getTable($db, $table)->isView()
|
||||
) {
|
||||
$schema_create .= 'DROP VIEW IF EXISTS '
|
||||
. Util::backquote($table_alias, $sql_backquotes) . ';'
|
||||
. $crlf;
|
||||
}
|
||||
|
||||
// no need to generate a DROP VIEW here, it was done earlier
|
||||
if (!empty($sql_drop_table)
|
||||
&& !$GLOBALS['dbi']->getTable($db, $table)->isView()
|
||||
@ -1551,6 +1567,15 @@ class ExportSql extends ExportPlugin
|
||||
$create_query
|
||||
);
|
||||
}
|
||||
|
||||
// whether to replace existing view or not
|
||||
if ($GLOBALS['sql_or_replace_view']) {
|
||||
$create_query = preg_replace(
|
||||
'/^CREATE/',
|
||||
'CREATE OR REPLACE',
|
||||
$create_query
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Substitute aliases in `CREATE` query.
|
||||
|
||||
@ -1959,13 +1959,14 @@ $cfg['Export']['sql_drop_table'] = false;
|
||||
$cfg['Export']['sql_if_not_exists'] = false;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* @global boolean $cfg['Export']['sql_view_current_user']
|
||||
*/
|
||||
$cfg['Export']['sql_view_current_user'] = false;
|
||||
|
||||
/**
|
||||
* @global boolean $cfg['Export']['sql_or_replace']
|
||||
*/
|
||||
$cfg['Export']['sql_or_replace_view'] = false;
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@ -283,7 +283,7 @@ class ExportSqlTest extends PmaTestCase
|
||||
);
|
||||
|
||||
$this->assertCount(
|
||||
1,
|
||||
2,
|
||||
$leaf->getProperties()
|
||||
);
|
||||
|
||||
@ -1025,7 +1025,7 @@ class ExportSqlTest extends PmaTestCase
|
||||
]
|
||||
)
|
||||
);
|
||||
$dbi->expects($this->once())
|
||||
$dbi->expects($this->exactly(2))
|
||||
->method('getTable')
|
||||
->will($this->returnValue(new Table('table', 'db', $dbi)));
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
@ -1180,7 +1180,7 @@ class ExportSqlTest extends PmaTestCase
|
||||
->method('getError')
|
||||
->will($this->returnValue('error occurred'));
|
||||
|
||||
$dbi->expects($this->once())
|
||||
$dbi->expects($this->exactly(2))
|
||||
->method('getTable')
|
||||
->will($this->returnValue(new Table('table', 'db', $dbi)));
|
||||
$dbi->expects($this->any())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user