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)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,28 +209,50 @@ class TableProperty
|
||||
function getIndexName()
|
||||
{
|
||||
if (strlen($this->key)>0)
|
||||
return "index=\"" . $this->name . "\"";
|
||||
return "index=\"" . htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8') . "\"";
|
||||
return "";
|
||||
}
|
||||
function isPK()
|
||||
{
|
||||
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("#name#", $this->name, $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);
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
$lines=array();
|
||||
@@ -244,31 +266,31 @@ class TableProperty
|
||||
$lines[] = "using System.Collections;";
|
||||
$lines[] = "using System.Collections.Generic;";
|
||||
$lines[] = "using System.Text;";
|
||||
$lines[] = "namespace ".ucfirst($db);
|
||||
$lines[] = "namespace ".cgMakeIdentifier($db);
|
||||
$lines[] = "{";
|
||||
$lines[] = " #region ".ucfirst($table);
|
||||
$lines[] = " public class ".ucfirst($table);
|
||||
$lines[] = " #region ".cgMakeIdentifier($table);
|
||||
$lines[] = " public class ".cgMakeIdentifier($table);
|
||||
$lines[] = " {";
|
||||
$lines[] = " #region Member Variables";
|
||||
foreach ($tableProperties as $tablePropertie)
|
||||
$lines[] = $tablePropertie->format(" protected #dotNetPrimitiveType# _#name#;");
|
||||
$lines[] = $tablePropertie->formatCs(" protected #dotNetPrimitiveType# _#name#;");
|
||||
$lines[] = " #endregion";
|
||||
$lines[] = " #region Constructors";
|
||||
$lines[] = " public ".ucfirst($table)."() { }";
|
||||
$lines[] = " public ".cgMakeIdentifier($table)."() { }";
|
||||
$temp = array();
|
||||
foreach ($tableProperties as $tablePropertie)
|
||||
if (! $tablePropertie->isPK())
|
||||
$temp[] = $tablePropertie->format("#dotNetPrimitiveType# #name#");
|
||||
$lines[] = " public ".ucfirst($table)."(".implode(", ", $temp).")";
|
||||
$temp[] = $tablePropertie->formatCs("#dotNetPrimitiveType# #name#");
|
||||
$lines[] = " public ".cgMakeIdentifier($table)."(".implode(", ", $temp).")";
|
||||
$lines[] = " {";
|
||||
foreach ($tableProperties as $tablePropertie)
|
||||
if (! $tablePropertie->isPK())
|
||||
$lines[] = $tablePropertie->format(" this._#name#=#name#;");
|
||||
$lines[] = $tablePropertie->formatCs(" 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[] = $tablePropertie->formatCs(" public virtual #dotNetPrimitiveType# #ucfirstName#\n {\n get {return _#name#;}\n set {_#name#=value;}\n }");
|
||||
$lines[] = " #endregion";
|
||||
$lines[] = " }";
|
||||
$lines[] = " #endregion";
|
||||
@@ -282,8 +304,8 @@ class TableProperty
|
||||
{
|
||||
$lines=array();
|
||||
$lines[] = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
|
||||
$lines[] = "<hibernate-mapping xmlns=\"urn:nhibernate-mapping-2.2\" namespace=\"".ucfirst($db)."\" assembly=\"".ucfirst($db)."\">";
|
||||
$lines[] = " <class name=\"".ucfirst($table)."\" table=\"".$table."\">";
|
||||
$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)
|
||||
{
|
||||
@@ -293,9 +315,9 @@ class TableProperty
|
||||
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>");
|
||||
$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->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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user