diff --git a/libraries/plugins/ExportPlugin.class.php b/libraries/plugins/ExportPlugin.class.php
index ecfde15f98..66af3e9bf2 100644
--- a/libraries/plugins/ExportPlugin.class.php
+++ b/libraries/plugins/ExportPlugin.class.php
@@ -52,11 +52,12 @@ abstract class ExportPlugin extends PluginObserver
/**
* Outputs database header
*
- * @param string $db Database name
+ * @param string $db Database name
+ * @param string $db_alias Aliases of db
*
* @return bool Whether it succeeded
*/
- abstract public function exportDBHeader ($db);
+ abstract public function exportDBHeader ($db, $db_alias = '');
/**
* Outputs database footer
@@ -70,11 +71,12 @@ abstract class ExportPlugin extends PluginObserver
/**
* Outputs CREATE DATABASE statement
*
- * @param string $db Database name
+ * @param string $db Database name
+ * @param string $db_alias Aliases of db
*
* @return bool Whether it succeeded
*/
- abstract public function exportDBCreate($db);
+ abstract public function exportDBCreate($db, $db_alias = '');
/**
* Outputs the content of a table
@@ -84,26 +86,28 @@ abstract class ExportPlugin extends PluginObserver
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
+ * @param array $aliases Aliases of db/table/columns
*
* @return bool Whether it succeeded
*/
- abstract public function exportData ($db, $table, $crlf, $error_url, $sql_query);
-
+ abstract public function exportData (
+ $db, $table, $crlf, $error_url, $sql_query, $aliases = array()
+ );
/**
* The following methods are used in export.php or in db_operations.php,
* but they are not implemented by all export plugins
*/
-
/**
* Exports routines (procedures and functions)
*
- * @param string $db Database
+ * @param string $db Database
+ * @param array $aliases Aliases of db/table/columns
*
* @return bool Whether it succeeded
*/
- public function exportRoutines($db)
+ public function exportRoutines($db, $aliases = array())
{
;
}
@@ -126,6 +130,7 @@ abstract class ExportPlugin extends PluginObserver
* types which use this parameter
* @param bool $mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
+ * @param array $aliases Aliases of db/table/columns
*
* @return bool Whether it succeeded
*/
@@ -139,7 +144,8 @@ abstract class ExportPlugin extends PluginObserver
$relation = false,
$comments = false,
$mime = false,
- $dates = false
+ $dates = false,
+ $aliases = array()
) {
;
}
@@ -147,13 +153,14 @@ abstract class ExportPlugin extends PluginObserver
/**
* Returns a stand-in CREATE definition to resolve view dependencies
*
- * @param string $db the database name
- * @param string $view the view name
- * @param string $crlf the end of line sequence
+ * @param string $db the database name
+ * @param string $view the view name
+ * @param string $crlf the end of line sequence
+ * @param array $aliases Aliases of db/table/columns
*
* @return string resulting definition
*/
- public function getTableDefStandIn($db, $view, $crlf)
+ public function getTableDefStandIn($db, $view, $crlf, $aliases = array())
{
;
}
@@ -181,10 +188,8 @@ abstract class ExportPlugin extends PluginObserver
;
}
-
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
-
/**
* Gets the export specific format plugin properties
*
@@ -202,5 +207,122 @@ abstract class ExportPlugin extends PluginObserver
* @return void
*/
abstract protected function setProperties();
+
+ /**
+ * The following methods are implemented here so that they
+ * can be used by all export plugin without overriding it.
+ * Note: If you are creating a export plugin then dont include
+ * below methods unless you want to override them.
+ */
+
+ /**
+ * Initialize aliases
+ *
+ * @param array $aliases Alias information for db/table/column
+ * @param string &$db the database
+ * @param string &$table the table
+ *
+ * @return nothing
+ */
+ public function initAlias($aliases, &$db, &$table = null)
+ {
+ if (!empty($aliases[$db]['tables'][$table]['alias'])) {
+ $table = $aliases[$db]['tables'][$table]['alias'];
+ }
+ if (!empty($aliases[$db]['alias'])) {
+ $db = $aliases[$db]['alias'];
+ }
+ }
+
+ /**
+ * Search for alias of a identifier.
+ *
+ * @param array $aliases Alias information for db/table/column
+ * @param string $id the identifier to be searched
+ * @param string $type db/tbl/col or any combination of them
+ * representing what to be searched
+ * @param string $db the database in which search is to be done
+ * @param string $tbl the table in which search is to be done
+ *
+ * @return string alias of the identifier if found or ''
+ */
+ public function getAlias($aliases, $id, $type = 'dbtblcol', $db = '', $tbl = '')
+ {
+ if (!empty($db) && isset($aliases[$db])) {
+ $aliases = array(
+ $db => $aliases[$db]
+ );
+ }
+ // search each database
+ foreach ($aliases as $db_key => $db) {
+ // check if id is database and has alias
+ if (stristr($type, 'db') !== false
+ && $db_key === $id && !empty($db['alias'])
+ ) {
+ return $db['alias'];
+ }
+ if (empty($db['tables'])) {
+ continue;
+ }
+ if (!empty($tbl) && isset($db['tables'][$tbl])) {
+ $db['tables'] = array(
+ $tbl => $db['tables'][$tbl]
+ );
+ }
+ // search each of its tables
+ foreach ($db['tables'] as $table_key => $table) {
+ // check if id is table and has alias
+ if (stristr($type, 'tbl') !== false
+ && $table_key === $id && !empty($table['alias'])
+ ) {
+ return $table['alias'];
+ }
+ if (empty($table['columns'])) {
+ continue;
+ }
+ // search each of its columns
+ foreach ($table['columns'] as $col_key => $col) {
+ // check if id is column
+ if (stristr($type, 'col') !== false
+ && $col_key === $id && !empty($col)
+ ) {
+ return $col;
+ }
+ }
+ }
+ }
+ return '';
+ }
+
+ /**
+ * Gives the relation string and
+ * also substitutes with alias if required
+ * in this format:
+ * [Foreign Table] ([Foreign Field])
+ *
+ * @param array $res_rel the foreigners array
+ * @param string $field_name the field name
+ * @param string $db the field name
+ * @param array $aliases Alias information for db/table/column
+ *
+ * @return string the Relation string
+ */
+ public function getRelationString(
+ $res_rel, $field_name, $db, $aliases = array()
+ ) {
+ $relation = '';
+ if (isset($res_rel[$field_name])) {
+ $ftable = $res_rel[$field_name]['foreign_table'];
+ $ffield = $res_rel[$field_name]['foreign_field'];
+ if (!empty($aliases[$db]['tables'][$ftable]['columns'][$ffield])) {
+ $ffield = $aliases[$db]['tables'][$ftable]['columns'][$ffield];
+ }
+ if (!empty($aliases[$db]['tables'][$ftable]['alias'])) {
+ $ftable = $aliases[$db]['tables'][$ftable]['alias'];
+ }
+ $relation = $ftable . ' (' . $ffield . ')';
+ }
+ return $relation;
+ }
}
-?>
\ No newline at end of file
+?>
diff --git a/libraries/plugins/export/ExportCodegen.class.php b/libraries/plugins/export/ExportCodegen.class.php
index 4495e7ee4d..b616144ca6 100644
--- a/libraries/plugins/export/ExportCodegen.class.php
+++ b/libraries/plugins/export/ExportCodegen.class.php
@@ -151,11 +151,12 @@ class ExportCodegen extends ExportPlugin
/**
* Outputs database header
*
- * @param string $db Database name
+ * @param string $db Database name
+ * @param string $db_alias Aliases of db
*
* @return bool Whether it succeeded
*/
- public function exportDBHeader ($db)
+ public function exportDBHeader ($db, $db_alias = '')
{
return true;
}
@@ -175,11 +176,12 @@ class ExportCodegen extends ExportPlugin
/**
* Outputs CREATE DATABASE statement
*
- * @param string $db Database name
+ * @param string $db Database name
+ * @param string $db_alias Aliases of db
*
* @return bool Whether it succeeded
*/
- public function exportDBCreate($db)
+ public function exportDBCreate($db, $db_alias = '')
{
return true;
}
@@ -192,18 +194,20 @@ class ExportCodegen extends ExportPlugin
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
+ * @param array $aliases Aliases of db/table/columns
*
* @return bool Whether it succeeded
*/
- public function exportData($db, $table, $crlf, $error_url, $sql_query)
- {
+ public function exportData(
+ $db, $table, $crlf, $error_url, $sql_query, $aliases = array()
+ ) {
$CG_FORMATS = $this->_getCgFormats();
$CG_HANDLERS = $this->_getCgHandlers();
$format = $GLOBALS['codegen_format'];
if (isset($CG_FORMATS[$format])) {
return PMA_exportOutputHandler(
- $this->$CG_HANDLERS[$format]($db, $table, $crlf)
+ $this->$CG_HANDLERS[$format]($db, $table, $crlf, $aliases)
);
}
return PMA_exportOutputHandler(sprintf("%s is not supported.", $format));
@@ -234,14 +238,18 @@ class ExportCodegen extends ExportPlugin
/**
* C# Handler
*
- * @param string $db database name
- * @param string $table table name
- * @param string $crlf line separator
+ * @param string $db database name
+ * @param string $table table name
+ * @param string $crlf line separator
+ * @param array $aliases Aliases of db/table/columns
*
* @return string containing C# code lines, separated by "\n"
*/
- private function _handleNHibernateCSBody($db, $table, $crlf)
+ private function _handleNHibernateCSBody($db, $table, $crlf, $aliases = array())
{
+ $db_alias = $db;
+ $table_alias = $table;
+ $this->initAlias($aliases, $db_alias, $table_alias);
$lines = array();
$result = $GLOBALS['dbi']->query(
@@ -253,6 +261,10 @@ class ExportCodegen extends ExportPlugin
if ($result) {
$tableProperties = array();
while ($row = $GLOBALS['dbi']->fetchRow($result)) {
+ $col_as = $this->getAlias($aliases, $row[0], 'col', $db, $table);
+ if (!empty($col_as)) {
+ $row[0] = $col_as;
+ }
$tableProperties[] = new TableProperty($row);
}
$GLOBALS['dbi']->freeResult($result);
@@ -260,10 +272,12 @@ class ExportCodegen extends ExportPlugin
$lines[] = 'using System.Collections;';
$lines[] = 'using System.Collections.Generic;';
$lines[] = 'using System.Text;';
- $lines[] = 'namespace ' . ExportCodegen::cgMakeIdentifier($db);
+ $lines[] = 'namespace ' . ExportCodegen::cgMakeIdentifier($db_alias);
$lines[] = '{';
- $lines[] = ' #region ' . ExportCodegen::cgMakeIdentifier($table);
- $lines[] = ' public class ' . ExportCodegen::cgMakeIdentifier($table);
+ $lines[] = ' #region '
+ . ExportCodegen::cgMakeIdentifier($table_alias);
+ $lines[] = ' public class '
+ . ExportCodegen::cgMakeIdentifier($table_alias);
$lines[] = ' {';
$lines[] = ' #region Member Variables';
foreach ($tableProperties as $tableProperty) {
@@ -274,7 +288,7 @@ class ExportCodegen extends ExportPlugin
$lines[] = ' #endregion';
$lines[] = ' #region Constructors';
$lines[] = ' public '
- . ExportCodegen::cgMakeIdentifier($table) . '() { }';
+ . ExportCodegen::cgMakeIdentifier($table_alias) . '() { }';
$temp = array();
foreach ($tableProperties as $tableProperty) {
if (! $tableProperty->isPK()) {
@@ -284,7 +298,7 @@ class ExportCodegen extends ExportPlugin
}
}
$lines[] = ' public '
- . ExportCodegen::cgMakeIdentifier($table)
+ . ExportCodegen::cgMakeIdentifier($table_alias)
. '('
. implode(', ', $temp)
. ')';
@@ -314,28 +328,33 @@ class ExportCodegen extends ExportPlugin
$lines[] = ' #endregion';
$lines[] = '}';
}
- return implode("\n", $lines);
+ return implode($crlf, $lines);
}
/**
* XML Handler
*
- * @param string $db database name
- * @param string $table table name
- * @param string $crlf line separator
+ * @param string $db database name
+ * @param string $table table name
+ * @param string $crlf line separator
+ * @param array $aliases Aliases of db/table/columns
*
* @return string containing XML code lines, separated by "\n"
*/
- private function _handleNHibernateXMLBody($db, $table, $crlf)
- {
+ private function _handleNHibernateXMLBody(
+ $db, $table, $crlf, $aliases = array()
+ ) {
+ $db_alias = $db;
+ $table_alias = $table;
+ $this->initAlias($aliases, $db_alias, $table_alias);
$lines = array();
$lines[] = '';
$lines[] = '
| ' - . (isset($res_rel[$field_name]) - ? htmlspecialchars( - $res_rel[$field_name]['foreign_table'] - . ' (' . $res_rel[$field_name]['foreign_field'] - . ')' + . htmlspecialchars( + $this->getRelationString( + $res_rel, $field_name, $db, $aliases ) - : '') . ' | '; + ) + . ''; } if ($do_comments && $cfgRelation['commwork']) { $schema_insert .= ''
@@ -530,6 +555,7 @@ class ExportHtmlword extends ExportPlugin
* export types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
+ * @param array $aliases Aliases of db/table/columns
*
* @return bool Whether it succeeded
*/
@@ -543,18 +569,24 @@ class ExportHtmlword extends ExportPlugin
$do_relation = false,
$do_comments = false,
$do_mime = false,
- $dates = false
+ $dates = false,
+ $aliases = array()
) {
+ $db_alias = $db;
+ $table_alias = $table;
+ $this->initAlias($aliases, $db_alias, $table_alias);
+
$dump = '';
switch($export_mode) {
case 'create_table':
$dump .= '' - . __('Table structure for table') . ' ' . htmlspecialchars($table) + . __('Table structure for table') . ' ' + . htmlspecialchars($table_alias) . ''; $dump .= $this->getTableDef( $db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, - $dates + $dates, true, false, $aliases ); break; case 'triggers': @@ -562,26 +594,27 @@ class ExportHtmlword extends ExportPlugin $triggers = $GLOBALS['dbi']->getTriggers($db, $table); if ($triggers) { $dump .= '' - . __('Triggers') . ' ' . htmlspecialchars($table) + . __('Triggers') . ' ' . htmlspecialchars($table_alias) . ''; $dump .= $this->getTriggers($db, $table); } break; case 'create_view': $dump .= '' - . __('Structure for view') . ' ' . htmlspecialchars($table) + . __('Structure for view') . ' ' . htmlspecialchars($table_alias) . ''; $dump .= $this->getTableDef( $db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, - $dates, true, true + $dates, true, true, $aliases ); break; case 'stand_in': $dump .= '' - . __('Stand-in structure for view') . ' ' . htmlspecialchars($table) + . __('Stand-in structure for view') . ' ' + . htmlspecialchars($table_alias) . ''; // export a stand-in definition to resolve view dependencies - $dump .= $this->getTableDefStandIn($db, $table, $crlf); + $dump .= $this->getTableDefStandIn($db, $table, $crlf, $aliases); } // end switch return PMA_exportOutputHandler($dump); @@ -590,14 +623,18 @@ class ExportHtmlword extends ExportPlugin /** * Formats the definition for one column * - * @param array $column info about this column - * @param array $unique_keys unique keys of the table + * @param array $column info about this column + * @param array $unique_keys unique keys of the table + * @param string $col_alias Column Alias * * @return string Formatted column definition */ protected function formatOneColumnDefinition( - $column, $unique_keys + $column, $unique_keys, $col_alias = '' ) { + if (empty($col_alias)) { + $col_alias = $column['Field']; + } $definition = ' | |
| ' . $fmt_pre - . htmlspecialchars($column['Field']) . $fmt_post . ' | '; + . htmlspecialchars($col_alias) . $fmt_post . ''; $definition .= '' . htmlspecialchars($type) . ' | '; $definition .= ''
diff --git a/libraries/plugins/export/ExportJson.class.php b/libraries/plugins/export/ExportJson.class.php
index 1db77617a9..f60ee77b04 100644
--- a/libraries/plugins/export/ExportJson.class.php
+++ b/libraries/plugins/export/ExportJson.class.php
@@ -111,13 +111,19 @@ class ExportJson extends ExportPlugin
/**
* Outputs database header
*
- * @param string $db Database name
+ * @param string $db Database name
+ * @param string $db_alias Aliases of db
*
* @return bool Whether it succeeded
*/
- public function exportDBHeader ($db)
+ public function exportDBHeader ($db, $db_alias = '')
{
- PMA_exportOutputHandler('// Database \'' . $db . '\'' . $GLOBALS['crlf']);
+ if (empty($db_alias)) {
+ $db_alias = $db;
+ }
+ PMA_exportOutputHandler(
+ '// Database \'' . $db_alias . '\'' . $GLOBALS['crlf']
+ );
return true;
}
@@ -136,11 +142,12 @@ class ExportJson extends ExportPlugin
/**
* Outputs CREATE DATABASE statement
*
- * @param string $db Database name
+ * @param string $db Database name
+ * @param string $db_alias Aliases of db
*
* @return bool Whether it succeeded
*/
- public function exportDBCreate($db)
+ public function exportDBCreate($db, $db_alias = '')
{
return true;
}
@@ -153,11 +160,17 @@ class ExportJson extends ExportPlugin
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
+ * @param array $aliases Aliases of db/table/columns
*
* @return bool Whether it succeeded
*/
- public function exportData($db, $table, $crlf, $error_url, $sql_query)
- {
+ public function exportData(
+ $db, $table, $crlf, $error_url, $sql_query, $aliases = array()
+ ) {
+ $db_alias = $db;
+ $table_alias = $table;
+ $this->initAlias($aliases, $db_alias, $table_alias);
+
$result = $GLOBALS['dbi']->query(
$sql_query, null, PMA_DatabaseInterface::QUERY_UNBUFFERED
);
@@ -165,9 +178,12 @@ class ExportJson extends ExportPlugin
$columns = array();
for ($i = 0; $i < $columns_cnt; $i++) {
- $columns[$i] = stripslashes($GLOBALS['dbi']->fieldName($result, $i));
+ $col_as = $GLOBALS['dbi']->fieldName($result, $i);
+ if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
+ $col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
+ }
+ $columns[$i] = stripslashes($col_as);
}
- unset($i);
$buffer = '';
$record_cnt = 0;
@@ -177,7 +193,8 @@ class ExportJson extends ExportPlugin
// Output table name as comment if this is the first record of the table
if ($record_cnt == 1) {
- $buffer = '// ' . $db . '.' . $table . $crlf . $crlf;
+ $buffer = $crlf . '// ' . $db_alias . '.' . $table_alias
+ . $crlf . $crlf;
$buffer .= '[';
} else {
$buffer = ', ';
@@ -199,7 +216,7 @@ class ExportJson extends ExportPlugin
}
if ($record_cnt) {
- if (! PMA_exportOutputHandler(']')) {
+ if (! PMA_exportOutputHandler(']' . $crlf)) {
return false;
}
}
diff --git a/libraries/plugins/export/ExportLatex.class.php b/libraries/plugins/export/ExportLatex.class.php
index 70f1f4b0a2..fc454bbf76 100644
--- a/libraries/plugins/export/ExportLatex.class.php
+++ b/libraries/plugins/export/ExportLatex.class.php
@@ -240,15 +240,19 @@ class ExportLatex extends ExportPlugin
/**
* Outputs database header
*
- * @param string $db Database name
+ * @param string $db Database name
+ * @param string $db_alias Aliases of db
*
* @return bool Whether it succeeded
*/
- public function exportDBHeader ($db)
+ public function exportDBHeader ($db, $db_alias = '')
{
+ if (empty($db_alias)) {
+ $db_alias = $db;
+ }
global $crlf;
$head = '% ' . $crlf
- . '% ' . __('Database:') . ' ' . '\'' . $db . '\'' . $crlf
+ . '% ' . __('Database:') . ' ' . '\'' . $db_alias . '\'' . $crlf
. '% ' . $crlf;
return PMA_exportOutputHandler($head);
}
@@ -268,11 +272,12 @@ class ExportLatex extends ExportPlugin
/**
* Outputs CREATE DATABASE statement
*
- * @param string $db Database name
+ * @param string $db Database name
+ * @param string $db_alias Aliases of db
*
* @return bool Whether it succeeded
*/
- public function exportDBCreate($db)
+ public function exportDBCreate($db, $db_alias = '')
{
return true;
}
@@ -285,23 +290,33 @@ class ExportLatex extends ExportPlugin
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
+ * @param array $aliases Aliases of db/table/columns
*
* @return bool Whether it succeeded
*/
- public function exportData($db, $table, $crlf, $error_url, $sql_query)
- {
+ public function exportData(
+ $db, $table, $crlf, $error_url, $sql_query, $aliases = array()
+ ) {
+ $db_alias = $db;
+ $table_alias = $table;
+ $this->initAlias($aliases, $db_alias, $table_alias);
+
$result = $GLOBALS['dbi']->tryQuery(
$sql_query, null, PMA_DatabaseInterface::QUERY_UNBUFFERED
);
$columns_cnt = $GLOBALS['dbi']->numFields($result);
$columns = array();
+ $columns_alias = array();
for ($i = 0; $i < $columns_cnt; $i++) {
- $columns[$i] = $GLOBALS['dbi']->fieldName($result, $i);
+ $columns[$i] = $col_as = $GLOBALS['dbi']->fieldName($result, $i);
+ if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
+ $col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
+ }
+ $columns_alias[$i] = $col_as;
}
- unset($i);
- $buffer = $crlf . '%' . $crlf . '% ' . __('Data:') . ' ' . $table
+ $buffer = $crlf . '%' . $crlf . '% ' . __('Data:') . ' ' . $table_alias
. $crlf . '%' . $crlf . ' \\begin{longtable}{|';
for ($index = 0; $index < $columns_cnt; $index++) {
@@ -319,13 +334,13 @@ class ExportLatex extends ExportPlugin
get_class($this),
'libraries/plugins/export/' . get_class($this) . ".class.php"
),
- array('table' => $table, 'database' => $db)
+ array('table' => $table_alias, 'database' => $db_alias)
)
. '} \\label{'
. PMA_Util::expandUserString(
$GLOBALS['latex_data_label'],
null,
- array('table' => $table, 'database' => $db)
+ array('table' => $table_alias, 'database' => $db_alias)
)
. '} \\\\';
}
@@ -338,7 +353,7 @@ class ExportLatex extends ExportPlugin
$buffer = '\\hline ';
for ($i = 0; $i < $columns_cnt; $i++) {
$buffer .= '\\multicolumn{1}{|c|}{\\textbf{'
- . self::texEscape(stripslashes($columns[$i])) . '}} & ';
+ . self::texEscape(stripslashes($columns_alias[$i])) . '}} & ';
}
$buffer = substr($buffer, 0, -2) . '\\\\ \\hline \hline ';
@@ -356,7 +371,7 @@ class ExportLatex extends ExportPlugin
'libraries/plugins/export/'
. get_class($this) . ".class.php"
),
- array('table' => $table, 'database' => $db)
+ array('table' => $table_alias, 'database' => $db_alias)
)
. '} \\\\ '
)) {
@@ -429,6 +444,7 @@ class ExportLatex extends ExportPlugin
* export types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
+ * @param array $aliases Aliases of db/table/columns
*
* @return bool Whether it succeeded
*/
@@ -442,8 +458,13 @@ class ExportLatex extends ExportPlugin
$do_relation = false,
$do_comments = false,
$do_mime = false,
- $dates = false
+ $dates = false,
+ $aliases = array()
) {
+ $db_alias = $db;
+ $table_alias = $table;
+ $this->initAlias($aliases, $db_alias, $table_alias);
+
global $cfgRelation;
/* We do not export triggers */
@@ -466,7 +487,7 @@ class ExportLatex extends ExportPlugin
* Gets fields properties
*/
$GLOBALS['dbi']->selectDb($db);
-
+ $res_rel = array();
// Check if we can use Relations
if ($do_relation && ! empty($cfgRelation['relation'])) {
// Find which tables are related with the current one and write it in
@@ -485,8 +506,8 @@ class ExportLatex extends ExportPlugin
/**
* Displays the table structure
*/
- $buffer = $crlf . '%' . $crlf . '% ' . __('Structure:') . ' ' . $table
- . $crlf . '%' . $crlf . ' \\begin{longtable}{';
+ $buffer = $crlf . '%' . $crlf . '% ' . __('Structure:') . ' '
+ . $table_alias . $crlf . '%' . $crlf . ' \\begin{longtable}{';
if (! PMA_exportOutputHandler($buffer)) {
return false;
}
@@ -534,13 +555,13 @@ class ExportLatex extends ExportPlugin
get_class($this),
'libraries/plugins/export/' . get_class($this) . ".class.php"
),
- array('table' => $table, 'database' => $db)
+ array('table' => $table_alias, 'database' => $db_alias)
)
. '} \\label{'
. PMA_Util::expandUserString(
$GLOBALS['latex_structure_label'],
null,
- array('table' => $table, 'database' => $db)
+ array('table' => $table_alias, 'database' => $db_alias)
)
. '} \\\\' . $crlf;
}
@@ -556,7 +577,7 @@ class ExportLatex extends ExportPlugin
get_class($this),
'libraries/plugins/export/' . get_class($this) . ".class.php"
),
- array('table' => $table, 'database' => $db)
+ array('table' => $table_alias, 'database' => $db_alias)
)
. '} \\\\ ' . $crlf;
}
@@ -583,19 +604,21 @@ class ExportLatex extends ExportPlugin
}
}
- $field_name = $row['Field'];
+ $field_name = $col_as = $row['Field'];
+ if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
+ $col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
+ }
- $local_buffer = $field_name . "\000" . $type . "\000"
+ $local_buffer = $col_as . "\000" . $type . "\000"
. (($row['Null'] == '' || $row['Null'] == 'NO')
? __('No') : __('Yes'))
. "\000" . (isset($row['Default']) ? $row['Default'] : '');
if ($do_relation && $have_rel) {
$local_buffer .= "\000";
- if (isset($res_rel[$field_name])) {
- $local_buffer .= $res_rel[$field_name]['foreign_table'] . ' ('
- . $res_rel[$field_name]['foreign_field'] . ')';
- }
+ $local_buffer .= $this->getRelationString(
+ $res_rel, $field_name, $db, $aliases
+ );
}
if ($do_comments && $cfgRelation['commwork']) {
$local_buffer .= "\000";
diff --git a/libraries/plugins/export/ExportMediawiki.class.php b/libraries/plugins/export/ExportMediawiki.class.php
index e481ef0a3c..e32a046646 100644
--- a/libraries/plugins/export/ExportMediawiki.class.php
+++ b/libraries/plugins/export/ExportMediawiki.class.php
@@ -133,11 +133,12 @@ class ExportMediawiki extends ExportPlugin
/**
* Outputs database header
*
- * @param string $db Database name
+ * @param string $db Database name
+ * @param string $db_alias Alias of db
*
* @return bool Whether it succeeded
*/
- public function exportDBHeader ($db)
+ public function exportDBHeader ($db, $db_alias = '')
{
return true;
}
@@ -157,11 +158,12 @@ class ExportMediawiki extends ExportPlugin
/**
* Outputs CREATE DATABASE statement
*
- * @param string $db Database name
+ * @param string $db Database name
+ * @param string $db_alias Alias of db
*
* @return bool Whether it succeeded
*/
- public function exportDBCreate($db)
+ public function exportDBCreate($db, $db_alias = '')
{
return true;
}
@@ -185,6 +187,7 @@ class ExportMediawiki extends ExportPlugin
* parameter
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
+ * @param array $aliases Aliases of db/table/columns
*
* @return bool Whether it succeeded
*/
@@ -198,8 +201,13 @@ class ExportMediawiki extends ExportPlugin
$do_relation = false,
$do_comments = false,
$do_mime = false,
- $dates = false
+ $dates = false,
+ $aliases = array()
) {
+ $db_alias = $db;
+ $table_alias = $table;
+ $this->initAlias($aliases, $db_alias, $table_alias);
+
$output = '';
switch($export_mode) {
case 'create_table':
@@ -210,7 +218,7 @@ class ExportMediawiki extends ExportPlugin
// Print structure comment
$output = $this->_exportComment(
"Table structure for "
- . PMA_Util::backquote($table)
+ . PMA_Util::backquote($table_alias)
);
// Begin the table construction
@@ -219,7 +227,7 @@ class ExportMediawiki extends ExportPlugin
// Add the table name
if (isset($GLOBALS['mediawiki_caption'])) {
- $output .= "|+'''" . $table . "'''" . $this->_exportCRLF();
+ $output .= "|+'''" . $table_alias . "'''" . $this->_exportCRLF();
}
// Add the table headers
@@ -228,7 +236,13 @@ class ExportMediawiki extends ExportPlugin
$output .= "! style=\"background:#ffffff\" | "
. $this->_exportCRLF();
for ($i = 0; $i < $row_cnt; ++$i) {
- $output .= " | " . $columns[$i]['Field'] . $this->_exportCRLF();
+ $col_as = $columns[$i]['Field'];
+ if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])
+ ) {
+ $col_as
+ = $aliases[$db]['tables'][$table]['columns'][$col_as];
+ }
+ $output .= " | " . $col_as . $this->_exportCRLF();
}
}
@@ -272,6 +286,7 @@ class ExportMediawiki extends ExportPlugin
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
+ * @param array $aliases Aliases of db/table/columns
*
* @return bool Whether it succeeded
*/
@@ -280,11 +295,16 @@ class ExportMediawiki extends ExportPlugin
$table,
$crlf,
$error_url,
- $sql_query
+ $sql_query,
+ $aliases = array()
) {
+ $db_alias = $db;
+ $table_alias = $table;
+ $this->initAlias($aliases, $db_alias, $table_alias);
+
// Print data comment
$output = $this->_exportComment(
- "Table data for " . PMA_Util::backquote($table)
+ "Table data for " . PMA_Util::backquote($table_alias)
);
// Begin the table construction
@@ -295,7 +315,7 @@ class ExportMediawiki extends ExportPlugin
// Add the table name
if (isset($GLOBALS['mediawiki_caption'])) {
- $output .= "|+'''" . $table . "'''" . $this->_exportCRLF();
+ $output .= "|+'''" . $table_alias . "'''" . $this->_exportCRLF();
}
// Add the table headers
@@ -310,6 +330,11 @@ class ExportMediawiki extends ExportPlugin
// Use '!' for separating table headers
foreach ($column_names as $column) {
+ if (!empty($aliases[$db]['tables'][$table]['columns'][$column])
+ ) {
+ $column
+ = $aliases[$db]['tables'][$table]['columns'][$column];
+ }
$output .= " ! " . $column . "" . $this->_exportCRLF();
}
}
diff --git a/libraries/plugins/export/ExportOds.class.php b/libraries/plugins/export/ExportOds.class.php
index d5fcda715f..ead16f68c0 100644
--- a/libraries/plugins/export/ExportOds.class.php
+++ b/libraries/plugins/export/ExportOds.class.php
@@ -177,11 +177,12 @@ class ExportOds extends ExportPlugin
/**
* Outputs database header
*
- * @param string $db Database name
+ * @param string $db Database name
+ * @param string $db_alias Aliases of db
*
* @return bool Whether it succeeded
*/
- public function exportDBHeader ($db)
+ public function exportDBHeader ($db, $db_alias = '')
{
return true;
}
@@ -201,11 +202,12 @@ class ExportOds extends ExportPlugin
/**
* Outputs CREATE DATABASE statement
*
- * @param string $db Database name
+ * @param string $db Database name
+ * @param string $db_alias Aliases of db
*
* @return bool Whether it succeeded
*/
- public function exportDBCreate($db)
+ public function exportDBCreate($db, $db_alias = '')
{
return true;
}
@@ -218,13 +220,18 @@ class ExportOds extends ExportPlugin
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
+ * @param array $aliases Aliases of db/table/columns
*
* @return bool Whether it succeeded
*/
- public function exportData($db, $table, $crlf, $error_url, $sql_query)
- {
+ public function exportData(
+ $db, $table, $crlf, $error_url, $sql_query, $aliases = array()
+ ) {
global $what;
+ $db_alias = $db;
+ $table_alias = $table;
+ $this->initAlias($aliases, $db_alias, $table_alias);
// Gets the data from the database
$result = $GLOBALS['dbi']->query(
$sql_query, null, PMA_DatabaseInterface::QUERY_UNBUFFERED
@@ -237,17 +244,21 @@ class ExportOds extends ExportPlugin
}
$GLOBALS['ods_buffer'] .=
- ' |