Fix CodeGen export
This commit is contained in:
@@ -138,12 +138,12 @@ function PMA_exportDBCreate($db)
|
|||||||
*/
|
*/
|
||||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||||
{
|
{
|
||||||
global $CG_FORMATS, $CG_HANDLERS;
|
global $CG_FORMATS, $CG_HANDLERS;
|
||||||
$format = cgGetOption("format");
|
$format = cgGetOption("format");
|
||||||
$index = array_search($format, $CG_FORMATS);
|
if (isset($CG_FORMATS[$format])) {
|
||||||
if ($index >= 0)
|
return PMA_exportOutputHandler($CG_HANDLERS[$format]($db, $table, $crlf));
|
||||||
return PMA_exportOutputHandler($CG_HANDLERS[$index]($db, $table, $crlf));
|
}
|
||||||
return PMA_exportOutputHandler(sprintf("%s is not supported.", $format));
|
return PMA_exportOutputHandler(sprintf("%s is not supported.", $format));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -209,28 +209,50 @@ class TableProperty
|
|||||||
function getIndexName()
|
function getIndexName()
|
||||||
{
|
{
|
||||||
if (strlen($this->key)>0)
|
if (strlen($this->key)>0)
|
||||||
return "index=\"" . $this->name . "\"";
|
return "index=\"" . htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8') . "\"";
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
function isPK()
|
function isPK()
|
||||||
{
|
{
|
||||||
return $this->key=="PRI";
|
return $this->key=="PRI";
|
||||||
}
|
}
|
||||||
function format($pattern)
|
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=$pattern;
|
$text=str_replace("#ucfirstName#", cgMakeIdentifier($this->name), $text);
|
||||||
$text=str_replace("#name#", $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("#type#", $this->getPureType(), $text);
|
||||||
$text=str_replace("#notNull#", $this->isNotNull(), $text);
|
$text=str_replace("#notNull#", $this->isNotNull(), $text);
|
||||||
$text=str_replace("#unique#", $this->isUnique(), $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;
|
return $text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 handleNHibernateCSBody($db, $table, $crlf)
|
function handleNHibernateCSBody($db, $table, $crlf)
|
||||||
{
|
{
|
||||||
$lines=array();
|
$lines=array();
|
||||||
@@ -244,31 +266,31 @@ class TableProperty
|
|||||||
$lines[] = "using System.Collections;";
|
$lines[] = "using System.Collections;";
|
||||||
$lines[] = "using System.Collections.Generic;";
|
$lines[] = "using System.Collections.Generic;";
|
||||||
$lines[] = "using System.Text;";
|
$lines[] = "using System.Text;";
|
||||||
$lines[] = "namespace ".ucfirst($db);
|
$lines[] = "namespace ".cgMakeIdentifier($db);
|
||||||
$lines[] = "{";
|
$lines[] = "{";
|
||||||
$lines[] = " #region ".ucfirst($table);
|
$lines[] = " #region ".cgMakeIdentifier($table);
|
||||||
$lines[] = " public class ".ucfirst($table);
|
$lines[] = " public class ".cgMakeIdentifier($table);
|
||||||
$lines[] = " {";
|
$lines[] = " {";
|
||||||
$lines[] = " #region Member Variables";
|
$lines[] = " #region Member Variables";
|
||||||
foreach ($tableProperties as $tablePropertie)
|
foreach ($tableProperties as $tablePropertie)
|
||||||
$lines[] = $tablePropertie->format(" protected #dotNetPrimitiveType# _#name#;");
|
$lines[] = $tablePropertie->formatCs(" protected #dotNetPrimitiveType# _#name#;");
|
||||||
$lines[] = " #endregion";
|
$lines[] = " #endregion";
|
||||||
$lines[] = " #region Constructors";
|
$lines[] = " #region Constructors";
|
||||||
$lines[] = " public ".ucfirst($table)."() { }";
|
$lines[] = " public ".cgMakeIdentifier($table)."() { }";
|
||||||
$temp = array();
|
$temp = array();
|
||||||
foreach ($tableProperties as $tablePropertie)
|
foreach ($tableProperties as $tablePropertie)
|
||||||
if (! $tablePropertie->isPK())
|
if (! $tablePropertie->isPK())
|
||||||
$temp[] = $tablePropertie->format("#dotNetPrimitiveType# #name#");
|
$temp[] = $tablePropertie->formatCs("#dotNetPrimitiveType# #name#");
|
||||||
$lines[] = " public ".ucfirst($table)."(".implode(", ", $temp).")";
|
$lines[] = " public ".cgMakeIdentifier($table)."(".implode(", ", $temp).")";
|
||||||
$lines[] = " {";
|
$lines[] = " {";
|
||||||
foreach ($tableProperties as $tablePropertie)
|
foreach ($tableProperties as $tablePropertie)
|
||||||
if (! $tablePropertie->isPK())
|
if (! $tablePropertie->isPK())
|
||||||
$lines[] = $tablePropertie->format(" this._#name#=#name#;");
|
$lines[] = $tablePropertie->formatCs(" this._#name#=#name#;");
|
||||||
$lines[] = " }";
|
$lines[] = " }";
|
||||||
$lines[] = " #endregion";
|
$lines[] = " #endregion";
|
||||||
$lines[] = " #region Public Properties";
|
$lines[] = " #region Public Properties";
|
||||||
foreach ($tableProperties as $tablePropertie)
|
foreach ($tableProperties as $tablePropertie)
|
||||||
$lines[] = $tablePropertie->format(" public virtual #dotNetPrimitiveType# _#ucfirstName#\n {\n get {return _#name#;}\n set {_#name#=value;}\n }");
|
$lines[] = $tablePropertie->formatCs(" public virtual #dotNetPrimitiveType# #ucfirstName#\n {\n get {return _#name#;}\n set {_#name#=value;}\n }");
|
||||||
$lines[] = " #endregion";
|
$lines[] = " #endregion";
|
||||||
$lines[] = " }";
|
$lines[] = " }";
|
||||||
$lines[] = " #endregion";
|
$lines[] = " #endregion";
|
||||||
@@ -282,8 +304,8 @@ class TableProperty
|
|||||||
{
|
{
|
||||||
$lines=array();
|
$lines=array();
|
||||||
$lines[] = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
|
$lines[] = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
|
||||||
$lines[] = "<hibernate-mapping xmlns=\"urn:nhibernate-mapping-2.2\" namespace=\"".ucfirst($db)."\" assembly=\"".ucfirst($db)."\">";
|
$lines[] = "<hibernate-mapping xmlns=\"urn:nhibernate-mapping-2.2\" namespace=\"".cgMakeIdentifier($db)."\" assembly=\"".cgMakeIdentifier($db)."\">";
|
||||||
$lines[] = " <class name=\"".ucfirst($table)."\" table=\"".$table."\">";
|
$lines[] = " <class name=\"".cgMakeIdentifier($table)."\" table=\"".cgMakeIdentifier($table)."\">";
|
||||||
$result = PMA_DBI_query(sprintf("DESC %s.%s", PMA_backquote($db), PMA_backquote($table)));
|
$result = PMA_DBI_query(sprintf("DESC %s.%s", PMA_backquote($db), PMA_backquote($table)));
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
@@ -293,9 +315,9 @@ class TableProperty
|
|||||||
foreach ($tableProperties as $tablePropertie)
|
foreach ($tableProperties as $tablePropertie)
|
||||||
{
|
{
|
||||||
if ($tablePropertie->isPK())
|
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>");
|
$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
|
else
|
||||||
$lines[] = $tablePropertie->format(" <property name=\"#ucfirstName#\" type=\"#dotNetObjectType#\">\n <column name=\"#name#\" sql-type=\"#type#\" not-null=\"#notNull#\" #indexName#/>\n </property>");
|
$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);
|
PMA_DBI_free_result($result);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user