[Phpmyadmin-git] [SCM] phpMyAdmin branch, master, updated. RELEASE_3_4_3_1-8731-g8ff9a1b
Piotr Przybylski
crackpl at users.sourceforge.net
Thu Jul 14 21:33:37 CEST 2011
The branch, master has been updated
via 8ff9a1bb7860ff30da83f1eca0860f81a767a637 (commit)
via ff7116bf7eed70f8848cdc1ba1702c5cf1cc8125 (commit)
via 4ec9c3b09c0c716c008423efd52ea1202fe36679 (commit)
via f1bcbb500aa38ddd174480da8adee217ce7decfd (commit)
via 94b83dc3e9bc46d090c4f5250294f378bb9cf0c3 (commit)
from 117dd687575b4af0f24ae6f79773122a5a133a23 (commit)
- Log -----------------------------------------------------------------
commit 8ff9a1bb7860ff30da83f1eca0860f81a767a637
Author: Piotr Przybylski <piotrprz at gmail.com>
Date: Thu Jul 14 21:30:47 2011 +0200
Whitespace
commit ff7116bf7eed70f8848cdc1ba1702c5cf1cc8125
Author: Piotr Przybylski <piotrprz at gmail.com>
Date: Thu Jul 14 21:28:41 2011 +0200
Fix CodeGen export
commit 4ec9c3b09c0c716c008423efd52ea1202fe36679
Author: Piotr Przybylski <piotrprz at gmail.com>
Date: Thu Jul 14 21:13:47 2011 +0200
Use PMA_DBI_get_columns in mediawiki export
commit f1bcbb500aa38ddd174480da8adee217ce7decfd
Author: Piotr Przybylski <piotrprz at gmail.com>
Date: Thu Jul 14 02:37:21 2011 +0200
Use PMA_DBI_get_columns in latex export
commit 94b83dc3e9bc46d090c4f5250294f378bb9cf0c3
Author: Piotr Przybylski <piotrprz at gmail.com>
Date: Thu Jul 14 02:36:09 2011 +0200
Escape column name in PMA_DBI_get_columns_full
-----------------------------------------------------------------------
Summary of changes:
libraries/database_interface.lib.php | 2 +-
libraries/export/codegen.php | 340 ++++++++++++++++++----------------
libraries/export/latex.php | 12 +-
libraries/export/mediawiki.php | 18 +-
4 files changed, 192 insertions(+), 180 deletions(-)
diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php
index ef2783d..ca50600 100644
--- a/libraries/database_interface.lib.php
+++ b/libraries/database_interface.lib.php
@@ -769,7 +769,7 @@ function PMA_DBI_get_columns_full($database = null, $table = null,
$sql = 'SHOW FULL COLUMNS FROM '
. PMA_backquote($database) . '.' . PMA_backquote($table);
if (null !== $column) {
- $sql .= " LIKE '" . $column . "'";
+ $sql .= " LIKE '" . PMA_sqlAddSlashes($column, true) . "'";
}
$columns = PMA_DBI_fetch_result($sql, 'Field', null, $link);
diff --git a/libraries/export/codegen.php b/libraries/export/codegen.php
index fb81cf9..ffed7d1 100644
--- a/libraries/export/codegen.php
+++ b/libraries/export/codegen.php
@@ -123,12 +123,12 @@ function PMA_exportDBCreate($db)
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
- global $CG_FORMATS, $CG_HANDLERS;
- $format = cgGetOption("format");
- $index = array_search($format, $CG_FORMATS);
- if ($index >= 0)
- return PMA_exportOutputHandler($CG_HANDLERS[$index]($db, $table, $crlf));
- return PMA_exportOutputHandler(sprintf("%s is not supported.", $format));
+ global $CG_FORMATS, $CG_HANDLERS;
+ $format = cgGetOption("format");
+ if (isset($CG_FORMATS[$format])) {
+ return PMA_exportOutputHandler($CG_HANDLERS[$format]($db, $table, $crlf));
+ }
+ return PMA_exportOutputHandler(sprintf("%s is not supported.", $format));
}
/**
@@ -138,162 +138,184 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
*/
class TableProperty
{
- public $name;
- public $type;
- public $nullable;
- public $key;
- public $defaultValue;
- public $ext;
- function __construct($row)
- {
- $this->name = trim($row[0]);
- $this->type = trim($row[1]);
- $this->nullable = trim($row[2]);
- $this->key = trim($row[3]);
- $this->defaultValue = trim($row[4]);
- $this->ext = trim($row[5]);
- }
- function getPureType()
- {
- $pos=strpos($this->type, "(");
- if ($pos > 0)
- return substr($this->type, 0, $pos);
- return $this->type;
- }
- function isNotNull()
- {
- return $this->nullable == "NO" ? "true" : "false";
- }
- function isUnique()
- {
- return $this->key == "PRI" || $this->key == "UNI" ? "true" : "false";
- }
- function getDotNetPrimitiveType()
- {
- if (strpos($this->type, "int") === 0) return "int";
- if (strpos($this->type, "long") === 0) return "long";
- if (strpos($this->type, "char") === 0) return "string";
- if (strpos($this->type, "varchar") === 0) return "string";
- if (strpos($this->type, "text") === 0) return "string";
- if (strpos($this->type, "longtext") === 0) return "string";
- if (strpos($this->type, "tinyint") === 0) return "bool";
- if (strpos($this->type, "datetime") === 0) return "DateTime";
- return "unknown";
- }
- function getDotNetObjectType()
- {
- if (strpos($this->type, "int") === 0) return "Int32";
- if (strpos($this->type, "long") === 0) return "Long";
- if (strpos($this->type, "char") === 0) return "String";
- if (strpos($this->type, "varchar") === 0) return "String";
- if (strpos($this->type, "text") === 0) return "String";
- if (strpos($this->type, "longtext") === 0) return "String";
- if (strpos($this->type, "tinyint") === 0) return "Boolean";
- if (strpos($this->type, "datetime") === 0) return "DateTime";
- return "Unknown";
- }
- function getIndexName()
- {
- if (strlen($this->key)>0)
- return "index=\"" . $this->name . "\"";
- return "";
- }
- function isPK()
- {
- return $this->key=="PRI";
- }
- function format($pattern)
- {
- $text=$pattern;
- $text=str_replace("#name#", $this->name, $text);
- $text=str_replace("#type#", $this->getPureType(), $text);
- $text=str_replace("#notNull#", $this->isNotNull(), $text);
- $text=str_replace("#unique#", $this->isUnique(), $text);
- $text=str_replace("#ucfirstName#", ucfirst($this->name), $text);
- $text=str_replace("#dotNetPrimitiveType#", $this->getDotNetPrimitiveType(), $text);
- $text=str_replace("#dotNetObjectType#", $this->getDotNetObjectType(), $text);
- $text=str_replace("#indexName#", $this->getIndexName(), $text);
- return $text;
- }
+ public $name;
+ public $type;
+ public $nullable;
+ public $key;
+ public $defaultValue;
+ public $ext;
+ function __construct($row)
+ {
+ $this->name = trim($row[0]);
+ $this->type = trim($row[1]);
+ $this->nullable = trim($row[2]);
+ $this->key = trim($row[3]);
+ $this->defaultValue = trim($row[4]);
+ $this->ext = trim($row[5]);
+ }
+ function getPureType()
+ {
+ $pos=strpos($this->type, "(");
+ if ($pos > 0)
+ return substr($this->type, 0, $pos);
+ return $this->type;
+ }
+ function isNotNull()
+ {
+ return $this->nullable == "NO" ? "true" : "false";
+ }
+ function isUnique()
+ {
+ return $this->key == "PRI" || $this->key == "UNI" ? "true" : "false";
+ }
+ function getDotNetPrimitiveType()
+ {
+ if (strpos($this->type, "int") === 0) return "int";
+ if (strpos($this->type, "long") === 0) return "long";
+ if (strpos($this->type, "char") === 0) return "string";
+ if (strpos($this->type, "varchar") === 0) return "string";
+ if (strpos($this->type, "text") === 0) return "string";
+ if (strpos($this->type, "longtext") === 0) return "string";
+ if (strpos($this->type, "tinyint") === 0) return "bool";
+ if (strpos($this->type, "datetime") === 0) return "DateTime";
+ return "unknown";
+ }
+ function getDotNetObjectType()
+ {
+ if (strpos($this->type, "int") === 0) return "Int32";
+ if (strpos($this->type, "long") === 0) return "Long";
+ if (strpos($this->type, "char") === 0) return "String";
+ if (strpos($this->type, "varchar") === 0) return "String";
+ if (strpos($this->type, "text") === 0) return "String";
+ if (strpos($this->type, "longtext") === 0) return "String";
+ if (strpos($this->type, "tinyint") === 0) return "Boolean";
+ if (strpos($this->type, "datetime") === 0) return "DateTime";
+ return "Unknown";
+ }
+ function getIndexName()
+ {
+ if (strlen($this->key)>0)
+ return "index=\"" . htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8') . "\"";
+ return "";
+ }
+ function isPK()
+ {
+ return $this->key=="PRI";
+ }
+ function formatCs($text)
+ {
+ $text=str_replace("#name#", cgMakeIdentifier($this->name, false), $text);
+ return $this->format($text);
+ }
+ function formatXml($text)
+ {
+ $text=str_replace("#name#", htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8'), $text);
+ $text=str_replace("#indexName#", $this->getIndexName(), $text);
+ return $this->format($text);
+ }
+ function format($text)
+ {
+ $text=str_replace("#ucfirstName#", cgMakeIdentifier($this->name), $text);
+ $text=str_replace("#dotNetPrimitiveType#", $this->getDotNetPrimitiveType(), $text);
+ $text=str_replace("#dotNetObjectType#", $this->getDotNetObjectType(), $text);
+ $text=str_replace("#type#", $this->getPureType(), $text);
+ $text=str_replace("#notNull#", $this->isNotNull(), $text);
+ $text=str_replace("#unique#", $this->isUnique(), $text);
+ return $text;
+ }
}
- function handleNHibernateCSBody($db, $table, $crlf)
- {
- $lines=array();
- $result=PMA_DBI_query(sprintf("DESC %s.%s", PMA_backquote($db), PMA_backquote($table)));
- if ($result)
- {
- $tableProperties=array();
- while ($row = PMA_DBI_fetch_row($result))
- $tableProperties[] = new TableProperty($row);
- $lines[] = "using System;";
- $lines[] = "using System.Collections;";
- $lines[] = "using System.Collections.Generic;";
- $lines[] = "using System.Text;";
- $lines[] = "namespace ".ucfirst($db);
- $lines[] = "{";
- $lines[] = " #region ".ucfirst($table);
- $lines[] = " public class ".ucfirst($table);
- $lines[] = " {";
- $lines[] = " #region Member Variables";
- foreach ($tableProperties as $tablePropertie)
- $lines[] = $tablePropertie->format(" protected #dotNetPrimitiveType# _#name#;");
- $lines[] = " #endregion";
- $lines[] = " #region Constructors";
- $lines[] = " public ".ucfirst($table)."() { }";
- $temp = array();
- foreach ($tableProperties as $tablePropertie)
- if (! $tablePropertie->isPK())
- $temp[] = $tablePropertie->format("#dotNetPrimitiveType# #name#");
- $lines[] = " public ".ucfirst($table)."(".implode(", ", $temp).")";
- $lines[] = " {";
- foreach ($tableProperties as $tablePropertie)
- if (! $tablePropertie->isPK())
- $lines[] = $tablePropertie->format(" this._#name#=#name#;");
- $lines[] = " }";
- $lines[] = " #endregion";
- $lines[] = " #region Public Properties";
- foreach ($tableProperties as $tablePropertie)
- $lines[] = $tablePropertie->format(" public virtual #dotNetPrimitiveType# _#ucfirstName#\n {\n get {return _#name#;}\n set {_#name#=value;}\n }");
- $lines[] = " #endregion";
- $lines[] = " }";
- $lines[] = " #endregion";
- $lines[] = "}";
- PMA_DBI_free_result($result);
- }
- return implode("\n", $lines);
- }
+ function cgMakeIdentifier($str, $ucfirst = true)
+ {
+ // remove unsafe characters
+ $str = preg_replace('/[^\p{L}\p{Nl}_]/u', '', $str);
+ // make sure first character is a letter or _
+ if (!preg_match('/^\pL/u', $str)) {
+ $str = '_' . $str;
+ }
+ if ($ucfirst) {
+ $str = ucfirst($str);
+ }
+ return $str;
+ }
- function handleNHibernateXMLBody($db, $table, $crlf)
- {
- $lines=array();
- $lines[] = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
- $lines[] = "<hibernate-mapping xmlns=\"urn:nhibernate-mapping-2.2\" namespace=\"".ucfirst(htmlspecialchars($db, ENT_COMPAT, 'UTF-8'))."\" assembly=\"".ucfirst(htmlspecialchars($db, ENT_COMPAT, 'UTF-8'))."\">";
- $lines[] = " <class name=\"".ucfirst(htmlspecialchars($table, ENT_COMPAT, 'UTF-8'))."\" table=\"".htmlspecialchars($table, ENT_COMPAT, 'UTF-8')."\">";
- $result = PMA_DBI_query(sprintf("DESC %s.%s", PMA_backquote($db), PMA_backquote($table)));
- if ($result)
- {
- $tableProperties = array();
- while ($row = PMA_DBI_fetch_row($result))
- $tableProperties[] = new TableProperty($row);
- foreach ($tableProperties as $tablePropertie)
- {
- if ($tablePropertie->isPK())
- $lines[] = $tablePropertie->format(" <id name=\"#ucfirstName#\" type=\"#dotNetObjectType#\" unsaved-value=\"0\">\n <column name=\"#name#\" sql-type=\"#type#\" not-null=\"#notNull#\" unique=\"#unique#\" index=\"PRIMARY\"/>\n <generator class=\"native\" />\n </id>");
- else
- $lines[] = $tablePropertie->format(" <property name=\"#ucfirstName#\" type=\"#dotNetObjectType#\">\n <column name=\"#name#\" sql-type=\"#type#\" not-null=\"#notNull#\" #indexName#/>\n </property>");
- }
- PMA_DBI_free_result($result);
- }
- $lines[]=" </class>";
- $lines[]="</hibernate-mapping>";
- return implode("\n", $lines);
- }
+ function handleNHibernateCSBody($db, $table, $crlf)
+ {
+ $lines=array();
+ $result=PMA_DBI_query(sprintf("DESC %s.%s", PMA_backquote($db), PMA_backquote($table)));
+ if ($result)
+ {
+ $tableProperties=array();
+ while ($row = PMA_DBI_fetch_row($result))
+ $tableProperties[] = new TableProperty($row);
+ $lines[] = "using System;";
+ $lines[] = "using System.Collections;";
+ $lines[] = "using System.Collections.Generic;";
+ $lines[] = "using System.Text;";
+ $lines[] = "namespace ".cgMakeIdentifier($db);
+ $lines[] = "{";
+ $lines[] = " #region ".cgMakeIdentifier($table);
+ $lines[] = " public class ".cgMakeIdentifier($table);
+ $lines[] = " {";
+ $lines[] = " #region Member Variables";
+ foreach ($tableProperties as $tablePropertie)
+ $lines[] = $tablePropertie->formatCs(" protected #dotNetPrimitiveType# _#name#;");
+ $lines[] = " #endregion";
+ $lines[] = " #region Constructors";
+ $lines[] = " public ".cgMakeIdentifier($table)."() { }";
+ $temp = array();
+ foreach ($tableProperties as $tablePropertie)
+ if (! $tablePropertie->isPK())
+ $temp[] = $tablePropertie->formatCs("#dotNetPrimitiveType# #name#");
+ $lines[] = " public ".cgMakeIdentifier($table)."(".implode(", ", $temp).")";
+ $lines[] = " {";
+ foreach ($tableProperties as $tablePropertie)
+ if (! $tablePropertie->isPK())
+ $lines[] = $tablePropertie->formatCs(" this._#name#=#name#;");
+ $lines[] = " }";
+ $lines[] = " #endregion";
+ $lines[] = " #region Public Properties";
+ foreach ($tableProperties as $tablePropertie)
+ $lines[] = $tablePropertie->formatCs(" public virtual #dotNetPrimitiveType# #ucfirstName#\n {\n get {return _#name#;}\n set {_#name#=value;}\n }");
+ $lines[] = " #endregion";
+ $lines[] = " }";
+ $lines[] = " #endregion";
+ $lines[] = "}";
+ PMA_DBI_free_result($result);
+ }
+ return implode("\n", $lines);
+ }
- function cgGetOption($optionName)
- {
- global $what;
- return $GLOBALS[$what . "_" . $optionName];
- }
+ function handleNHibernateXMLBody($db, $table, $crlf)
+ {
+ $lines=array();
+ $lines[] = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
+ $lines[] = "<hibernate-mapping xmlns=\"urn:nhibernate-mapping-2.2\" namespace=\"".cgMakeIdentifier($db)."\" assembly=\"".cgMakeIdentifier($db)."\">";
+ $lines[] = " <class name=\"".cgMakeIdentifier($table)."\" table=\"".cgMakeIdentifier($table)."\">";
+ $result = PMA_DBI_query(sprintf("DESC %s.%s", PMA_backquote($db), PMA_backquote($table)));
+ if ($result)
+ {
+ $tableProperties = array();
+ while ($row = PMA_DBI_fetch_row($result))
+ $tableProperties[] = new TableProperty($row);
+ foreach ($tableProperties as $tablePropertie)
+ {
+ if ($tablePropertie->isPK())
+ $lines[] = $tablePropertie->formatXml(" <id name=\"#ucfirstName#\" type=\"#dotNetObjectType#\" unsaved-value=\"0\">\n <column name=\"#name#\" sql-type=\"#type#\" not-null=\"#notNull#\" unique=\"#unique#\" index=\"PRIMARY\"/>\n <generator class=\"native\" />\n </id>");
+ else
+ $lines[] = $tablePropertie->formatXml(" <property name=\"#ucfirstName#\" type=\"#dotNetObjectType#\">\n <column name=\"#name#\" sql-type=\"#type#\" not-null=\"#notNull#\" #indexName#/>\n </property>");
+ }
+ PMA_DBI_free_result($result);
+ }
+ $lines[]=" </class>";
+ $lines[]="</hibernate-mapping>";
+ return implode("\n", $lines);
+ }
+
+ function cgGetOption($optionName)
+ {
+ global $what;
+ return $GLOBALS[$what . "_" . $optionName];
+ }
}
?>
diff --git a/libraries/export/latex.php b/libraries/export/latex.php
index 96be536..0742109 100644
--- a/libraries/export/latex.php
+++ b/libraries/export/latex.php
@@ -316,9 +316,6 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals
* Gets fields properties
*/
PMA_DBI_select_db($db);
- $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
- $result = PMA_DBI_query($local_query);
- $fields_cnt = PMA_DBI_num_rows($result);
// Check if we can use Relations
if ($do_relation && !empty($cfgRelation['relation'])) {
@@ -374,8 +371,6 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals
$mime_map = PMA_getMIME($db, $table, true);
}
- $local_buffer = PMA_texEscape($table);
-
// Table caption for first page and label
if (isset($GLOBALS['latex_caption'])) {
$buffer .= ' \\caption{'. PMA_expandUserString($GLOBALS['latex_structure_caption'], 'PMA_texEscape', array('table' => $table, 'database' => $db))
@@ -394,8 +389,8 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals
return false;
}
- while ($row = PMA_DBI_fetch_assoc($result)) {
-
+ $fields = PMA_DBI_get_columns($db, $table);
+ foreach ($fields as $row) {
$type = $row['Type'];
// reformat mysql query output
// set or enum types: slashes single quotes inside options
@@ -424,8 +419,6 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals
if ($row['Null'] != 'NO') {
$row['Default'] = 'NULL';
}
- } else {
- $row['Default'] = $row['Default'];
}
$field_name = $row['Field'];
@@ -468,7 +461,6 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals
return false;
}
} // end while
- PMA_DBI_free_result($result);
$buffer = ' \\end{longtable}' . $crlf;
return PMA_exportOutputHandler($buffer);
diff --git a/libraries/export/mediawiki.php b/libraries/export/mediawiki.php
index 76c8b2a..7599df9 100644
--- a/libraries/export/mediawiki.php
+++ b/libraries/export/mediawiki.php
@@ -95,18 +95,16 @@ function PMA_exportDBCreate($db) {
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
- global $mediawiki_export_struct;
- global $mediawiki_export_data;
-
- $result = PMA_DBI_fetch_result("SHOW COLUMNS FROM `" . $db . "`.`" . $table . "`");
- $row_cnt = count($result);
+ $columns = PMA_DBI_get_columns($db, $table);
+ $columns = array_values($columns);
+ $row_cnt = count($columns);
$output = "{| cellpadding=\"10\" cellspacing=\"0\" border=\"1\" style=\"text-align:center;\"\n";
$output .= "|+'''" . $table . "'''\n";
$output .= "|- style=\"background:#ffdead;\"\n";
$output .= "! style=\"background:#ffffff\" | \n";
for ($i = 0; $i < $row_cnt; ++$i) {
- $output .= " | " . $result[$i]['Field'];
+ $output .= " | " . $columns[$i]['Field'];
if (($i + 1) != $row_cnt) {
$output .= "\n";
}
@@ -116,7 +114,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
$output .= "|- style=\"background:#f9f9f9;\"\n";
$output .= "! style=\"background:#f2f2f2\" | Type\n";
for ($i = 0; $i < $row_cnt; ++$i) {
- $output .= " | " . $result[$i]['Type'];
+ $output .= " | " . $columns[$i]['Type'];
if (($i + 1) != $row_cnt) {
$output .= "\n";
}
@@ -126,7 +124,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
$output .= "|- style=\"background:#f9f9f9;\"\n";
$output .= "! style=\"background:#f2f2f2\" | Null\n";
for ($i = 0; $i < $row_cnt; ++$i) {
- $output .= " | " . $result[$i]['Null'];
+ $output .= " | " . $columns[$i]['Null'];
if (($i + 1) != $row_cnt) {
$output .= "\n";
}
@@ -136,7 +134,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
$output .= "|- style=\"background:#f9f9f9;\"\n";
$output .= "! style=\"background:#f2f2f2\" | Default\n";
for ($i = 0; $i < $row_cnt; ++$i) {
- $output .= " | " . $result[$i]['Default'];
+ $output .= " | " . $columns[$i]['Default'];
if (($i + 1) != $row_cnt) {
$output .= "\n";
}
@@ -146,7 +144,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
$output .= "|- style=\"background:#f9f9f9;\"\n";
$output .= "! style=\"background:#f2f2f2\" | Extra\n";
for ($i = 0; $i < $row_cnt; ++$i) {
- $output .= " | " . $result[$i]['Extra'];
+ $output .= " | " . $columns[$i]['Extra'];
if (($i + 1) != $row_cnt) {
$output .= "\n";
}
hooks/post-receive
--
phpMyAdmin
More information about the Git
mailing list