export rework
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1080,6 +1080,100 @@ if (!defined('PMA_CONFIG_IMPORT_LIB_INCLUDED')) {
|
||||
$cfg['CtrlArrowsMoving'] = TRUE;
|
||||
}
|
||||
|
||||
if (!isset($cfg['Export']['format'])) {
|
||||
$cfg['Export']['format'] = 'sql';
|
||||
} // sql/latex/excel/csv/xml
|
||||
if (!isset($cfg['Export']['compression'])) {
|
||||
$cfg['Export']['compression'] = 'none';
|
||||
} // none/zip/gzip/bzip2
|
||||
|
||||
if (!isset($cfg['Export']['asfile'])) {
|
||||
$cfg['Export']['asfile'] = FALSE;
|
||||
}
|
||||
if (!isset($cfg['Export']['onserver'])) {
|
||||
$cfg['Export']['onserver'] = FALSE;
|
||||
}
|
||||
if (!isset($cfg['Export']['onserver_overwrite'])) {
|
||||
$cfg['Export']['onserver_overwrite'] = FALSE;
|
||||
}
|
||||
if (!isset($cfg['Export']['remember_file_template'])) {
|
||||
$cfg['Export']['remember_file_template'] = TRUE;
|
||||
}
|
||||
if (!isset($cfg['Export']['csv_columns'])) {
|
||||
$cfg['Export']['csv_columns'] = FALSE;
|
||||
}
|
||||
if (!isset($cfg['Export']['csv_null'])) {
|
||||
$cfg['Export']['csv_null'] = 'NULL';
|
||||
}
|
||||
if (!isset($cfg['Export']['excel_null'])) {
|
||||
$cfg['Export']['excel_null'] = 'NULL';
|
||||
}
|
||||
if (!isset($cfg['Export']['latex_null'])) {
|
||||
$cfg['Export']['latex_null'] = '\textit{NULL}';
|
||||
}
|
||||
if (!isset($cfg['Export']['csv_separator'])) {
|
||||
$cfg['Export']['csv_separator'] = ';';
|
||||
}
|
||||
if (!isset($cfg['Export']['csv_enclosed'])) {
|
||||
$cfg['Export']['csv_enclosed'] = '"';
|
||||
}
|
||||
if (!isset($cfg['Export']['csv_escaped'])) {
|
||||
$cfg['Export']['csv_escaped'] = '\\';
|
||||
}
|
||||
if (!isset($cfg['Export']['csv_terminated'])) {
|
||||
$cfg['Export']['csv_terminated'] = 'AUTO';
|
||||
}
|
||||
|
||||
if (!isset($cfg['Export']['latex_structure'])) {
|
||||
$cfg['Export']['latex_structure'] = TRUE;
|
||||
}
|
||||
if (!isset($cfg['Export']['latex_data'])) {
|
||||
$cfg['Export']['latex_data'] = TRUE;
|
||||
}
|
||||
if (!isset($cfg['Export']['latex_columns'])) {
|
||||
$cfg['Export']['latex_columns'] = TRUE;
|
||||
}
|
||||
if (!isset($cfg['Export']['latex_relation'])) {
|
||||
$cfg['Export']['latex_relation'] = TRUE;
|
||||
}
|
||||
if (!isset($cfg['Export']['latex_comments'])) {
|
||||
$cfg['Export']['latex_comments'] = TRUE;
|
||||
}
|
||||
if (!isset($cfg['Export']['latex_mime'])) {
|
||||
$cfg['Export']['latex_mime'] = TRUE;
|
||||
}
|
||||
|
||||
if (!isset($cfg['Export']['sql_drop_database'])) {
|
||||
$cfg['Export']['sql_drop_database'] = FALSE;
|
||||
}
|
||||
if (!isset($cfg['Export']['sql_drop_table'])) {
|
||||
$cfg['Export']['sql_drop_table'] = FALSE;
|
||||
}
|
||||
if (!isset($cfg['Export']['sql_structure'])) {
|
||||
$cfg['Export']['sql_structure'] = TRUE;
|
||||
}
|
||||
if (!isset($cfg['Export']['sql_data'])) {
|
||||
$cfg['Export']['sql_data'] = TRUE;
|
||||
}
|
||||
if (!isset($cfg['Export']['sql_backquotes'])) {
|
||||
$cfg['Export']['sql_backquotes'] = TRUE;
|
||||
}
|
||||
if (!isset($cfg['Export']['sql_relation'])) {
|
||||
$cfg['Export']['sql_relation'] = FALSE;
|
||||
}
|
||||
if (!isset($cfg['Export']['sql_columns'])) {
|
||||
$cfg['Export']['sql_columns'] = FALSE;
|
||||
}
|
||||
if (!isset($cfg['Export']['sql_extended'])) {
|
||||
$cfg['Export']['sql_extended'] = FALSE;
|
||||
}
|
||||
if (!isset($cfg['Export']['sql_comments'])) {
|
||||
$cfg['Export']['sql_comments'] = FALSE;
|
||||
}
|
||||
if (!isset($cfg['Export']['sql_mime'])) {
|
||||
$cfg['Export']['sql_mime'] = FALSE;
|
||||
}
|
||||
|
||||
} // $__PMA_CONFIG_IMPORT_LIB__
|
||||
|
||||
?>
|
||||
|
@@ -2,22 +2,36 @@
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
/*
|
||||
* Whether we export single table or more
|
||||
*/
|
||||
$export_single = (!isset($multi_tables) || $multi_tables == '') && (isset($table));
|
||||
?>
|
||||
// Get relations & co. status
|
||||
require('./libraries/relation.lib.php3');
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
|
||||
<form method="post" action="tbl_dump.php3" name="<?php echo $tbl_dump_form_name; ?>">
|
||||
<?php
|
||||
if ($export_single) {
|
||||
echo ' ' . PMA_generate_common_hidden_inputs($db, $table);
|
||||
} else {
|
||||
echo ' ' . PMA_generate_common_hidden_inputs($db);
|
||||
function PMA_exportCheckboxCheck($str) {
|
||||
if (isset($GLOBALS['cfg']['Export'][$str]) && $GLOBALS['cfg']['Export'][$str]) {
|
||||
echo ' checked="checked"';
|
||||
}
|
||||
}
|
||||
|
||||
function PMA_exportIsActive($what, $val) {
|
||||
if (isset($GLOBALS['cfg']['Export'][$what]) && $GLOBALS['cfg']['Export'][$what] == $val) {
|
||||
echo ' checked="checked"';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<form method="post" action="export.php3" name="dump">
|
||||
<?php
|
||||
if ($export_type == 'server') {
|
||||
echo PMA_generate_common_hidden_inputs('', '', 1);
|
||||
} elseif ($export_type == 'database') {
|
||||
echo PMA_generate_common_hidden_inputs($db, '', 1);
|
||||
} else {
|
||||
echo PMA_generate_common_hidden_inputs($db, $table, 1);
|
||||
}
|
||||
echo ' <input type="hidden" name="export_type" value="' . $export_type . '" />';
|
||||
|
||||
if (isset($sql_query)) {
|
||||
echo ' <input type="hidden" name="sql_query" value="' . urlencode($sql_query) . '" />';
|
||||
echo ' <input type="hidden" name="sql_query" value="' . htmlspecialchars($sql_query) . '" />';
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -38,36 +52,36 @@ if (isset($sql_query)) {
|
||||
|
||||
<!-- Formats to export to -->
|
||||
<td nowrap="nowrap" valign="top">
|
||||
<fieldset <?php echo ((!isset($multi_tables) || isset($multi_tables) && $multi_tables == '') ? 'style="height: 220px;"' : ''); ?>>
|
||||
<fieldset <?php echo ((!isset($multi_values) || isset($multi_values) && $multi_values == '') ? 'style="height: 220px;"' : ''); ?>>
|
||||
<legend><?php echo $strExport; ?></legend>
|
||||
<br>
|
||||
<?php
|
||||
if (isset($multi_tables) && $multi_tables != '') {
|
||||
echo $multi_tables;
|
||||
if (isset($multi_values) && $multi_values != '') {
|
||||
echo $multi_values;
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- SQL -->
|
||||
<input type="radio" name="what" value="sql" id="radio_dump_sql" checked="checked" onclick="if(this.checked) { hide_them_all(); getElement('sql_options').style.display = 'block'; }; return true" />
|
||||
<input type="radio" name="what" value="sql" id="radio_dump_sql" onclick="if(this.checked) { hide_them_all(); getElement('sql_options').style.display = 'block'; }; return true" <?php PMA_exportIsActive('format', 'sql'); ?> />
|
||||
<label for="radio_dump_sql"><?php echo $strSQL; ?></label>
|
||||
<br /><br />
|
||||
|
||||
<!-- LaTeX table -->
|
||||
<input type="radio" name="what" value="latex" id="radio_dump_latex" onclick="if(this.checked) { hide_them_all(); getElement('latex_options').style.display = 'block'; }; return true" />
|
||||
<input type="radio" name="what" value="latex" id="radio_dump_latex" onclick="if(this.checked) { hide_them_all(); getElement('latex_options').style.display = 'block'; }; return true" <?php PMA_exportIsActive('format', 'latex'); ?> />
|
||||
<label for="radio_dump_latex"><?php echo $strLaTeX; ?></label>
|
||||
<br /><br />
|
||||
|
||||
<!-- Excel CSV -->
|
||||
<input type="radio" name="what" value="excel" id="radio_dump_excel" onclick="if(this.checked) { hide_them_all(); getElement('excel_options').style.display = 'block'; }; return true" />
|
||||
<input type="radio" name="what" value="excel" id="radio_dump_excel" onclick="if(this.checked) { hide_them_all(); getElement('excel_options').style.display = 'block'; }; return true" <?php PMA_exportIsActive('format', 'excel'); ?> />
|
||||
<label for="radio_dump_excel"><?php echo $strStrucExcelCSV; ?></label>
|
||||
<br /><br />
|
||||
<!-- General CSV -->
|
||||
<input type="radio" name="what" value="csv" id="radio_dump_csv" onclick="if(this.checked) { hide_them_all(); getElement('csv_options').style.display = 'block'; }; return true" />
|
||||
<input type="radio" name="what" value="csv" id="radio_dump_csv" onclick="if(this.checked) { hide_them_all(); getElement('csv_options').style.display = 'block'; }; return true" <?php PMA_exportIsActive('format', 'csv'); ?> />
|
||||
<label for="radio_dump_csv"><?php echo $strStrucCSV;?></label>
|
||||
<br /><br />
|
||||
|
||||
<!-- XML -->
|
||||
<input type="radio" name="what" value="xml" id="radio_dump_xml" onclick="if(this.checked) { hide_them_all(); getElement('none_options').style.display = 'block'; }; return true" />
|
||||
<input type="radio" name="what" value="xml" id="radio_dump_xml" onclick="if(this.checked) { hide_them_all(); getElement('none_options').style.display = 'block'; }; return true" <?php PMA_exportIsActive('format', 'xml'); ?> />
|
||||
<label for="radio_dump_xml"><?php echo $strXML; ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
@@ -77,48 +91,73 @@ if (isset($sql_query)) {
|
||||
<!-- SQL options -->
|
||||
<fieldset id="sql_options">
|
||||
<legend><?php echo $strSQLOptions; ?> (<a href="./Documentation.html#faqexport" target="documentation"><?php echo $strDocu; ?></a>)</legend>
|
||||
|
||||
<?php
|
||||
if ($export_type == 'server') {
|
||||
?>
|
||||
<!-- For databases -->
|
||||
<fieldset>
|
||||
<legend>
|
||||
<?php echo $strDatabaseExportOptions; ?>
|
||||
</legend>
|
||||
<input type="checkbox" name="drop_database" value="yes" id="checkbox_drop_database" <?php PMA_exportCheckboxCheck('sql_drop_database'); ?> />
|
||||
<label for="checkbox_drop_database"><?php echo $strAddDropDatabase; ?></label><br />
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<!-- For structure -->
|
||||
<fieldset>
|
||||
<legend>
|
||||
<input type="checkbox" name="sql_structure" value="structure" id="checkbox_sql_structure" checked="checked" onclick="if(!this.checked && !getElement('checkbox_sql_data').checked) return false; else return true;" />
|
||||
<input type="checkbox" name="sql_structure" value="structure" id="checkbox_sql_structure" <?php PMA_exportCheckboxCheck('sql_structure'); ?> onclick="if(!this.checked && !getElement('checkbox_sql_data').checked) return false; else return true;" />
|
||||
<label for="checkbox_sql_structure"><?php echo $strStructure; ?></label><br />
|
||||
</legend>
|
||||
<input type="checkbox" name="drop" value="1" id="checkbox_dump_drop" />
|
||||
<input type="checkbox" name="drop" value="1" id="checkbox_dump_drop" <?php PMA_exportCheckboxCheck('sql_drop_table'); ?> />
|
||||
<label for="checkbox_dump_drop"><?php echo $strStrucDrop; ?></label><br />
|
||||
<?php
|
||||
// Add backquotes checkbox
|
||||
if (PMA_MYSQL_INT_VERSION >= 32306) {
|
||||
?>
|
||||
<input type="checkbox" name="use_backquotes" value="1" id="checkbox_dump_use_backquotes" checked="checked" />
|
||||
<input type="checkbox" name="use_backquotes" value="1" id="checkbox_dump_use_backquotes" <?php PMA_exportCheckboxCheck('sql_backquotes'); ?> />
|
||||
<label for="checkbox_dump_use_backquotes"><?php echo $strUseBackquotes; ?></label><br />
|
||||
<?php
|
||||
} // end backquotes feature
|
||||
echo "\n";
|
||||
|
||||
// garvin: whether to show column comments
|
||||
require('./libraries/relation.lib.php3');
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
|
||||
if ($cfgRelation['commwork']) {
|
||||
?>
|
||||
<input type="checkbox" name="use_comments" value="1" id="checkbox_dump_use_comments" />
|
||||
<label for="checkbox_dump_use_comments"><?php echo $strDumpComments; ?></label><br />
|
||||
<?php
|
||||
} // end dump comments
|
||||
echo "\n";
|
||||
?>
|
||||
<fieldset>
|
||||
<legend><?php echo $strAddIntoComments; ?></legend>
|
||||
<?php
|
||||
if (!empty($cfgRelation['relation'])) {
|
||||
?>
|
||||
<input type="checkbox" name="sql_relation" value="yes" id="checkbox_sql_use_relation" <?php PMA_exportCheckboxCheck('sql_relation'); ?> />
|
||||
<label for="checkbox_sql_use_relation"><?php echo $strRelations; ?></label><br />
|
||||
<?php
|
||||
} // end relation
|
||||
|
||||
if ($cfgRelation['commwork']) {
|
||||
?>
|
||||
<input type="checkbox" name="sql_comments" value="yes" id="checkbox_sql_use_comments" <?php PMA_exportCheckboxCheck('sql_comments'); ?> />
|
||||
<label for="checkbox_sql_use_comments"><?php echo $strComments; ?></label><br />
|
||||
<?php
|
||||
} // end comments
|
||||
|
||||
if ($cfgRelation['mimework']) {
|
||||
?>
|
||||
<input type="checkbox" name="sql_mime" value="yes" id="checkbox_sql_use_mime" <?php PMA_exportCheckboxCheck('sql_mime'); ?> />
|
||||
<label for="checkbox_sql_use_mime"><?php echo $strMIME_MIMEtype; ?></label><br />
|
||||
<?php
|
||||
} // end MIME
|
||||
?>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
|
||||
<!-- For data -->
|
||||
<fieldset>
|
||||
<legend>
|
||||
<input type="checkbox" name="sql_data" value="data" id="checkbox_sql_data" checked="checked" onclick="if(!this.checked && !getElement('checkbox_sql_structure').checked) return false; else return true;" />
|
||||
<input type="checkbox" name="sql_data" value="data" id="checkbox_sql_data" <?php PMA_exportCheckboxCheck('sql_data'); ?> onclick="if(!this.checked && !getElement('checkbox_sql_structure').checked) return false; else return true;" />
|
||||
<label for="checkbox_sql_data"><?php echo $strData; ?></label><br />
|
||||
</legend>
|
||||
<input type="checkbox" name="showcolumns" value="yes" id="checkbox_dump_showcolumns" />
|
||||
<input type="checkbox" name="showcolumns" value="yes" id="checkbox_dump_showcolumns" <?php PMA_exportCheckboxCheck('sql_columns'); ?> />
|
||||
<label for="checkbox_dump_showcolumns"><?php echo $strCompleteInserts; ?></label><br />
|
||||
<input type="checkbox" name="extended_ins" value="yes" id="checkbox_dump_extended_ins" />
|
||||
<input type="checkbox" name="extended_ins" value="yes" id="checkbox_dump_extended_ins" <?php PMA_exportCheckboxCheck('sql_extended'); ?> />
|
||||
<label for="checkbox_dump_extended_ins"><?php echo $strExtendedInserts; ?></label><br />
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
@@ -130,54 +169,48 @@ echo "\n";
|
||||
<!-- For structure -->
|
||||
<fieldset>
|
||||
<legend>
|
||||
<input type="checkbox" name="ltx_structure" value="structure" id="checkbox_ltx_structure" checked="checked" onclick="if(!this.checked && !getElement('checkbox_ltx_data').checked) return false; else return true;" />
|
||||
<label for="checkbox_ltx_structure"><?php echo $strStructure; ?></label><br />
|
||||
<input type="checkbox" name="latex_structure" value="structure" id="checkbox_latex_structure" <?php PMA_exportCheckboxCheck('latex_structure'); ?> onclick="if(!this.checked && !getElement('checkbox_latex_data').checked) return false; else return true;" />
|
||||
<label for="checkbox_latex_structure"><?php echo $strStructure; ?></label><br />
|
||||
</legend>
|
||||
<?php
|
||||
|
||||
// garvin: whether to show column comments
|
||||
require('./libraries/relation.lib.php3');
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
|
||||
if (!empty($cfgRelation['relation'])) {
|
||||
?>
|
||||
<input type="checkbox" name="ltx_relation" value="yes" id="checkbox_ltx_use_relation" checked="checked" />
|
||||
<label for="checkbox_ltx_use_relation"><?php echo $strRelations; ?></label><br />
|
||||
<?php
|
||||
<?php
|
||||
if (!empty($cfgRelation['relation'])) {
|
||||
?>
|
||||
<input type="checkbox" name="latex_relation" value="yes" id="checkbox_latex_use_relation" <?php PMA_exportCheckboxCheck('latex_relation'); ?> />
|
||||
<label for="checkbox_latex_use_relation"><?php echo $strRelations; ?></label><br />
|
||||
<?php
|
||||
} // end relation
|
||||
|
||||
if ($cfgRelation['commwork']) {
|
||||
if ($cfgRelation['commwork']) {
|
||||
?>
|
||||
<input type="checkbox" name="ltx_comments" value="yes" id="checkbox_ltx_use_comments" checked="checked" />
|
||||
<label for="checkbox_ltx_use_comments"><?php echo $strComments; ?></label><br />
|
||||
<?php
|
||||
} // end comments
|
||||
<input type="checkbox" name="latex_comments" value="yes" id="checkbox_latex_use_comments" <?php PMA_exportCheckboxCheck('latex_comments'); ?> />
|
||||
<label for="checkbox_latex_use_comments"><?php echo $strComments; ?></label><br />
|
||||
<?php
|
||||
} // end comments
|
||||
|
||||
if ($cfgRelation['mimework']) {
|
||||
if ($cfgRelation['mimework']) {
|
||||
?>
|
||||
<input type="checkbox" name="ltx_mime" value="yes" id="checkbox_ltx_use_mime" checked="checked" />
|
||||
<label for="checkbox_ltx_use_mime"><?php echo $strMIME_MIMEtype; ?></label><br />
|
||||
<?php
|
||||
} // end MIME
|
||||
echo "\n";
|
||||
?>
|
||||
<input type="checkbox" name="latex_mime" value="yes" id="checkbox_latex_use_mime" <?php PMA_exportCheckboxCheck('latex_mime'); ?> />
|
||||
<label for="checkbox_latex_use_mime"><?php echo $strMIME_MIMEtype; ?></label><br />
|
||||
<?php
|
||||
} // end MIME
|
||||
?>
|
||||
</fieldset>
|
||||
|
||||
<!-- For data -->
|
||||
<fieldset>
|
||||
<legend>
|
||||
<input type="checkbox" name="ltx_data" value="data" id="checkbox_ltx_data" checked="checked" onclick="if(!this.checked && !getElement('checkbox_ltx_structure').checked) return false; else return true;" />
|
||||
<label for="checkbox_ltx_data"><?php echo $strData; ?></label><br />
|
||||
<input type="checkbox" name="latex_data" value="data" id="checkbox_latex_data" <?php PMA_exportCheckboxCheck('latex_data'); ?> onclick="if(!this.checked && !getElement('checkbox_latex_structure').checked) return false; else return true;" />
|
||||
<label for="checkbox_latex_data"><?php echo $strData; ?></label><br />
|
||||
</legend>
|
||||
<input type="checkbox" name="ltx_showcolumns" value="yes" id="ch_ltx_showcolumns" checked="checked" />
|
||||
<label for="ch_ltx_showcolumns"><?php echo $strColumnNames; ?></label><br />
|
||||
<input type="checkbox" name="latex_showcolumns" value="yes" id="ch_latex_showcolumns" <?php PMA_exportCheckboxCheck('latex_columns'); ?> />
|
||||
<label for="ch_latex_showcolumns"><?php echo $strColumnNames; ?></label><br />
|
||||
<table border="0" cellspacing="1" cellpadding="0">
|
||||
<tr>
|
||||
<td>
|
||||
<?php echo $strReplaceNULLBy; ?>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="ltx_replace_null" size="20" value="\textit{NULL}" class="textfield" />
|
||||
<input type="text" name="latex_replace_null" size="20" value="<?php echo $cfg['Export']['latex_null']; ?>" class="textfield" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -187,13 +220,14 @@ echo "\n";
|
||||
<!-- CSV options -->
|
||||
<fieldset id="csv_options">
|
||||
<legend><?php echo $strCSVOptions; ?></legend>
|
||||
<input type="hidden" name="csv_data" value="csv_data" />
|
||||
<table border="0" cellspacing="1" cellpadding="0">
|
||||
<tr>
|
||||
<td>
|
||||
<?php echo $strFieldsTerminatedBy; ?>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="separator" size="2" value=";" class="textfield" />
|
||||
<input type="text" name="separator" size="2" value="<?php echo $cfg['Export']['csv_separator']; ?>" class="textfield" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -201,7 +235,7 @@ echo "\n";
|
||||
<?php echo $strFieldsEnclosedBy; ?>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="enclosed" size="2" value=""" class="textfield" />
|
||||
<input type="text" name="enclosed" size="2" value="<?php echo $cfg['Export']['csv_enclosed']; ?>" class="textfield" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -209,7 +243,7 @@ echo "\n";
|
||||
<?php echo $strFieldsEscapedBy; ?>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="escaped" size="2" value="\" class="textfield" />
|
||||
<input type="text" name="escaped" size="2" value="<?php echo $cfg['Export']['csv_escaped']; ?>" class="textfield" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -217,7 +251,7 @@ echo "\n";
|
||||
<?php echo $strFieldsTerminatedBy; ?>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="add_character" size="2" value="<?php echo ((PMA_whichCrlf() == "\n") ? '\n' : '\r\n'); ?>" class="textfield" />
|
||||
<input type="text" name="add_character" size="2" value="<?php if ($cfg['Export']['csv_terminated'] == 'AUTO') echo ((PMA_whichCrlf() == "\n") ? '\n' : '\r\n'); else echo $cfg['Export']['csv_terminated']; ?>" class="textfield" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -225,24 +259,25 @@ echo "\n";
|
||||
<?php echo $strReplaceNULLBy; ?>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="csv_replace_null" size="20" value="NULL" class="textfield" />
|
||||
<input type="text" name="csv_replace_null" size="20" value="<?php echo $cfg['Export']['csv_null']; ?>" class="textfield" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<input type="checkbox" name="showcsvnames" value="yes" id="checkbox_dump_showcsvnames" />
|
||||
<input type="checkbox" name="showcsvnames" value="yes" id="checkbox_dump_showcsvnames" <?php PMA_exportCheckboxCheck('csv_columns'); ?> />
|
||||
<label for="checkbox_dump_showcsvnames"><?php echo $strPutColNames; ?></label>
|
||||
</fieldset>
|
||||
|
||||
<!-- Excel options -->
|
||||
<fieldset id="excel_options">
|
||||
<legend><?php echo $strExcelOptions; ?></legend>
|
||||
<input type="hidden" name="excel_data" value="excel_data" />
|
||||
<table border="0" cellspacing="1" cellpadding="0">
|
||||
<tr>
|
||||
<td>
|
||||
<?php echo $strReplaceNULLBy; ?>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="excel_replace_null" size="20" value="NULL" class="textfield" />
|
||||
<input type="text" name="excel_replace_null" size="20" value="<?php echo $cfg['Export']['excel_null']; ?>" class="textfield" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -250,6 +285,7 @@ echo "\n";
|
||||
|
||||
<fieldset id="none_options">
|
||||
<legend><?php echo $strNoOptions; ?></legend>
|
||||
<input type="hidden" name="xml_data" value="xml_data" />
|
||||
</fieldset>
|
||||
|
||||
<script type="text/javascript">
|
||||
@@ -290,14 +326,14 @@ if (isset($table) && !empty($table) && !isset($num_tables)) {
|
||||
<td colspan="2">
|
||||
<fieldset>
|
||||
<legend>
|
||||
<input type="checkbox" name="asfile" value="sendit" id="checkbox_dump_asfile" />
|
||||
<input type="checkbox" name="asfile" value="sendit" id="checkbox_dump_asfile" <?php PMA_exportCheckboxCheck('asfile'); ?> />
|
||||
<label for="checkbox_dump_asfile"><?php echo $strSend; ?></label>
|
||||
</legend>
|
||||
|
||||
<?php if (isset($cfg['SaveDir']) && !empty($cfg['SaveDir'])) { ?>
|
||||
<input type="checkbox" name="onserver" value="saveit" id="checkbox_dump_onserver" onclick="getElement('checkbox_dump_asfile').checked = true;" />
|
||||
<input type="checkbox" name="onserver" value="saveit" id="checkbox_dump_onserver" onclick="getElement('checkbox_dump_asfile').checked = true;" <?php PMA_exportCheckboxCheck('onserver'); ?> />
|
||||
<label for="checkbox_dump_onserver"><?php echo sprintf($strSaveOnServer, htmlspecialchars($cfg['SaveDir'])); ?></label>,
|
||||
<input type="checkbox" name="onserverover" value="saveitover" id="checkbox_dump_onserverover" onclick="getElement('checkbox_dump_onserver').checked = true;getElement('checkbox_dump_asfile').checked = true;" />
|
||||
<input type="checkbox" name="onserverover" value="saveitover" id="checkbox_dump_onserverover" onclick="getElement('checkbox_dump_onserver').checked = true;getElement('checkbox_dump_asfile').checked = true;" <?php PMA_exportCheckboxCheck('onserver_overwrite'); ?> />
|
||||
<label for="checkbox_dump_onserverover"><?php echo $strOverwriteExisting; ?></label>
|
||||
<br />
|
||||
<?php } ?>
|
||||
@@ -306,7 +342,7 @@ if (isset($table) && !empty($table) && !isset($num_tables)) {
|
||||
<input type="text" name="filename_template"
|
||||
<?php
|
||||
echo ' value="';
|
||||
if (!$export_single) {
|
||||
if ($export_type == 'database') {
|
||||
if (isset($_COOKIE) && !empty($_COOKIE['pma_db_filename_template'])) {
|
||||
echo $_COOKIE['pma_db_filename_template'];
|
||||
} elseif (isset($HTTP_COOKIE_VARS) && !empty($HTTP_COOKIE_VARS['pma_db_filename_template'])) {
|
||||
@@ -314,7 +350,7 @@ if (isset($table) && !empty($table) && !isset($num_tables)) {
|
||||
} else {
|
||||
echo '__DB__';
|
||||
}
|
||||
} else {
|
||||
} elseif ($export_type == 'table') {
|
||||
if (isset($_COOKIE) && !empty($_COOKIE['pma_table_filename_template'])) {
|
||||
echo $_COOKIE['pma_table_filename_template'];
|
||||
} elseif (isset($HTTP_COOKIE_VARS) && !empty($HTTP_COOKIE_VARS['pma_table_filename_template'])) {
|
||||
@@ -322,12 +358,20 @@ if (isset($table) && !empty($table) && !isset($num_tables)) {
|
||||
} else {
|
||||
echo '__TABLE__';
|
||||
}
|
||||
} else {
|
||||
if (isset($_COOKIE) && !empty($_COOKIE['pma_server_filename_template'])) {
|
||||
echo $_COOKIE['pma_server_filename_template'];
|
||||
} elseif (isset($HTTP_COOKIE_VARS) && !empty($HTTP_COOKIE_VARS['pma_server_filename_template'])) {
|
||||
echo $HTTP_COOKIE_VARS['pma_server_filename_template'];
|
||||
} else {
|
||||
echo '__SERVER__';
|
||||
}
|
||||
}
|
||||
echo '" ';
|
||||
?>
|
||||
/>
|
||||
(
|
||||
<input type="checkbox" name="remember_template" checked="checked" id="checkbox_remember_template" />
|
||||
<input type="checkbox" name="remember_template" id="checkbox_remember_template" <?php PMA_exportCheckboxCheck('remember_file_template'); ?> />
|
||||
<label for="checkbox_remember_template"><?php echo $strFileNameTemplateRemember; ?></label>
|
||||
)*
|
||||
|
||||
@@ -359,7 +403,7 @@ if (isset($table) && !empty($table) && !isset($num_tables)) {
|
||||
<fieldset>
|
||||
<legend><?php echo $strCompression; ?></legend>
|
||||
|
||||
<input type="radio" name="compression" value="none" id="radio_compression_none" checked="checked" onclick="getElement('checkbox_dump_asfile').checked = true;" />
|
||||
<input type="radio" name="compression" value="none" id="radio_compression_none" onclick="getElement('checkbox_dump_asfile').checked = true;" <?php PMA_exportIsActive('compression', 'none'); ?> />
|
||||
<label for="radio_compression_none"><?php echo $strNone; ?></label>
|
||||
|
||||
<?php
|
||||
@@ -372,21 +416,21 @@ if (PMA_PHP_INT_VERSION >= 40004) {
|
||||
if ($is_zip || $is_gzip || $is_bzip) {
|
||||
if ($is_zip) {
|
||||
?>
|
||||
<input type="radio" name="compression" value="zip" id="radio_compression_zip" onclick="getElement('checkbox_dump_asfile').checked = true;" />
|
||||
<input type="radio" name="compression" value="zip" id="radio_compression_zip" onclick="getElement('checkbox_dump_asfile').checked = true;" <?php PMA_exportIsActive('compression', 'zip'); ?> />
|
||||
<label for="radio_compression_zip"><?php echo $strZip; ?></label><?php echo (($is_gzip || $is_bzip) ? ' ' : ''); ?>
|
||||
<?php
|
||||
}
|
||||
if ($is_gzip) {
|
||||
echo "\n"
|
||||
?>
|
||||
<input type="radio" name="compression" value="gzip" id="radio_compression_gzip" onclick="getElement('checkbox_dump_asfile').checked = true;" />
|
||||
<input type="radio" name="compression" value="gzip" id="radio_compression_gzip" onclick="getElement('checkbox_dump_asfile').checked = true;" <?php PMA_exportIsActive('compression', 'gzip'); ?> />
|
||||
<label for="radio_compression_gzip"><?php echo $strGzip; ?></label><?php echo ($is_bzip ? ' ' : ''); ?>
|
||||
<?php
|
||||
}
|
||||
if ($is_bzip) {
|
||||
echo "\n"
|
||||
?>
|
||||
<input type="radio" name="compression" value="bzip" id="radio_compression_bzip" onclick="getElement('checkbox_dump_asfile').checked = true;" />
|
||||
<input type="radio" name="compression" value="bzip" id="radio_compression_bzip" onclick="getElement('checkbox_dump_asfile').checked = true;" <?php PMA_exportIsActive('compression', 'bzip'); ?> />
|
||||
<label for="radio_compression_bzip"><?php echo $strBzip; ?></label>
|
||||
<?php
|
||||
}
|
||||
|
172
libraries/export/csv.php3
Normal file
172
libraries/export/csv.php3
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
/**
|
||||
* Set of functions used to build CSV dumps of tables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Outputs comment
|
||||
*
|
||||
* @param string Text of comment
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*/
|
||||
function PMA_exportComment($text) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader() {
|
||||
global $what;
|
||||
global $add_character;
|
||||
global $separator;
|
||||
global $enclosed;
|
||||
global $escaped;
|
||||
|
||||
// Here we just prepare some values for export
|
||||
if ($what == 'excel') {
|
||||
$add_character = "\015\012";
|
||||
$separator = ',';
|
||||
$enclosed = '"';
|
||||
$escaped = '"';
|
||||
} else {
|
||||
if (empty($add_character)) {
|
||||
$add_character = $GLOBALS['crlf'];
|
||||
} else {
|
||||
$add_character = str_replace('\\r', "\015", $add_character);
|
||||
$add_character = str_replace('\\n', "\012", $add_character);
|
||||
$add_character = str_replace('\\t', "\011", $add_character);
|
||||
} // end if
|
||||
$separator = str_replace('\\t', "\011", $separator);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string Database name
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database footer
|
||||
*
|
||||
* @param string Database name
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs create database database
|
||||
*
|
||||
* @param string Database name
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in CSV format
|
||||
*
|
||||
* @param string the database name
|
||||
* @param string the table name
|
||||
* @param string the end of line sequence
|
||||
* @param string the url to go back in case of error
|
||||
* @param string SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
|
||||
global $what;
|
||||
global $add_character;
|
||||
global $separator;
|
||||
global $enclosed;
|
||||
global $escaped;
|
||||
|
||||
|
||||
// If required, get fields name at the first line
|
||||
if (isset($GLOBALS['showcsvnames']) && $GLOBALS['showcsvnames'] == 'yes') {
|
||||
$schema_insert = '';
|
||||
$local_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
|
||||
$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url);
|
||||
while ($row = PMA_mysql_fetch_array($result)) {
|
||||
if ($enc_by == '') {
|
||||
$schema_insert .= $row['Field'];
|
||||
} else {
|
||||
$schema_insert .= $enc_by
|
||||
. str_replace($enc_by, $esc_by . $enc_by, $row['Field'])
|
||||
. $enc_by;
|
||||
}
|
||||
$schema_insert .= $sep;
|
||||
} // end while
|
||||
$schema_insert =trim(substr($schema_insert, 0, -1));
|
||||
if (!PMA_exportOutputHandler($schema_insert . $add_character)) return FALSE;
|
||||
} // end if
|
||||
|
||||
// Gets the data from the database
|
||||
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url);
|
||||
$fields_cnt = mysql_num_fields($result);
|
||||
|
||||
// Format the data
|
||||
$i = 0;
|
||||
while ($row = PMA_mysql_fetch_row($result)) {
|
||||
$schema_insert = '';
|
||||
for ($j = 0; $j < $fields_cnt; $j++) {
|
||||
if (!isset($row[$j])) {
|
||||
$schema_insert .= $GLOBALS[$what . '_replace_null'];
|
||||
}
|
||||
else if ($row[$j] == '0' || $row[$j] != '') {
|
||||
// loic1 : always enclose fields
|
||||
if ($what == 'excel') {
|
||||
$row[$j] = ereg_replace("\015(\012)?", "\012", $row[$j]);
|
||||
}
|
||||
if ($enclosed == '') {
|
||||
$schema_insert .= $row[$j];
|
||||
} else {
|
||||
$schema_insert .= $enclosed
|
||||
. str_replace($enclosed, $escaped . $enclosed, $row[$j])
|
||||
. $enclosed;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$schema_insert .= '';
|
||||
}
|
||||
if ($j < $fields_cnt-1) {
|
||||
$schema_insert .= $separator;
|
||||
}
|
||||
} // end for
|
||||
$schema_insert =trim($schema_insert);
|
||||
if (!PMA_exportOutputHandler($schema_insert . $add_character)) return FALSE;
|
||||
$i++;
|
||||
} // end while
|
||||
mysql_free_result($result);
|
||||
|
||||
return TRUE;
|
||||
} // end of the 'PMA_getTableCsv()' function
|
||||
?>
|
340
libraries/export/latex.php3
Normal file
340
libraries/export/latex.php3
Normal file
@@ -0,0 +1,340 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
/**
|
||||
* Set of functions used to build dumps of tables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Outputs comment
|
||||
*
|
||||
* @param string Text of comment
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*/
|
||||
function PMA_exportComment($text) {
|
||||
return PMA_exportOutputHandler('% ' . $text . $GLOBALS['crlf']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader() {
|
||||
global $crlf;
|
||||
global $cfg;
|
||||
|
||||
$head = '% phpMyAdmin LaTeX Dump' . $crlf
|
||||
. '% version ' . PMA_VERSION . $crlf
|
||||
. '% http://www.phpmyadmin.net' . $crlf
|
||||
. '%' . $crlf
|
||||
. '% ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host'];
|
||||
if (!empty($cfg['Server']['port'])) {
|
||||
$head .= ':' . $cfg['Server']['port'];
|
||||
}
|
||||
$head .= $crlf
|
||||
. '% ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf
|
||||
. '% ' . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3) . $crlf
|
||||
. '% ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf;
|
||||
return PMA_exportOutputHandler($head);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string Database name
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db) {
|
||||
global $crlf;
|
||||
$head = '% ' . $crlf
|
||||
. '% ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf
|
||||
. '% ' . $crlf;
|
||||
return PMA_exportOutputHandler($head);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database footer
|
||||
*
|
||||
* @param string Database name
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs create database database
|
||||
*
|
||||
* @param string Database name
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in LaTeX table/sideways table environment
|
||||
*
|
||||
* @param string the database name
|
||||
* @param string the table name
|
||||
* @param string the end of line sequence
|
||||
* @param string the url to go back in case of error
|
||||
* @param string SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
|
||||
|
||||
$local_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
|
||||
$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url);
|
||||
for ($i = 0; $row = PMA_mysql_fetch_array($result, MYSQL_ASSOC); $i++) {
|
||||
$columns[$i] = $row['Field'];
|
||||
}
|
||||
$columns_cnt = count($columns);
|
||||
unset($i);
|
||||
unset($local_query);
|
||||
mysql_free_result($result);
|
||||
|
||||
$tex_escape = array("$", "%", "{", "}", "&", "#", "_", "^");
|
||||
|
||||
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url);
|
||||
|
||||
$buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strData'] . $crlf . '%' . $crlf
|
||||
. '\\begin{table} ' . $crlf
|
||||
. ' \\begin{longtable}{|';
|
||||
|
||||
for($index=0;$index<$columns_cnt;$index++) {
|
||||
$buffer .= 'c|';
|
||||
}
|
||||
$buffer .= '} ' . $crlf ;
|
||||
|
||||
$buffer .= ' \\hline \\endhead \\hline \\endfoot \\hline ' . $crlf;
|
||||
if (!PMA_exportOutputHandler($buffer)) return FALSE;
|
||||
|
||||
// show column names
|
||||
if (isset($GLOBALS['latex_showcolumns'])) {
|
||||
$local_buffer = implode("\000", $columns);
|
||||
for($k=0;$k<count($tex_escape);$k++) {
|
||||
$local_buffer = str_replace($tex_escape[$k], '\\' . $tex_escape[$k], $local_buffer);
|
||||
}
|
||||
$buffer = str_replace("\000", ' & ', $local_buffer);
|
||||
unset($local_buffer);
|
||||
$buffer .= ' \\\\ \\hline \\hline' . $crlf;
|
||||
if (!PMA_exportOutputHandler($buffer)) return FALSE;
|
||||
}
|
||||
|
||||
// print the whole table
|
||||
while ($record = PMA_mysql_fetch_array($result, MYSQL_ASSOC)) {
|
||||
|
||||
$buffer = '';
|
||||
// print each row
|
||||
for($i = 0; $i < $columns_cnt; $i++) {
|
||||
if ( isset($record[$columns[$i]]) && (!function_exists('is_null') || !is_null($record[$columns[$i]]))) {
|
||||
$column_value = $record[$columns[$i]];
|
||||
|
||||
// $ % { } & # _ ^
|
||||
// escaping special characters
|
||||
for($k=0;$k<count($tex_escape);$k++) {
|
||||
$column_value = str_replace($tex_escape[$k], '\\' . $tex_escape[$k], $column_value);
|
||||
}
|
||||
} else {
|
||||
$column_value = $GLOBALS['latex_replace_null'];
|
||||
}
|
||||
|
||||
// last column ... no need for & character
|
||||
if($i == ($columns_cnt - 1)) {
|
||||
$buffer .= $column_value;
|
||||
} else {
|
||||
$buffer .= $column_value . " & ";
|
||||
}
|
||||
}
|
||||
$buffer .= ' \\\\ \\hline ' . $crlf;
|
||||
if (!PMA_exportOutputHandler($buffer)) return FALSE;
|
||||
}
|
||||
|
||||
$buffer = ' \\end{longtable} \\end{table}' . $crlf;
|
||||
if (!PMA_exportOutputHandler($buffer)) return FALSE;
|
||||
|
||||
mysql_free_result($result);
|
||||
return TRUE;
|
||||
|
||||
} // end getTableLaTeX
|
||||
|
||||
/**
|
||||
* Returns $table's structure as LaTeX
|
||||
*
|
||||
* @param string the database name
|
||||
* @param string the table name
|
||||
* @param string the end of line sequence
|
||||
* @param string the url to go back in case of error
|
||||
* @param boolean whether to include relation comments
|
||||
* @param boolean whether to include column comments
|
||||
* @param boolean whether to include mime comments
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false)
|
||||
{
|
||||
global $cfgRelation;
|
||||
|
||||
$tex_escape = array("$", "%", "{", "}", "&", "#", "_", "^");
|
||||
/**
|
||||
* Gets fields properties
|
||||
*/
|
||||
PMA_mysql_select_db($db);
|
||||
$local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
|
||||
$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url);
|
||||
$fields_cnt = mysql_num_rows($result);
|
||||
|
||||
// Check if we can use Relations (Mike Beck)
|
||||
if ($do_relation && !empty($cfgRelation['relation'])) {
|
||||
// Find which tables are related with the current one and write it in
|
||||
// an array
|
||||
$res_rel = PMA_getForeigners($db, $table);
|
||||
|
||||
if ($res_rel && count($res_rel) > 0) {
|
||||
$have_rel = TRUE;
|
||||
} else {
|
||||
$have_rel = FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$have_rel = FALSE;
|
||||
} // end if
|
||||
|
||||
/**
|
||||
* Displays the table structure
|
||||
*/
|
||||
$buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strStructure'] . $crlf . '%' . $crlf
|
||||
. '\\begin{table} ' . $crlf
|
||||
. ' \\begin{longtable}{|';
|
||||
if (!PMA_exportOutputHandler($buffer)) return FALSE;
|
||||
|
||||
$columns_cnt = 4;
|
||||
if ($do_relation && $have_rel) {
|
||||
$columns_cnt++;
|
||||
}
|
||||
if ($do_comments && $cfgRelation['commwork']) {
|
||||
$columns_cnt++;
|
||||
}
|
||||
if ($do_mime && $cfgRelation['mimework']) {
|
||||
$columns_cnt++;
|
||||
}
|
||||
$buffer = '';
|
||||
for($index=0;$index<$columns_cnt;$index++) {
|
||||
$buffer .= 'c|';
|
||||
}
|
||||
$buffer .= '} ' . $crlf ;
|
||||
|
||||
$buffer .= ' \\hline \\endhead \\hline \\endfoot \\hline ' . $crlf;
|
||||
|
||||
$buffer .= $GLOBALS['strField'] . ' & ' . $GLOBALS['strType'] . ' & ' . $GLOBALS['strNull'] . ' & ' . $GLOBALS['strDefault'];
|
||||
if ($do_relation && $have_rel) {
|
||||
$buffer .= ' & ' . $GLOBALS['strLinksTo'];
|
||||
}
|
||||
if ($do_comments && $cfgRelation['commwork']) {
|
||||
$buffer .= ' & ' . $GLOBALS['strComments'];
|
||||
$comments = PMA_getComments($db, $table);
|
||||
}
|
||||
if ($do_mime && $cfgRelation['mimework']) {
|
||||
$buffer .= ' & MIME';
|
||||
$mime_map = PMA_getMIME($db, $table, true);
|
||||
}
|
||||
$buffer .= ' \\\\ \\hline \\hline ' . $crlf;
|
||||
if (!PMA_exportOutputHandler($buffer)) return FALSE;
|
||||
|
||||
while ($row = PMA_mysql_fetch_array($result)) {
|
||||
|
||||
$type = $row['Type'];
|
||||
// reformat mysql query output - staybyte - 9. June 2001
|
||||
// loic1: set or enum types: slashes single quotes inside options
|
||||
if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
|
||||
$tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
|
||||
$type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
|
||||
$type_nowrap = '';
|
||||
|
||||
$binary = 0;
|
||||
$unsigned = 0;
|
||||
$zerofill = 0;
|
||||
} else {
|
||||
$type_nowrap = ' nowrap="nowrap"';
|
||||
$type = eregi_replace('BINARY', '', $type);
|
||||
$type = eregi_replace('ZEROFILL', '', $type);
|
||||
$type = eregi_replace('UNSIGNED', '', $type);
|
||||
if (empty($type)) {
|
||||
$type = ' ';
|
||||
}
|
||||
|
||||
$binary = eregi('BINARY', $row['Type'], $test);
|
||||
$unsigned = eregi('UNSIGNED', $row['Type'], $test);
|
||||
$zerofill = eregi('ZEROFILL', $row['Type'], $test);
|
||||
}
|
||||
$strAttribute = ' ';
|
||||
if ($binary) {
|
||||
$strAttribute = 'BINARY';
|
||||
}
|
||||
if ($unsigned) {
|
||||
$strAttribute = 'UNSIGNED';
|
||||
}
|
||||
if ($zerofill) {
|
||||
$strAttribute = 'UNSIGNED ZEROFILL';
|
||||
}
|
||||
if (!isset($row['Default'])) {
|
||||
if ($row['Null'] != '') {
|
||||
$row['Default'] = 'NULL';
|
||||
}
|
||||
} else {
|
||||
$row['Default'] = $row['Default'];
|
||||
}
|
||||
$field_name = $row['Field'];
|
||||
|
||||
$local_buffer = $field_name . "\000" . $type . "\000" . (($row['Null'] == '') ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . "\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'];
|
||||
}
|
||||
}
|
||||
if ($do_comments && $cfgRelation['commwork']) {
|
||||
$local_buffer .= "\000";
|
||||
if (isset($comments[$field_name])) {
|
||||
$local_buffer .= $comments[$field_name];
|
||||
}
|
||||
}
|
||||
if ($do_mime && $cfgRelation['mimework']) {
|
||||
$local_buffer .= "\000";
|
||||
if (isset($mime_map[$field_name])) {
|
||||
$local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']);
|
||||
}
|
||||
}
|
||||
for($k=0;$k<count($tex_escape);$k++) {
|
||||
$local_buffer = str_replace($tex_escape[$k], '\\' . $tex_escape[$k], $local_buffer);
|
||||
}
|
||||
$buffer = str_replace("\000", ' & ', $local_buffer);
|
||||
$buffer .= ' \\\\ \\hline ' . $crlf;
|
||||
if (!PMA_exportOutputHandler($buffer)) return FALSE;
|
||||
} // end while
|
||||
mysql_free_result($result);
|
||||
$buffer = ' \\end{longtable} \\end{table}' . $crlf;
|
||||
return PMA_exportOutputHandler($buffer);
|
||||
} // end of the 'PMA_getTableStructureLaTeX()' function
|
||||
?>
|
658
libraries/export/sql.php3
Normal file
658
libraries/export/sql.php3
Normal file
@@ -0,0 +1,658 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
/**
|
||||
* Set of functions used to build SQL dumps of tables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns $table's field types
|
||||
*
|
||||
* @param string the database name
|
||||
* @param string the table name
|
||||
*
|
||||
* @return array the field types; key of array is PMA_backquote
|
||||
* of the field name
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* This function exists because mysql_field_type() returns 'blob'
|
||||
* even for 'text' fields.
|
||||
*/
|
||||
function PMA_fieldTypes($db, $table,$use_backquotes) {
|
||||
PMA_mysql_select_db($db);
|
||||
$table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table));
|
||||
while($row = @PMA_mysql_fetch_array($table_def)) {
|
||||
$types[PMA_backquote($row['Field'],$use_backquotes)] = ereg_replace('\\(.*', '', $row['Type']);
|
||||
}
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs comment
|
||||
*
|
||||
* @param string Text of comment
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*/
|
||||
function PMA_exportComment($text) {
|
||||
return PMA_exportOutputHandler('# ' . $text . $GLOBALS['crlf']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader() {
|
||||
global $crlf;
|
||||
global $cfg;
|
||||
|
||||
$head = '# phpMyAdmin SQL Dump' . $crlf
|
||||
. '# version ' . PMA_VERSION . $crlf
|
||||
. '# http://www.phpmyadmin.net' . $crlf
|
||||
. '#' . $crlf
|
||||
. '# ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host'];
|
||||
if (!empty($cfg['Server']['port'])) {
|
||||
$head .= ':' . $cfg['Server']['port'];
|
||||
}
|
||||
$head .= $crlf
|
||||
. '# ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf
|
||||
. '# ' . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3) . $crlf
|
||||
. '# ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf;
|
||||
return PMA_exportOutputHandler($head);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs create database database
|
||||
*
|
||||
* @param string Database name
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db) {
|
||||
global $crlf;
|
||||
if (isset($GLOBALS['drop_database'])) {
|
||||
if (!PMA_exportOutputHandler('DROP DATABASE ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : $db) . ';' . $crlf)) return FALSE;
|
||||
}
|
||||
if (!PMA_exportOutputHandler('CREATE DATABASE ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : $db) . ';' . $crlf)) return FALSE;
|
||||
return PMA_exportOutputHandler('USE ' . $db . ';' . $crlf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string Database name
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db) {
|
||||
global $crlf;
|
||||
$head = '# ' . $crlf
|
||||
. '# ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf
|
||||
. '# ' . $crlf;
|
||||
return PMA_exportOutputHandler($head);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database footer
|
||||
*
|
||||
* @param string Database name
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns $table's CREATE definition
|
||||
*
|
||||
* @param string the database name
|
||||
* @param string the table name
|
||||
* @param string the end of line sequence
|
||||
* @param string the url to go back in case of error
|
||||
* @param boolean whether to include relation comments
|
||||
* @param boolean whether to include column comments
|
||||
* @param boolean whether to include mime comments
|
||||
*
|
||||
* @return string resulting schema
|
||||
*
|
||||
* @global boolean whether to add 'drop' statements or not
|
||||
* @global boolean whether to use backquotes to allow the use of special
|
||||
* characters in database, table and fields names or not
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false)
|
||||
{
|
||||
global $drop;
|
||||
global $use_backquotes;
|
||||
global $cfgRelation;
|
||||
|
||||
$schema_create = '';
|
||||
$auto_increment = '';
|
||||
$new_crlf = $crlf;
|
||||
|
||||
if (PMA_MYSQL_INT_VERSION >= 32321) {
|
||||
$result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table) . '\'');
|
||||
if ($result != FALSE && mysql_num_rows($result) > 0) {
|
||||
$tmpres = PMA_mysql_fetch_array($result);
|
||||
if (!empty($tmpres['Auto_increment'])) {
|
||||
$auto_increment .= ' AUTO_INCREMENT=' . $tmpres['Auto_increment'] . ' ';
|
||||
}
|
||||
|
||||
if (isset($tmpres['Create_time']) && !empty($tmpres['Create_time'])) {
|
||||
$schema_create .= '# ' . $GLOBALS['strStatCreateTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Create_time'])) . $crlf;
|
||||
$new_crlf = '#' . $crlf . $crlf;
|
||||
}
|
||||
|
||||
if (isset($tmpres['Update_time']) && !empty($tmpres['Update_time'])) {
|
||||
$schema_create .= '# ' . $GLOBALS['strStatUpdateTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Update_time'])) . $crlf;
|
||||
$new_crlf = '#' . $crlf . $crlf;
|
||||
}
|
||||
|
||||
if (isset($tmpres['Check_time']) && !empty($tmpres['Check_time'])) {
|
||||
$schema_create .= '# ' . $GLOBALS['strStatCheckTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Check_time'])) . $crlf;
|
||||
$new_crlf = '#' . $crlf . $crlf;
|
||||
}
|
||||
}
|
||||
mysql_free_result($result);
|
||||
}
|
||||
|
||||
$schema_create .= $new_crlf;
|
||||
|
||||
if (!empty($drop)) {
|
||||
$schema_create .= 'DROP TABLE IF EXISTS ' . PMA_backquote($table, $use_backquotes) . ';' . $crlf;
|
||||
}
|
||||
|
||||
if ($do_comments && $cfgRelation['commwork']) {
|
||||
if (!($comments_map = PMA_getComments($db, $table))) unset($comments_map);
|
||||
}
|
||||
|
||||
// Check if we can use Relations (Mike Beck)
|
||||
if ($do_relation && !empty($cfgRelation['relation'])) {
|
||||
// Find which tables are related with the current one and write it in
|
||||
// an array
|
||||
$res_rel = PMA_getForeigners($db, $table);
|
||||
|
||||
if ($res_rel && count($res_rel) > 0) {
|
||||
$have_rel = TRUE;
|
||||
} else {
|
||||
$have_rel = FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$have_rel = FALSE;
|
||||
} // end if
|
||||
|
||||
if ($do_mime && $cfgRelation['mimework']) {
|
||||
if (!($mime_map = PMA_getMIME($db, $table, true))) unset($mime_map);
|
||||
}
|
||||
|
||||
// Steve Alberty's patch for complete table dump,
|
||||
// modified by Lem9 to allow older MySQL versions to continue to work
|
||||
if (PMA_MYSQL_INT_VERSION >= 32321) {
|
||||
// Whether to quote table and fields names or not
|
||||
if ($use_backquotes) {
|
||||
PMA_mysql_query('SET SQL_QUOTE_SHOW_CREATE = 1');
|
||||
} else {
|
||||
PMA_mysql_query('SET SQL_QUOTE_SHOW_CREATE = 0');
|
||||
}
|
||||
$result = PMA_mysql_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table));
|
||||
if ($result != FALSE && mysql_num_rows($result) > 0) {
|
||||
$tmpres = PMA_mysql_fetch_array($result);
|
||||
// Fix for case problems with winwin, thanks to
|
||||
// Pawe<77> Szczepa<70>ski <pauluz at users.sourceforge.net>
|
||||
$pos = strpos($tmpres[1], ' (');
|
||||
|
||||
// Fix a problem with older versions of mysql
|
||||
// Find the first opening parenthesys, i.e. that after the name
|
||||
// of the table
|
||||
$pos2 = strpos($tmpres[1], '(');
|
||||
// Old mysql did not insert a space after table name
|
||||
// in query "show create table ..."!
|
||||
if ($pos2 != $pos + 1)
|
||||
{
|
||||
// This is the real position of the first character after
|
||||
// the name of the table
|
||||
$pos = $pos2;
|
||||
// Old mysql did not even put newlines and indentation...
|
||||
$tmpres[1] = str_replace(",", ",\n ", $tmpres[1]);
|
||||
}
|
||||
|
||||
$tmpres[1] = substr($tmpres[1], 0, 13)
|
||||
. (($use_backquotes) ? PMA_backquote($tmpres[0]) : $tmpres[0])
|
||||
. substr($tmpres[1], $pos);
|
||||
$schema_create .= str_replace("\n", $crlf, $tmpres[1]);
|
||||
}
|
||||
|
||||
$schema_create .= $auto_increment;
|
||||
|
||||
|
||||
// garvin: Because replacing within a direct mysql result is a bit dangerous, just insert comments after that.
|
||||
if (isset($comments_map) && count($comments_map) > 0) {
|
||||
$schema_create .= $crlf . $crlf . '/* COMMENTS FOR TABLE ' . PMA_backquote($table, $use_backquotes) . ':' . $crlf;
|
||||
@reset($comments_map);
|
||||
while(list($comment_field, $comment) = each($comments_map)) {
|
||||
$schema_create .= ' ' . PMA_backquote($comment_field, $use_backquotes) . $crlf . ' ' . PMA_backquote($comment, $use_backquotes) . $crlf;
|
||||
// omitting html_format is intentional. No use for htmlchars in the dump.
|
||||
}
|
||||
$schema_create .= '*/';
|
||||
}
|
||||
|
||||
if (isset($mime_map) && count($mime_map) > 0) {
|
||||
$schema_create .= $crlf . $crlf . '/* MIME TYPES FOR TABLE ' . PMA_backquote($table, $use_backquotes) . ':' . $crlf;
|
||||
@reset($mime_map);
|
||||
while(list($mime_field, $mime) = each($mime_map)) {
|
||||
$schema_create .= ' ' . PMA_backquote($mime_field, $use_backquotes) . $crlf . ' ' . PMA_backquote($mime['mimetype'], $use_backquotes) . $crlf;
|
||||
// omitting html_format is intentional. No use for htmlchars in the dump.
|
||||
}
|
||||
$schema_create .= '*/';
|
||||
}
|
||||
|
||||
if ($have_rel) {
|
||||
$schema_create .= $crlf . $crlf . '/* RELATIONS FOR TABLE ' . PMA_backquote($table, $use_backquotes) . ':' . $crlf;
|
||||
@reset($res_rel);
|
||||
while(list($rel_field, $rel) = each($res_rel)) {
|
||||
$schema_create .= ' ' . PMA_backquote($rel_field, $use_backquotes) . $crlf . ' ' . PMA_backquote($rel['foreign_table'], $use_backquotes) . ' -> ' . PMA_backquote($rel['foreign_field'], $use_backquotes) . $crlf;
|
||||
// omitting html_format is intentional. No use for htmlchars in the dump.
|
||||
}
|
||||
$schema_create .= '*/';
|
||||
}
|
||||
|
||||
mysql_free_result($result);
|
||||
return $schema_create;
|
||||
} // end if MySQL >= 3.23.21
|
||||
|
||||
// For MySQL < 3.23.20
|
||||
$schema_create .= 'CREATE TABLE ' . PMA_backquote($table, $use_backquotes) . ' (' . $crlf;
|
||||
|
||||
$local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
|
||||
$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url);
|
||||
while ($row = PMA_mysql_fetch_array($result)) {
|
||||
$schema_create .= ' ' . PMA_backquote($row['Field'], $use_backquotes) . ' ' . $row['Type'];
|
||||
if (isset($row['Default']) && $row['Default'] != '') {
|
||||
$schema_create .= ' DEFAULT \'' . PMA_sqlAddslashes($row['Default']) . '\'';
|
||||
}
|
||||
if ($row['Null'] != 'YES') {
|
||||
$schema_create .= ' NOT NULL';
|
||||
}
|
||||
if ($row['Extra'] != '') {
|
||||
$schema_create .= ' ' . $row['Extra'];
|
||||
}
|
||||
|
||||
if ($comments && is_array($comments_map) && isset($comments_map[$row['Field']])) {
|
||||
$schema_create .= $crlf . ' /* ' . PMA_backquote($comments_map[$row['Field']], $use_backquotes) . ' */';
|
||||
// omitting html_format is intentional. No use for htmlchars in the dump.
|
||||
}
|
||||
|
||||
$schema_create .= ',' . $crlf;
|
||||
} // end while
|
||||
mysql_free_result($result);
|
||||
$schema_create = ereg_replace(',' . $crlf . '$', '', $schema_create);
|
||||
|
||||
$local_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
|
||||
$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url);
|
||||
while ($row = PMA_mysql_fetch_array($result))
|
||||
{
|
||||
$kname = $row['Key_name'];
|
||||
$comment = (isset($row['Comment'])) ? $row['Comment'] : '';
|
||||
$sub_part = (isset($row['Sub_part'])) ? $row['Sub_part'] : '';
|
||||
|
||||
if ($kname != 'PRIMARY' && $row['Non_unique'] == 0) {
|
||||
$kname = "UNIQUE|$kname";
|
||||
}
|
||||
if ($comment == 'FULLTEXT') {
|
||||
$kname = 'FULLTEXT|$kname';
|
||||
}
|
||||
if (!isset($index[$kname])) {
|
||||
$index[$kname] = array();
|
||||
}
|
||||
if ($sub_part > 1) {
|
||||
$index[$kname][] = PMA_backquote($row['Column_name'], $use_backquotes) . '(' . $sub_part . ')';
|
||||
} else {
|
||||
$index[$kname][] = PMA_backquote($row['Column_name'], $use_backquotes);
|
||||
}
|
||||
} // end while
|
||||
mysql_free_result($result);
|
||||
|
||||
while (list($x, $columns) = @each($index)) {
|
||||
$schema_create .= ',' . $crlf;
|
||||
if ($x == 'PRIMARY') {
|
||||
$schema_create .= ' PRIMARY KEY (';
|
||||
} else if (substr($x, 0, 6) == 'UNIQUE') {
|
||||
$schema_create .= ' UNIQUE ' . substr($x, 7) . ' (';
|
||||
} else if (substr($x, 0, 8) == 'FULLTEXT') {
|
||||
$schema_create .= ' FULLTEXT ' . substr($x, 9) . ' (';
|
||||
} else {
|
||||
$schema_create .= ' KEY ' . $x . ' (';
|
||||
}
|
||||
$schema_create .= implode($columns, ', ') . ')';
|
||||
} // end while
|
||||
|
||||
$schema_create .= $crlf . ')';
|
||||
|
||||
return $schema_create;
|
||||
} // end of the 'PMA_getTableDef()' function
|
||||
|
||||
/**
|
||||
* Outputs table's structure
|
||||
*
|
||||
* @param string the database name
|
||||
* @param string the table name
|
||||
* @param string the end of line sequence
|
||||
* @param string the url to go back in case of error
|
||||
* @param boolean whether to include relation comments
|
||||
* @param boolean whether to include column comments
|
||||
* @param boolean whether to include mime comments
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = FALSE, $comments = FALSE, $mime = FALSE) {
|
||||
$formatted_table_name = (isset($GLOBALS['use_backquotes']))
|
||||
? PMA_backquote($table)
|
||||
: '\'' . $table . '\'';
|
||||
$dump = $crlf
|
||||
. '# --------------------------------------------------------' . $crlf
|
||||
. $crlf . '#' . $crlf
|
||||
. '# ' . $GLOBALS['strTableStructure'] . ' ' . $formatted_table_name . $crlf
|
||||
. '#' . $crlf
|
||||
. PMA_getTableDef($db, $table, $crlf, $error_url, $relation, $comments, $mime) . ';' . $crlf;
|
||||
|
||||
return PMA_exportOutputHandler($dump);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* php >= 4.0.5 only : get the content of $table as a series of INSERT
|
||||
* statements.
|
||||
*
|
||||
* Last revision 13 July 2001: Patch for limiting dump size from
|
||||
* vinay@sanisoft.com & girish@sanisoft.com
|
||||
*
|
||||
* @param string the current database name
|
||||
* @param string the current table name
|
||||
* @param string the end of line sequence
|
||||
* @param string the url to go back in case of error
|
||||
* @param string the sql query
|
||||
*
|
||||
* @return boolean whether it suceeded
|
||||
*
|
||||
* @global boolean whether to use backquotes to allow the use of special
|
||||
* characters in database, table and fields names or not
|
||||
* @global integer the number of records
|
||||
* @global integer the current record position
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @see PMA_getTableContent()
|
||||
*
|
||||
* @author staybyte
|
||||
*/
|
||||
function PMA_getTableContentFast($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
global $use_backquotes;
|
||||
global $rows_cnt;
|
||||
global $current_row;
|
||||
|
||||
$eol_dlm = (isset($GLOBALS['extended_ins']) && ($GLOBALS['current_row'] < $GLOBALS['rows_cnt']))
|
||||
? ','
|
||||
: ';';
|
||||
$buffer = '';
|
||||
|
||||
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url);
|
||||
if ($result != FALSE) {
|
||||
$fields_cnt = mysql_num_fields($result);
|
||||
$rows_cnt = mysql_num_rows($result);
|
||||
|
||||
// get the real types of the table's fields (in an array)
|
||||
// the key of the array is the backquoted field name
|
||||
$field_types = PMA_fieldTypes($db,$table,$use_backquotes);
|
||||
|
||||
// Checks whether the field is an integer or not
|
||||
for ($j = 0; $j < $fields_cnt; $j++) {
|
||||
$field_set[$j] = PMA_backquote(PMA_mysql_field_name($result, $j), $use_backquotes);
|
||||
$type = $field_types[$field_set[$j]];
|
||||
|
||||
if ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' ||
|
||||
$type == 'bigint' ||$type == 'timestamp') {
|
||||
$field_num[$j] = TRUE;
|
||||
} else {
|
||||
$field_num[$j] = FALSE;
|
||||
}
|
||||
// blob
|
||||
if ($type == 'blob' || $type == 'mediumblob' || $type == 'largeblob' || $type == 'tinyblob') {
|
||||
$field_blob[$j] = TRUE;
|
||||
} else {
|
||||
$field_blob[$j] = FALSE;
|
||||
}
|
||||
} // end for
|
||||
|
||||
// Sets the scheme
|
||||
if (isset($GLOBALS['showcolumns'])) {
|
||||
$fields = implode(', ', $field_set);
|
||||
$schema_insert = 'INSERT INTO ' . PMA_backquote($table, $use_backquotes)
|
||||
. ' (' . $fields . ') VALUES (';
|
||||
} else {
|
||||
$schema_insert = 'INSERT INTO ' . PMA_backquote($table, $use_backquotes)
|
||||
. ' VALUES (';
|
||||
}
|
||||
|
||||
$search = array("\x00", "\x0a", "\x0d", "\x1a"); //\x08\\x09, not required
|
||||
$replace = array('\0', '\n', '\r', '\Z');
|
||||
$current_row = 0;
|
||||
|
||||
while ($row = PMA_mysql_fetch_row($result)) {
|
||||
$current_row++;
|
||||
for ($j = 0; $j < $fields_cnt; $j++) {
|
||||
if (!isset($row[$j])) {
|
||||
$values[] = 'NULL';
|
||||
} else if ($row[$j] == '0' || $row[$j] != '') {
|
||||
// a number
|
||||
if ($field_num[$j]) {
|
||||
$values[] = $row[$j];
|
||||
// a not empty blob
|
||||
} else if ($field_blob[$j] && !empty($row[$j])) {
|
||||
$values[] = '0x' . bin2hex($row[$j]);
|
||||
// a string
|
||||
} else {
|
||||
$values[] = "'" . str_replace($search, $replace, PMA_sqlAddslashes($row[$j])) . "'";
|
||||
}
|
||||
} else {
|
||||
$values[] = "''";
|
||||
} // end if
|
||||
} // end for
|
||||
|
||||
// Extended inserts case
|
||||
if (isset($GLOBALS['extended_ins'])) {
|
||||
if ($current_row == 1) {
|
||||
$insert_line = $schema_insert . implode(', ', $values) . ')';
|
||||
} else {
|
||||
$insert_line = '(' . implode(', ', $values) . ')';
|
||||
}
|
||||
}
|
||||
// Other inserts case
|
||||
else {
|
||||
$insert_line = $schema_insert . implode(', ', $values) . ')';
|
||||
}
|
||||
unset($values);
|
||||
|
||||
if (!PMA_exportOutputHandler($insert_line . $eol_dlm . $crlf)) return FALSE;
|
||||
|
||||
} // end while
|
||||
} // end if ($result != FALSE)
|
||||
mysql_free_result($result);
|
||||
|
||||
return TRUE;
|
||||
} // end of the 'PMA_getTableContentFast()' function
|
||||
|
||||
|
||||
/**
|
||||
* php < 4.0.5 only: get the content of $table as a series of INSERT
|
||||
* statements.
|
||||
*
|
||||
* @param string the current database name
|
||||
* @param string the current table name
|
||||
* @param string the end of line sequence
|
||||
* @param string the url to go back in case of error
|
||||
* @param string the sql query
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @global boolean whether to use backquotes to allow the use of special
|
||||
* characters in database, table and fields names or not
|
||||
* @global integer the number of records
|
||||
* @global integer the current record position
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @see PMA_getTableContent()
|
||||
*/
|
||||
function PMA_getTableContentOld($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
global $use_backquotes;
|
||||
global $rows_cnt;
|
||||
global $current_row;
|
||||
|
||||
$eol_dlm = (isset($GLOBALS['extended_ins']) && ($GLOBALS['current_row'] < $GLOBALS['rows_cnt']))
|
||||
? ','
|
||||
: ';';
|
||||
$buffer = '';
|
||||
|
||||
if (!empty($sql_query)) {
|
||||
$local_query = $sql_query . $add_query;
|
||||
PMA_mysql_select_db($db);
|
||||
} else {
|
||||
$local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query;
|
||||
}
|
||||
$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url);
|
||||
$current_row = 0;
|
||||
$fields_cnt = mysql_num_fields($result);
|
||||
$rows_cnt = mysql_num_rows($result);
|
||||
|
||||
|
||||
while ($row = PMA_mysql_fetch_row($result)) {
|
||||
$current_row++;
|
||||
$table_list = '(';
|
||||
for ($j = 0; $j < $fields_cnt; $j++) {
|
||||
$table_list .= PMA_backquote(PMA_mysql_field_name($result, $j), $use_backquotes) . ', ';
|
||||
}
|
||||
$table_list = substr($table_list, 0, -2);
|
||||
$table_list .= ')';
|
||||
|
||||
if (isset($GLOBALS['extended_ins']) && $current_row > 1) {
|
||||
$schema_insert = '(';
|
||||
} else {
|
||||
if (isset($GLOBALS['showcolumns'])) {
|
||||
$schema_insert = 'INSERT INTO ' . PMA_backquote($table, $use_backquotes)
|
||||
. ' ' . $table_list . ' VALUES (';
|
||||
} else {
|
||||
$schema_insert = 'INSERT INTO ' . PMA_backquote($table, $use_backquotes)
|
||||
. ' VALUES (';
|
||||
}
|
||||
$is_first_row = FALSE;
|
||||
}
|
||||
|
||||
|
||||
// get the real types of the table's fields (in an array)
|
||||
// the key of the array is the backquoted field name
|
||||
$field_types = PMA_fieldTypes($db,$table,$use_backquotes);
|
||||
|
||||
for ($j = 0; $j < $fields_cnt; $j++) {
|
||||
if (!isset($row[$j])) {
|
||||
$schema_insert .= ' NULL, ';
|
||||
} else if ($row[$j] == '0' || $row[$j] != '') {
|
||||
$type = $field_types[PMA_backquote(PMA_mysql_field_name($result, $j), $use_backquotes)];
|
||||
|
||||
// a number
|
||||
if ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' ||
|
||||
$type == 'bigint' ||$type == 'timestamp') {
|
||||
$schema_insert .= $row[$j] . ', ';
|
||||
// blob
|
||||
} else if (($type == 'blob' || $type == 'mediumblob' || $type == 'largeblob' || $type == 'tinyblob') && !empty($row[$j])) {
|
||||
$schema_insert .= '0x' . bin2hex($row[$j]) . ', ';
|
||||
// a string
|
||||
} else {
|
||||
$dummy = '';
|
||||
$srcstr = $row[$j];
|
||||
for ($xx = 0; $xx < strlen($srcstr); $xx++) {
|
||||
$yy = strlen($dummy);
|
||||
if ($srcstr[$xx] == '\\') $dummy .= '\\\\';
|
||||
if ($srcstr[$xx] == '\'') $dummy .= '\\\'';
|
||||
// if ($srcstr[$xx] == '"') $dummy .= '\\"';
|
||||
if ($srcstr[$xx] == "\x00") $dummy .= '\0';
|
||||
if ($srcstr[$xx] == "\x0a") $dummy .= '\n';
|
||||
if ($srcstr[$xx] == "\x0d") $dummy .= '\r';
|
||||
// if ($srcstr[$xx] == "\x08") $dummy .= '\b';
|
||||
// if ($srcstr[$xx] == "\t") $dummy .= '\t';
|
||||
if ($srcstr[$xx] == "\x1a") $dummy .= '\Z';
|
||||
if (strlen($dummy) == $yy) $dummy .= $srcstr[$xx];
|
||||
}
|
||||
$schema_insert .= "'" . $dummy . "', ";
|
||||
}
|
||||
} else {
|
||||
$schema_insert .= "'', ";
|
||||
} // end if
|
||||
} // end for
|
||||
$schema_insert = trim(ereg_replace(', $', '', $schema_insert));
|
||||
$schema_insert .= ')';
|
||||
|
||||
if (!PMA_exportOutputHandler($schema_insert . $eol_dlm . $crlf)) return FALSE;
|
||||
} // end while
|
||||
mysql_free_result($result);
|
||||
|
||||
return TRUE;
|
||||
} // end of the 'PMA_getTableContentOld()' function
|
||||
|
||||
|
||||
/**
|
||||
* Dispatches between the versions of 'getTableContent' to use depending
|
||||
* on the php version
|
||||
*
|
||||
* @param string the database name
|
||||
* @param string the table name
|
||||
* @param string the end of line sequence
|
||||
* @param string the url to go back in case of error
|
||||
* @param string SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @see PMA_getTableContentFast(), PMA_getTableContentOld()
|
||||
*
|
||||
* @author staybyte
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
global $crlf;
|
||||
|
||||
$formatted_table_name = (isset($GLOBALS['use_backquotes']))
|
||||
? PMA_backquote($table)
|
||||
: '\'' . $table . '\'';
|
||||
$head = $crlf
|
||||
. '#' . $crlf
|
||||
. '# ' . $GLOBALS['strDumpingData'] . ' ' . $formatted_table_name . $crlf
|
||||
. '#' . $crlf .$crlf;
|
||||
|
||||
if (!PMA_exportOutputHandler($head)) return FALSE;
|
||||
// Call the working function depending on the php version
|
||||
if (PMA_PHP_INT_VERSION >= 40005) {
|
||||
return PMA_getTableContentFast($db, $table, $crlf, $error_url, $sql_query);
|
||||
} else {
|
||||
return PMA_getTableContentOld($db, $table, $crlf, $error_url, $sql_query);
|
||||
}
|
||||
} // end of the 'PMA_exportData()' function
|
||||
?>
|
139
libraries/export/xml.php3
Normal file
139
libraries/export/xml.php3
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
/**
|
||||
* Set of functions used to build XML dumps of tables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Outputs comment
|
||||
*
|
||||
* @param string Text of comment
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*/
|
||||
function PMA_exportComment($text) {
|
||||
return PMA_exportOutputHandler('<!-- ' . $text . ' -->' . $GLOBALS['crlf']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader() {
|
||||
global $crlf;
|
||||
global $cfg;
|
||||
|
||||
$head = '<!--' . $crlf
|
||||
. '-' . $crlf
|
||||
. '- phpMyAdmin XML Dump' . $crlf
|
||||
. '- version ' . PMA_VERSION . $crlf
|
||||
. '- http://www.phpmyadmin.net' . $crlf
|
||||
. '-' . $crlf
|
||||
. '- ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host'];
|
||||
if (!empty($cfg['Server']['port'])) {
|
||||
$head .= ':' . $cfg['Server']['port'];
|
||||
}
|
||||
$head .= $crlf
|
||||
. '- ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf
|
||||
. '- ' . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3) . $crlf
|
||||
. '- ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf
|
||||
. '-->' . $crlf . $crlf;
|
||||
return PMA_exportOutputHandler($head);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string Database name
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db) {
|
||||
global $crlf;
|
||||
$head = '<!--' . $crlf
|
||||
. '- ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf
|
||||
. '-->' . $crlf
|
||||
. '<' . $db . '>' . $crlf;
|
||||
return PMA_exportOutputHandler($head);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database footer
|
||||
*
|
||||
* @param string Database name
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db) {
|
||||
global $crlf;
|
||||
return PMA_exportOutputHandler('</' . $db . '>' . $crlf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs create database database
|
||||
*
|
||||
* @param string Database name
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Outputs the content of a table
|
||||
*
|
||||
* @param string the database name
|
||||
* @param string the table name
|
||||
* @param string the end of line sequence
|
||||
* @param string the url to go back in case of error
|
||||
* @param string SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it suceeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
|
||||
$local_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
|
||||
$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url);
|
||||
for ($i = 0; $row = PMA_mysql_fetch_array($result, MYSQL_ASSOC); $i++) {
|
||||
$columns[$i] = $row['Field'];
|
||||
}
|
||||
$columns_cnt = count($columns);
|
||||
unset($i);
|
||||
mysql_free_result($result);
|
||||
|
||||
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url);
|
||||
$buffer = ' <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf;
|
||||
if (!PMA_exportOutputHandler($buffer)) return FALSE;
|
||||
|
||||
while ($record = PMA_mysql_fetch_array($result, MYSQL_ASSOC)) {
|
||||
$buffer = ' <' . $table . '>' . $crlf;
|
||||
for ($i = 0; $i < $columns_cnt; $i++) {
|
||||
// There is no way to dectect a "NULL" value with PHP3
|
||||
if ( isset($record[$columns[$i]]) && (!function_exists('is_null') || !is_null($record[$columns[$i]]))) {
|
||||
$buffer .= ' <' . $columns[$i] . '>' . htmlspecialchars($record[$columns[$i]])
|
||||
. '</' . $columns[$i] . '>' . $crlf;
|
||||
}
|
||||
}
|
||||
$buffer .= ' </' . $table . '>' . $crlf;
|
||||
|
||||
if (!PMA_exportOutputHandler($buffer)) return FALSE;
|
||||
}
|
||||
mysql_free_result($result);
|
||||
|
||||
return TRUE;
|
||||
} // end of the 'PMA_getTableXML()' function
|
||||
?>
|
Reference in New Issue
Block a user