Drop view and or replace added to exporting view #14404

Signed-off-by: Aswani Prakash <aswani15prakash@gmail.com>
This commit is contained in:
Aswani Prakash 2018-07-03 13:23:48 +05:30 committed by Maurício Meneghini Fauth
parent 3209bd34c0
commit e5fb032ff7
5 changed files with 32 additions and 3 deletions

View File

@ -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',

View File

@ -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'),

View File

@ -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',

View File

@ -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.

View File

@ -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;
/**
*