Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2014-06-18 16:21:04 +02:00
commit d1f4b2d70e
22 changed files with 723 additions and 364 deletions

View File

@ -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;
}
}
?>
?>

View File

@ -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[] = '<?xml version="1.0" encoding="utf-8" ?' . '>';
$lines[] = '<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" '
. 'namespace="' . ExportCodegen::cgMakeIdentifier($db) . '" '
. 'assembly="' . ExportCodegen::cgMakeIdentifier($db) . '">';
. 'namespace="' . ExportCodegen::cgMakeIdentifier($db_alias) . '" '
. 'assembly="' . ExportCodegen::cgMakeIdentifier($db_alias) . '">';
$lines[] = ' <class '
. 'name="' . ExportCodegen::cgMakeIdentifier($table) . '" '
. 'table="' . ExportCodegen::cgMakeIdentifier($table) . '">';
. 'name="' . ExportCodegen::cgMakeIdentifier($table_alias) . '" '
. 'table="' . ExportCodegen::cgMakeIdentifier($table_alias) . '">';
$result = $GLOBALS['dbi']->query(
sprintf(
"DESC %s.%s", PMA_Util::backquote($db),
@ -344,6 +363,10 @@ class ExportCodegen extends ExportPlugin
);
if ($result) {
while ($row = $GLOBALS['dbi']->fetchRow($result)) {
$col_as = $this->getAlias($aliases, $row[0], 'col', $db, $table);
if (!empty($col_as)) {
$row[0] = $col_as;
}
$tableProperty = new TableProperty($row);
if ($tableProperty->isPK()) {
$lines[] = $tableProperty->formatXml(
@ -369,7 +392,7 @@ class ExportCodegen extends ExportPlugin
}
$lines[] = ' </class>';
$lines[] = '</hibernate-mapping>';
return implode("\n", $lines);
return implode($crlf, $lines);
}

View File

@ -170,11 +170,12 @@ class ExportCsv 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;
}
@ -194,11 +195,12 @@ class ExportCsv 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;
}
@ -211,13 +213,19 @@ class ExportCsv 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, $csv_terminated, $csv_separator, $csv_enclosed, $csv_escaped;
$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
@ -228,16 +236,19 @@ class ExportCsv extends ExportPlugin
if (isset($GLOBALS['csv_columns'])) {
$schema_insert = '';
for ($i = 0; $i < $fields_cnt; $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];
}
$col_as = stripslashes($col_as);
if ($csv_enclosed == '') {
$schema_insert .= stripslashes(
$GLOBALS['dbi']->fieldName($result, $i)
);
$schema_insert .= $col_as;
} else {
$schema_insert .= $csv_enclosed
. str_replace(
$csv_enclosed,
$csv_escaped . $csv_enclosed,
stripslashes($GLOBALS['dbi']->fieldName($result, $i))
$col_as
)
. $csv_enclosed;
}

View File

@ -148,14 +148,18 @@ class ExportHtmlword 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;
}
return PMA_exportOutputHandler(
'<h1>' . __('Database') . ' ' . htmlspecialchars($db) . '</h1>'
'<h1>' . __('Database') . ' ' . htmlspecialchars($db_alias) . '</h1>'
);
}
@ -174,11 +178,12 @@ class ExportHtmlword 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;
}
@ -191,16 +196,22 @@ class ExportHtmlword 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);
if (! PMA_exportOutputHandler(
'<h2>'
. __('Dumping data for table') . ' ' . htmlspecialchars($table)
. __('Dumping data for table') . ' ' . htmlspecialchars($table_alias)
. '</h2>'
)) {
return false;
@ -221,10 +232,13 @@ class ExportHtmlword extends ExportPlugin
if (isset($GLOBALS['htmlword_columns'])) {
$schema_insert = '<tr class="print-category">';
for ($i = 0; $i < $fields_cnt; $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];
}
$col_as = stripslashes($col_as);
$schema_insert .= '<td class="print"><strong>'
. htmlspecialchars(
stripslashes($GLOBALS['dbi']->fieldName($result, $i))
)
. htmlspecialchars($col_as)
. '</strong></td>';
} // end for
$schema_insert .= '</tr>';
@ -264,13 +278,14 @@ class ExportHtmlword extends ExportPlugin
/**
* 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())
{
$schema_insert = '<table class="width100" cellspacing="1">'
. '<tr class="print-category">'
@ -301,9 +316,14 @@ class ExportHtmlword extends ExportPlugin
$columns = $GLOBALS['dbi']->getColumns($db, $view);
foreach ($columns as $column) {
$col_as = $column['Field'];
if (!empty($aliases[$db]['tables'][$view]['columns'][$col_as])) {
$col_as = $aliases[$db]['tables'][$view]['columns'][$col_as];
}
$schema_insert .= $this->formatOneColumnDefinition(
$column,
$unique_keys
$unique_keys,
$col_as
);
$schema_insert .= '</tr>';
}
@ -331,6 +351,7 @@ class ExportHtmlword extends ExportPlugin
* @param bool $add_semicolon whether to add semicolon and end-of-line
* at the end
* @param bool $view whether we're handling a view
* @param array $aliases Aliases of db/table/columns
*
* @return string resulting schema
*/
@ -344,7 +365,8 @@ class ExportHtmlword extends ExportPlugin
$do_mime,
$show_dates = false,
$add_semicolon = true,
$view = false
$view = false,
$aliases = array()
) {
// set $cfgRelation here, because there is a chance that it's modified
// since the class initialization
@ -356,7 +378,7 @@ class ExportHtmlword 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
@ -432,21 +454,24 @@ class ExportHtmlword extends ExportPlugin
}
}
foreach ($columns as $column) {
$col_as = $column['Field'];
if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
}
$schema_insert .= $this->formatOneColumnDefinition(
$column,
$unique_keys
$unique_keys,
$col_as
);
$field_name = $column['Field'];
if ($do_relation && $have_rel) {
$schema_insert .= '<td class="print">'
. (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
)
: '') . '</td>';
)
. '</td>';
}
if ($do_comments && $cfgRelation['commwork']) {
$schema_insert .= '<td class="print">'
@ -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 .= '<h2>'
. __('Table structure for table') . ' ' . htmlspecialchars($table)
. __('Table structure for table') . ' '
. htmlspecialchars($table_alias)
. '</h2>';
$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 .= '<h2>'
. __('Triggers') . ' ' . htmlspecialchars($table)
. __('Triggers') . ' ' . htmlspecialchars($table_alias)
. '</h2>';
$dump .= $this->getTriggers($db, $table);
}
break;
case 'create_view':
$dump .= '<h2>'
. __('Structure for view') . ' ' . htmlspecialchars($table)
. __('Structure for view') . ' ' . htmlspecialchars($table_alias)
. '</h2>';
$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 .= '<h2>'
. __('Stand-in structure for view') . ' ' . htmlspecialchars($table)
. __('Stand-in structure for view') . ' '
. htmlspecialchars($table_alias)
. '</h2>';
// 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 = '<tr class="print-category">';
$extracted_columnspec
@ -625,7 +662,7 @@ class ExportHtmlword extends ExportPlugin
$fmt_post = $fmt_post . '</em>';
}
$definition .= '<td class="print">' . $fmt_pre
. htmlspecialchars($column['Field']) . $fmt_post . '</td>';
. htmlspecialchars($col_alias) . $fmt_post . '</td>';
$definition .= '<td class="print">' . htmlspecialchars($type)
. '</td>';
$definition .= '<td class="print">'

View File

@ -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;
}
}

View File

@ -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";

View File

@ -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();
}
}

View File

@ -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'] .=
'<table:table table:name="' . htmlspecialchars($table) . '">';
'<table:table table:name="' . htmlspecialchars($table_alias) . '">';
// If required, get fields name at the first line
if (isset($GLOBALS[$what . '_columns'])) {
$GLOBALS['ods_buffer'] .= '<table:table-row>';
for ($i = 0; $i < $fields_cnt; $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];
}
$GLOBALS['ods_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p>'
. htmlspecialchars(
stripslashes($GLOBALS['dbi']->fieldName($result, $i))
stripslashes($col_as)
)
. '</text:p>'
. '</table:table-cell>';

View File

@ -190,16 +190,20 @@ class ExportOdt 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;
}
$GLOBALS['odt_buffer'] .=
'<text:h text:outline-level="1" text:style-name="Heading_1"'
. ' text:is-list-header="true">'
. __('Database') . ' ' . htmlspecialchars($db)
. __('Database') . ' ' . htmlspecialchars($db_alias)
. '</text:h>';
return true;
}
@ -219,11 +223,12 @@ class ExportOdt 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;
}
@ -235,13 +240,18 @@ class ExportOdt 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
@ -256,10 +266,10 @@ class ExportOdt extends ExportPlugin
$GLOBALS['odt_buffer'] .=
'<text:h text:outline-level="2" text:style-name="Heading_2"'
. ' text:is-list-header="true">'
. __('Dumping data for table') . ' ' . htmlspecialchars($table)
. __('Dumping data for table') . ' ' . htmlspecialchars($table_alias)
. '</text:h>'
. '<table:table'
. ' table:name="' . htmlspecialchars($table) . '_structure">'
. ' table:name="' . htmlspecialchars($table_alias) . '_structure">'
. '<table:table-column'
. ' table:number-columns-repeated="' . $fields_cnt . '"/>';
@ -267,11 +277,15 @@ class ExportOdt extends ExportPlugin
if (isset($GLOBALS[$what . '_columns'])) {
$GLOBALS['odt_buffer'] .= '<table:table-row>';
for ($i = 0; $i < $fields_cnt; $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];
}
$GLOBALS['odt_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p>'
. htmlspecialchars(
stripslashes($GLOBALS['dbi']->fieldName($result, $i))
stripslashes($col_as)
)
. '</text:p>'
. '</table:table-cell>';
@ -330,14 +344,18 @@ class ExportOdt extends ExportPlugin
/**
* 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 bool true
* @return string resulting definition
*/
public function getTableDefStandIn($db, $view, $crlf)
public function getTableDefStandIn($db, $view, $crlf, $aliases = array())
{
$db_alias = $db;
$view_alias = $view;
$this->initAlias($aliases, $db_alias, $view_alias);
/**
* Gets fields properties
*/
@ -348,7 +366,7 @@ class ExportOdt extends ExportPlugin
*/
$GLOBALS['odt_buffer'] .=
'<table:table table:name="'
. htmlspecialchars($view) . '_data">';
. htmlspecialchars($view_alias) . '_data">';
$columns_cnt = 4;
$GLOBALS['odt_buffer'] .=
'<table:table-column'
@ -371,7 +389,13 @@ class ExportOdt extends ExportPlugin
$columns = $GLOBALS['dbi']->getColumns($db, $view);
foreach ($columns as $column) {
$GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column);
$col_as = $column['Field'];
if (!empty($aliases[$db]['tables'][$view]['columns'][$col_as])) {
$col_as = $aliases[$db]['tables'][$view]['columns'][$col_as];
}
$GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition(
$column, $col_as
);
$GLOBALS['odt_buffer'] .= '</table:table-row>';
} // end foreach
@ -397,6 +421,7 @@ class ExportOdt extends ExportPlugin
* @param bool $add_semicolon whether to add semicolon and end-of-line at
* the end
* @param bool $view whether we're handling a view
* @param array $aliases Aliases of db/table/columns
*
* @return bool true
*/
@ -410,10 +435,14 @@ class ExportOdt extends ExportPlugin
$do_mime,
$show_dates = false,
$add_semicolon = true,
$view = false
$view = false,
$aliases = array()
) {
global $cfgRelation;
$db_alias = $db;
$table_alias = $table;
$this->initAlias($aliases, $db_alias, $table_alias);
/**
* Gets fields properties
*/
@ -438,7 +467,7 @@ class ExportOdt extends ExportPlugin
* Displays the table structure
*/
$GLOBALS['odt_buffer'] .= '<table:table table:name="'
. htmlspecialchars($table) . '_structure">';
. htmlspecialchars($table_alias) . '_structure">';
$columns_cnt = 4;
if ($do_relation && $have_rel) {
$columns_cnt++;
@ -486,18 +515,30 @@ class ExportOdt extends ExportPlugin
$columns = $GLOBALS['dbi']->getColumns($db, $table);
foreach ($columns as $column) {
$field_name = $column['Field'];
$GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column);
$col_as = $field_name = $column['Field'];
if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
}
$GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition(
$column, $col_as
);
if ($do_relation && $have_rel) {
if (isset($res_rel[$field_name])) {
$rtable = $res_rel[$field_name]['foreign_table'];
$rfield = $res_rel[$field_name]['foreign_field'];
if (!empty($aliases[$db]['tables'][$rtable]['columns'][$rfield])
) {
$rfield
= $aliases[$db]['tables'][$rtable]['columns'][$rfield];
}
if (!empty($aliases[$db]['tables'][$rtable]['alias'])) {
$rtable = $aliases[$db]['tables'][$rtable]['alias'];
}
$relation = htmlspecialchars($rtable . ' (' . $rfield . ')');
$GLOBALS['odt_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p>'
. htmlspecialchars(
$res_rel[$field_name]['foreign_table']
. ' (' . $res_rel[$field_name]['foreign_field'] . ')'
)
. htmlspecialchars($relation)
. '</text:p>'
. '</table:table-cell>';
}
@ -544,15 +585,19 @@ class ExportOdt extends ExportPlugin
/**
* Outputs triggers
*
* @param string $db database name
* @param string $table table name
* @param string $db database name
* @param string $table table name
* @param array $aliases Aliases of db/table/columns
*
* @return bool true
*/
protected function getTriggers($db, $table)
protected function getTriggers($db, $table, $aliases = array())
{
$db_alias = $db;
$table_alias = $table;
$this->initAlias($aliases, $db_alias, $table_alias);
$GLOBALS['odt_buffer'] .= '<table:table'
. ' table:name="' . htmlspecialchars($table) . '_triggers">'
. ' table:name="' . htmlspecialchars($table_alias) . '_triggers">'
. '<table:table-column'
. ' table:number-columns-repeated="4"/>'
. '<table:table-row>'
@ -619,6 +664,7 @@ class ExportOdt extends ExportPlugin
* PMA_exportStructure() also for other
* @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
*/
@ -632,29 +678,33 @@ class ExportOdt 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);
switch($export_mode) {
case 'create_table':
$GLOBALS['odt_buffer'] .=
'<text:h text:outline-level="2" text:style-name="Heading_2"'
. ' text:is-list-header="true">'
. __('Table structure for table') . ' ' .
htmlspecialchars($table)
htmlspecialchars($table_alias)
. '</text:h>';
$this->getTableDef(
$db, $table, $crlf, $error_url, $do_relation, $do_comments,
$do_mime, $dates
$do_mime, $dates, true, false, $aliases
);
break;
case 'triggers':
$triggers = $GLOBALS['dbi']->getTriggers($db, $table);
$triggers = $GLOBALS['dbi']->getTriggers($db, $table, $aliases);
if ($triggers) {
$GLOBALS['odt_buffer'] .=
'<text:h text:outline-level="2" text:style-name="Heading_2"'
. ' text:is-list-header="true">'
. __('Triggers') . ' '
. htmlspecialchars($table)
. htmlspecialchars($table_alias)
. '</text:h>';
$this->getTriggers($db, $table);
}
@ -664,11 +714,11 @@ class ExportOdt extends ExportPlugin
'<text:h text:outline-level="2" text:style-name="Heading_2"'
. ' text:is-list-header="true">'
. __('Structure for view') . ' '
. htmlspecialchars($table)
. htmlspecialchars($table_alias)
. '</text:h>';
$this->getTableDef(
$db, $table, $crlf, $error_url, $do_relation, $do_comments,
$do_mime, $dates, true, true
$do_mime, $dates, true, true, $aliases
);
break;
case 'stand_in':
@ -676,10 +726,10 @@ class ExportOdt extends ExportPlugin
'<text:h text:outline-level="2" text:style-name="Heading_2"'
. ' text:is-list-header="true">'
. __('Stand-in structure for view') . ' '
. htmlspecialchars($table)
. htmlspecialchars($table_alias)
. '</text:h>';
// export a stand-in definition to resolve view dependencies
$this->getTableDefStandIn($db, $table, $crlf);
$this->getTableDefStandIn($db, $table, $crlf, $aliases);
} // end switch
return true;
@ -688,16 +738,19 @@ class ExportOdt extends ExportPlugin
/**
* Formats the definition for one column
*
* @param array $column info about this column
* @param array $column info about this column
* @param string $col_as column alias
*
* @return string Formatted column definition
*/
protected function formatOneColumnDefinition($column)
protected function formatOneColumnDefinition($column, $col_as = '')
{
$field_name = $column['Field'];
if (empty($col_as)) {
$col_as = $column['Field'];
}
$definition = '<table:table-row>';
$definition .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($field_name) . '</text:p>'
. '<text:p>' . htmlspecialchars($col_as) . '</text:p>'
. '</table:table-cell>';
$extracted_columnspec

View File

@ -171,11 +171,12 @@ class ExportPdf 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;
}
@ -195,11 +196,12 @@ class ExportPdf 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;
}
@ -211,14 +213,23 @@ class ExportPdf 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);
$pdf = $this->_getPdf();
$attr = array('currentDb' => $db, 'currentTable' => $table);
$attr = array(
'currentDb' => $db, 'currentTable' => $table,
'dbAlias' => $db_alias, 'tableAlias' => $table_alias,
'aliases' => $aliases
);
$pdf->setAttributes($attr);
$pdf->mysqlReport($sql_query);

View File

@ -112,15 +112,19 @@ class ExportPhparray 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;
}
PMA_exportOutputHandler(
'//' . $GLOBALS['crlf']
. '// Database ' . PMA_Util::backquote($db)
. '// Database ' . PMA_Util::backquote($db_alias)
. $GLOBALS['crlf'] . '//' . $GLOBALS['crlf']
);
return true;
@ -141,11 +145,12 @@ class ExportPhparray 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;
}
@ -158,11 +163,17 @@ class ExportPhparray 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
);
@ -170,19 +181,24 @@ class ExportPhparray extends ExportPlugin
$columns_cnt = $GLOBALS['dbi']->numFields($result);
$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);
// fix variable names (based on
// http://www.php.net/manual/language.variables.basics.php)
if (! preg_match(
'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/',
$table
$table_alias
)) {
// fix invalid characters in variable names by replacing them with
// underscores
$tablefixed = preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '_', $table);
$tablefixed = preg_replace(
'/[^a-zA-Z0-9_\x7f-\xff]/', '_', $table_alias
);
// variable name must not start with a number or dash...
if (preg_match('/^[a-zA-Z_\x7f-\xff]/', $tablefixed) == false) {
@ -196,8 +212,8 @@ class ExportPhparray extends ExportPlugin
$record_cnt = 0;
// Output table name as comment
$buffer .= $crlf . '// '
. PMA_Util::backquote($db) . '.'
. PMA_Util::backquote($table) . $crlf;
. PMA_Util::backquote($db_alias) . '.'
. PMA_Util::backquote($table_alias) . $crlf;
$buffer .= '$' . $tablefixed . ' = array(';
while ($record = $GLOBALS['dbi']->fetchRow($result)) {

View File

@ -2536,65 +2536,4 @@ class ExportSql extends ExportPlugin
);
return $sql_query;
}
/**
* 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'];
}
}
/**
* recursively 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
*
* @return string alias of the identifier if found or ''
*/
public function getAlias($aliases, $id, $type = 'dbtblcol')
{
// 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'];
}
// 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'];
}
// 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 '';
}
}

View File

@ -132,14 +132,18 @@ class ExportTexytext 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 = '')
{
if (empty($db_alias)) {
$db_alias = $db;
}
return PMA_exportOutputHandler(
'===' . __('Database') . ' ' . $db . "\n\n"
'===' . __('Database') . ' ' . $db_alias . "\n\n"
);
}
@ -158,11 +162,12 @@ class ExportTexytext 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;
}
@ -174,15 +179,21 @@ class ExportTexytext 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);
if (! PMA_exportOutputHandler(
'== ' . __('Dumping data for table') . ' ' . $table . "\n\n"
'== ' . __('Dumping data for table') . ' ' . $table_alias . "\n\n"
)) {
return false;
}
@ -197,10 +208,12 @@ class ExportTexytext extends ExportPlugin
if (isset($GLOBALS[$what . '_columns'])) {
$text_output = "|------\n";
for ($i = 0; $i < $fields_cnt; $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];
}
$text_output .= '|'
. htmlspecialchars(
stripslashes($GLOBALS['dbi']->fieldName($result, $i))
);
. htmlspecialchars(stripslashes($col_as));
} // end for
$text_output .= "\n|------\n";
if (! PMA_exportOutputHandler($text_output)) {
@ -237,13 +250,14 @@ class ExportTexytext extends ExportPlugin
/**
* 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
*/
function getTableDefStandIn($db, $view, $crlf)
public function getTableDefStandIn($db, $view, $crlf, $aliases = array())
{
$text_output = '';
@ -276,7 +290,13 @@ class ExportTexytext extends ExportPlugin
$columns = $GLOBALS['dbi']->getColumns($db, $view);
foreach ($columns as $column) {
$text_output .= $this->formatOneColumnDefinition($column, $unique_keys);
$col_as = $column['Field'];
if (!empty($aliases[$db]['tables'][$view]['columns'][$col_as])) {
$col_as = $aliases[$db]['tables'][$view]['columns'][$col_as];
}
$text_output .= $this->formatOneColumnDefinition(
$column, $unique_keys, $col_as
);
$text_output .= "\n";
} // end foreach
@ -302,6 +322,7 @@ class ExportTexytext extends ExportPlugin
* @param bool $add_semicolon whether to add semicolon and end-of-line
* at the end
* @param bool $view whether we're handling a view
* @param array $aliases Aliases of db/table/columns
*
* @return string resulting schema
*/
@ -315,7 +336,8 @@ class ExportTexytext extends ExportPlugin
$do_mime,
$show_dates = false,
$add_semicolon = true,
$view = false
$view = false,
$aliases = array()
) {
global $cfgRelation;
@ -336,7 +358,7 @@ class ExportTexytext 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
@ -387,17 +409,18 @@ class ExportTexytext extends ExportPlugin
$columns = $GLOBALS['dbi']->getColumns($db, $table);
foreach ($columns as $column) {
$text_output .= $this->formatOneColumnDefinition($column, $unique_keys);
$col_as = $column['Field'];
if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
}
$text_output .= $this->formatOneColumnDefinition(
$column, $unique_keys, $col_as
);
$field_name = $column['Field'];
if ($do_relation && $have_rel) {
$text_output .= '|'
. (isset($res_rel[$field_name])
? htmlspecialchars(
$res_rel[$field_name]['foreign_table']
. ' (' . $res_rel[$field_name]['foreign_field'] . ')'
)
: '');
$text_output .= '|' . htmlspecialchars(
$this->getRelationString($res_rel, $field_name, $db, $aliases)
);
}
if ($do_comments && $cfgRelation['commwork']) {
$text_output .= '|'
@ -476,6 +499,7 @@ class ExportTexytext 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
*/
@ -489,38 +513,43 @@ class ExportTexytext 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') . ' ' . $table . "\n\n";
$dump .= '== ' . __('Table structure for table') . ' '
. $table_alias . "\n\n";
$dump .= $this->getTableDef(
$db, $table, $crlf, $error_url, $do_relation, $do_comments,
$do_mime, $dates
$do_mime, $dates, true, false, $aliases
);
break;
case 'triggers':
$dump = '';
$triggers = $GLOBALS['dbi']->getTriggers($db, $table);
if ($triggers) {
$dump .= '== ' . __('Triggers') . ' ' . $table . "\n\n";
$dump .= '== ' . __('Triggers') . ' ' . $table_alias . "\n\n";
$dump .= $this->getTriggers($db, $table);
}
break;
case 'create_view':
$dump .= '== ' . __('Structure for view') . ' ' . $table . "\n\n";
$dump .= '== ' . __('Structure for view') . ' ' . $table_alias . "\n\n";
$dump .= $this->getTableDef(
$db, $table, $crlf, $error_url, $do_relation, $do_comments,
$do_mime, $dates, true, true
$do_mime, $dates, true, true, $aliases
);
break;
case 'stand_in':
$dump .= '== ' . __('Stand-in structure for view')
. ' ' . $table . "\n\n";
// 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);
@ -529,14 +558,18 @@ class ExportTexytext extends ExportPlugin
/**
* Formats the definition for one column
*
* @param array $column info about this column
* @param array $unique_keys unique keys for this table
* @param array $column info about this column
* @param array $unique_keys unique keys for this table
* @param string $col_alias Column Alias
*
* @return string Formatted column definition
*/
function formatOneColumnDefinition(
$column, $unique_keys
$column, $unique_keys, $col_alias = ''
) {
if (empty($col_alias)) {
$col_alias = $column['Field'];
}
$extracted_columnspec
= PMA_Util::extractColumnSpec($column['Type']);
$type = $extracted_columnspec['print_type'];
@ -561,7 +594,7 @@ class ExportTexytext extends ExportPlugin
$fmt_post = $fmt_post . '//';
}
$definition = '|'
. $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post;
. $fmt_pre . htmlspecialchars($col_alias) . $fmt_post;
$definition .= '|' . htmlspecialchars($type);
$definition .= '|'
. (($column['Null'] == '' || $column['Null'] == 'NO')

View File

@ -383,21 +383,26 @@ class ExportXml 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 = '')
{
global $crlf;
if (empty($db_alias)) {
$db_alias = $db;
}
if (isset($GLOBALS['xml_export_contents'])
&& $GLOBALS['xml_export_contents']
) {
$head = ' <!--' . $crlf
. ' - ' . __('Database:') . ' ' . '\'' . $db . '\'' . $crlf
. ' -->' . $crlf
. ' <database name="' . htmlspecialchars($db) . '">' . $crlf;
. ' - ' . __('Database:') . ' ' . '\''
. $db_alias . '\'' . $crlf
. ' -->' . $crlf . ' <database name="'
. htmlspecialchars($db_alias) . '">' . $crlf;
return PMA_exportOutputHandler($head);
} else {
@ -428,11 +433,12 @@ class ExportXml 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;
}
@ -445,11 +451,16 @@ class ExportXml 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);
if (isset($GLOBALS['xml_export_contents'])
&& $GLOBALS['xml_export_contents']
) {
@ -464,22 +475,29 @@ class ExportXml extends ExportPlugin
}
unset($i);
$buffer = ' <!-- ' . __('Table') . ' ' . $table . ' -->' . $crlf;
$buffer = ' <!-- ' . __('Table') . ' '
. $table_alias . ' -->' . $crlf;
if (! PMA_exportOutputHandler($buffer)) {
return false;
}
while ($record = $GLOBALS['dbi']->fetchRow($result)) {
$buffer = ' <table name="'
. htmlspecialchars($table) . '">' . $crlf;
. htmlspecialchars($table_alias) . '">' . $crlf;
for ($i = 0; $i < $columns_cnt; $i++) {
$col_as = $columns[$i];
if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])
) {
$col_as
= $aliases[$db]['tables'][$table]['columns'][$col_as];
}
// If a cell is NULL, still export it to preserve
// the XML structure
if (! isset($record[$i]) || is_null($record[$i])) {
$record[$i] = 'NULL';
}
$buffer .= ' <column name="'
. htmlspecialchars($columns[$i]) . '">'
. htmlspecialchars($col_as) . '">'
. htmlspecialchars((string)$record[$i])
. '</column>' . $crlf;
}

View File

@ -110,11 +110,12 @@ class ExportYaml 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;
}
@ -134,11 +135,12 @@ class ExportYaml 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;
}
@ -151,11 +153,16 @@ class ExportYaml 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
);
@ -163,9 +170,12 @@ class ExportYaml extends ExportPlugin
$columns_cnt = $GLOBALS['dbi']->numFields($result);
$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;
@ -174,7 +184,7 @@ class ExportYaml extends ExportPlugin
// Output table name as comment if this is the first record of the table
if ($record_cnt == 1) {
$buffer = '# ' . $db . '.' . $table . $crlf;
$buffer = '# ' . $db_alias . '.' . $table_alias . $crlf;
$buffer .= '-' . $crlf;
} else {
$buffer = '-' . $crlf;
@ -185,15 +195,13 @@ class ExportYaml extends ExportPlugin
continue;
}
$column = $columns[$i];
if (is_null($record[$i])) {
$buffer .= ' ' . $column . ': null' . $crlf;
$buffer .= ' ' . $columns[$i] . ': null' . $crlf;
continue;
}
if (is_numeric($record[$i])) {
$buffer .= ' ' . $column . ': ' . $record[$i] . $crlf;
$buffer .= ' ' . $columns[$i] . ': ' . $record[$i] . $crlf;
continue;
}
@ -202,7 +210,7 @@ class ExportYaml extends ExportPlugin
array('\\\\', '\"', '\n', '\r'),
$record[$i]
);
$buffer .= ' ' . $column . ': "' . $record[$i] . '"' . $crlf;
$buffer .= ' ' . $columns[$i] . ': "' . $record[$i] . '"' . $crlf;
}
if (! PMA_exportOutputHandler($buffer)) {

View File

@ -113,8 +113,8 @@ class PMA_ExportPdf extends PMA_PDF
$this->Cell(
0,
$this->FontSizePt,
__('Database:') . ' ' . $this->currentDb . ', '
. __('Table:') . ' ' . $this->currentTable,
__('Database:') . ' ' . $this->dbAlias . ', '
. __('Table:') . ' ' . $this->tableAlias,
0, 1, 'L'
);
$l = ($this->lMargin);
@ -310,7 +310,13 @@ class PMA_ExportPdf extends PMA_PDF
$colFits = array();
$titleWidth = array();
for ($i = 0; $i < $this->numFields; $i++) {
$stringWidth = $this->getstringwidth($this->fields[$i]->name) + 6 ;
$col_as = $this->fields[$i]->name;
$db = $this->currentDb;
$table = $this->currentTable;
if (!empty($this->aliases[$db]['tables'][$table]['columns'][$col_as])) {
$col_as = $this->aliases[$db]['tables'][$table]['columns'][$col_as];
}
$stringWidth = $this->getstringwidth($col_as) + 6 ;
// save the real title's width
$titleWidth[$i] = $stringWidth;
$totalTitleWidth += $stringWidth;
@ -320,7 +326,7 @@ class PMA_ExportPdf extends PMA_PDF
if ($stringWidth < $this->sColWidth) {
$colFits[$i] = $stringWidth ;
}
$this->colTitles[$i] = $this->fields[$i]->name;
$this->colTitles[$i] = $col_as;
$this->display_column[$i] = true;
switch ($this->fields[$i]->type) {

View File

@ -160,11 +160,12 @@ class Export[Name] 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 = '')
{
// implementation
return true;
@ -186,11 +187,12 @@ class Export[Name] 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 = '')
{
// implementation
return true;
@ -204,11 +206,13 @@ class Export[Name] 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()
) {
// implementation;
return true;
}
@ -273,4 +277,4 @@ class Export[Name] extends ExportPlugin
$this->_globalVariableName = $global_variable_name;
}
}
?>
?>

View File

@ -437,13 +437,13 @@ class PMA_ExportHtmlword_Test extends PHPUnit_Framework_TestCase
$dbi->expects($this->once())
->method('getColumns')
->with('database', 'view')
->will($this->returnValue(array('column')));
->will($this->returnValue(array(array('Field' => 'column'))));
$GLOBALS['dbi'] = $dbi;
$this->object->expects($this->once())
->method('formatOneColumnDefinition')
->with('column', array('name1'))
->with(array('Field' => 'column'), array('name1'), 'column')
->will($this->returnValue(1));
$this->assertEquals(
@ -542,6 +542,7 @@ class PMA_ExportHtmlword_Test extends PHPUnit_Framework_TestCase
->will($this->returnValue(1));
$GLOBALS['cfgRelation']['relation'] = true;
$GLOBALS['controllink'] = null;
$_SESSION['relation'][0] = array(
'relwork' => true,
'commwork' => true,

View File

@ -245,8 +245,8 @@ class PMA_ExportJson_Test extends PHPUnit_Framework_TestCase
$GLOBALS['dbi'] = $dbi;
$this->expectOutputString(
"// db.tbl\n\n" .
"[{\"f1\":\"foo\"}, {\"f1\":\"bar\"}]"
"\n// db.tbl\n\n" .
"[{\"f1\":\"foo\"}, {\"f1\":\"bar\"}]\n"
);
$this->assertTrue(

View File

@ -753,7 +753,7 @@ class PMA_ExportOdt_Test extends PHPUnit_Framework_TestCase
'relation' => 'rel',
'column_info' => 'col'
);
$GLOBALS['controllink'] = null;
$this->assertTrue(
$this->object->getTableDef(
'database',
@ -1068,18 +1068,16 @@ class PMA_ExportOdt_Test extends PHPUnit_Framework_TestCase
'Type' => 'set(abc)enum123'
);
$unique_keys = array(
'field'
);
$col_alias = 'alias';
$this->assertEquals(
'<table:table-row><table:table-cell office:value-type="string">' .
'<text:p>field</text:p></table:table-cell><table:table-cell off' .
'<text:p>alias</text:p></table:table-cell><table:table-cell off' .
'ice:value-type="string"><text:p>set(abc)</text:p></table:table' .
'-cell><table:table-cell office:value-type="string"><text:p>Yes' .
'</text:p></table:table-cell><table:table-cell office:value-typ' .
'e="string"><text:p>NULL</text:p></table:table-cell>',
$method->invoke($this->object, $cols, $unique_keys)
$method->invoke($this->object, $cols, $col_alias)
);
$cols = array(
@ -1090,10 +1088,6 @@ class PMA_ExportOdt_Test extends PHPUnit_Framework_TestCase
'Default' => 'def'
);
$unique_keys = array(
'field'
);
$this->assertEquals(
'<table:table-row><table:table-cell office:value-type="string">' .
'<text:p>fields</text:p></table:table-cell><table:table-cell off' .
@ -1101,7 +1095,7 @@ class PMA_ExportOdt_Test extends PHPUnit_Framework_TestCase
'-cell><table:table-cell office:value-type="string"><text:p>No' .
'</text:p></table:table-cell><table:table-cell office:value-type=' .
'"string"><text:p>def</text:p></table:table-cell>',
$method->invoke($this->object, $cols, $unique_keys)
$method->invoke($this->object, $cols, '')
);
}
}

View File

@ -255,7 +255,13 @@ class PMA_ExportPdf_Test extends PHPUnit_Framework_TestCase
$pdf->expects($this->once())
->method('setAttributes')
->with(array('currentDb' => 'db', 'currentTable' => 'table'));
->with(
array(
'currentDb' => 'db', 'currentTable' => 'table',
'dbAlias' => 'db', 'tableAlias' => 'table',
'aliases' => array()
)
);
$pdf->expects($this->once())
->method('mysqlReport')

View File

@ -50,6 +50,7 @@ class PMA_ExportSql_Test extends PHPUnit_Framework_TestCase
$GLOBALS['plugin_param']['export_type'] = 'table';
$GLOBALS['plugin_param']['single_table'] = false;
$GLOBALS['cfgRelation']['relation'] = true;
$GLOBALS['controllink'] = null;
$this->object = new ExportSql();
}