tabs -> spaces
This commit is contained in:
@@ -152,70 +152,70 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
|||||||
*/
|
*/
|
||||||
class TableProperty
|
class TableProperty
|
||||||
{
|
{
|
||||||
public $name;
|
public $name;
|
||||||
public $type;
|
public $type;
|
||||||
public $nullable;
|
public $nullable;
|
||||||
public $key;
|
public $key;
|
||||||
public $defaultValue;
|
public $defaultValue;
|
||||||
public $ext;
|
public $ext;
|
||||||
function __construct($row)
|
function __construct($row)
|
||||||
{
|
{
|
||||||
$this->name = trim($row[0]);
|
$this->name = trim($row[0]);
|
||||||
$this->type = trim($row[1]);
|
$this->type = trim($row[1]);
|
||||||
$this->nullable = trim($row[2]);
|
$this->nullable = trim($row[2]);
|
||||||
$this->key = trim($row[3]);
|
$this->key = trim($row[3]);
|
||||||
$this->defaultValue = trim($row[4]);
|
$this->defaultValue = trim($row[4]);
|
||||||
$this->ext = trim($row[5]);
|
$this->ext = trim($row[5]);
|
||||||
}
|
}
|
||||||
function getPureType()
|
function getPureType()
|
||||||
{
|
{
|
||||||
$pos=strpos($this->type, "(");
|
$pos=strpos($this->type, "(");
|
||||||
if ($pos > 0)
|
if ($pos > 0)
|
||||||
return substr($this->type, 0, $pos);
|
return substr($this->type, 0, $pos);
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
function isNotNull()
|
function isNotNull()
|
||||||
{
|
{
|
||||||
return $this->nullable == "NO" ? "true" : "false";
|
return $this->nullable == "NO" ? "true" : "false";
|
||||||
}
|
}
|
||||||
function isUnique()
|
function isUnique()
|
||||||
{
|
{
|
||||||
return $this->key == "PRI" || $this->key == "UNI" ? "true" : "false";
|
return $this->key == "PRI" || $this->key == "UNI" ? "true" : "false";
|
||||||
}
|
}
|
||||||
function getDotNetPrimitiveType()
|
function getDotNetPrimitiveType()
|
||||||
{
|
{
|
||||||
if (strpos($this->type, "int") === 0) return "int";
|
if (strpos($this->type, "int") === 0) return "int";
|
||||||
if (strpos($this->type, "long") === 0) return "long";
|
if (strpos($this->type, "long") === 0) return "long";
|
||||||
if (strpos($this->type, "char") === 0) return "string";
|
if (strpos($this->type, "char") === 0) return "string";
|
||||||
if (strpos($this->type, "varchar") === 0) return "string";
|
if (strpos($this->type, "varchar") === 0) return "string";
|
||||||
if (strpos($this->type, "text") === 0) return "string";
|
if (strpos($this->type, "text") === 0) return "string";
|
||||||
if (strpos($this->type, "longtext") === 0) return "string";
|
if (strpos($this->type, "longtext") === 0) return "string";
|
||||||
if (strpos($this->type, "tinyint") === 0) return "bool";
|
if (strpos($this->type, "tinyint") === 0) return "bool";
|
||||||
if (strpos($this->type, "datetime") === 0) return "DateTime";
|
if (strpos($this->type, "datetime") === 0) return "DateTime";
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
function getDotNetObjectType()
|
function getDotNetObjectType()
|
||||||
{
|
{
|
||||||
if (strpos($this->type, "int") === 0) return "Int32";
|
if (strpos($this->type, "int") === 0) return "Int32";
|
||||||
if (strpos($this->type, "long") === 0) return "Long";
|
if (strpos($this->type, "long") === 0) return "Long";
|
||||||
if (strpos($this->type, "char") === 0) return "String";
|
if (strpos($this->type, "char") === 0) return "String";
|
||||||
if (strpos($this->type, "varchar") === 0) return "String";
|
if (strpos($this->type, "varchar") === 0) return "String";
|
||||||
if (strpos($this->type, "text") === 0) return "String";
|
if (strpos($this->type, "text") === 0) return "String";
|
||||||
if (strpos($this->type, "longtext") === 0) return "String";
|
if (strpos($this->type, "longtext") === 0) return "String";
|
||||||
if (strpos($this->type, "tinyint") === 0) return "Boolean";
|
if (strpos($this->type, "tinyint") === 0) return "Boolean";
|
||||||
if (strpos($this->type, "datetime") === 0) return "DateTime";
|
if (strpos($this->type, "datetime") === 0) return "DateTime";
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
function getIndexName()
|
function getIndexName()
|
||||||
{
|
{
|
||||||
if (strlen($this->key)>0)
|
if (strlen($this->key)>0)
|
||||||
return "index=\"" . htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8') . "\"";
|
return "index=\"" . htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8') . "\"";
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
function isPK()
|
function isPK()
|
||||||
{
|
{
|
||||||
return $this->key=="PRI";
|
return $this->key=="PRI";
|
||||||
}
|
}
|
||||||
function formatCs($text)
|
function formatCs($text)
|
||||||
{
|
{
|
||||||
$text=str_replace("#name#", cgMakeIdentifier($this->name, false), $text);
|
$text=str_replace("#name#", cgMakeIdentifier($this->name, false), $text);
|
||||||
@@ -227,16 +227,16 @@ class TableProperty
|
|||||||
$text=str_replace("#indexName#", $this->getIndexName(), $text);
|
$text=str_replace("#indexName#", $this->getIndexName(), $text);
|
||||||
return $this->format($text);
|
return $this->format($text);
|
||||||
}
|
}
|
||||||
function format($text)
|
function format($text)
|
||||||
{
|
{
|
||||||
$text=str_replace("#ucfirstName#", cgMakeIdentifier($this->name), $text);
|
$text=str_replace("#ucfirstName#", cgMakeIdentifier($this->name), $text);
|
||||||
$text=str_replace("#dotNetPrimitiveType#", $this->getDotNetPrimitiveType(), $text);
|
$text=str_replace("#dotNetPrimitiveType#", $this->getDotNetPrimitiveType(), $text);
|
||||||
$text=str_replace("#dotNetObjectType#", $this->getDotNetObjectType(), $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);
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cgMakeIdentifier($str, $ucfirst = true)
|
function cgMakeIdentifier($str, $ucfirst = true)
|
||||||
@@ -253,83 +253,83 @@ class TableProperty
|
|||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleNHibernateCSBody($db, $table, $crlf)
|
function handleNHibernateCSBody($db, $table, $crlf)
|
||||||
{
|
{
|
||||||
$lines=array();
|
$lines=array();
|
||||||
$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)
|
||||||
{
|
{
|
||||||
$tableProperties=array();
|
$tableProperties=array();
|
||||||
while ($row = PMA_DBI_fetch_row($result))
|
while ($row = PMA_DBI_fetch_row($result))
|
||||||
$tableProperties[] = new TableProperty($row);
|
$tableProperties[] = new TableProperty($row);
|
||||||
$lines[] = "using System;";
|
$lines[] = "using System;";
|
||||||
$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 ".cgMakeIdentifier($db);
|
$lines[] = "namespace ".cgMakeIdentifier($db);
|
||||||
$lines[] = "{";
|
$lines[] = "{";
|
||||||
$lines[] = " #region ".cgMakeIdentifier($table);
|
$lines[] = " #region ".cgMakeIdentifier($table);
|
||||||
$lines[] = " public class ".cgMakeIdentifier($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->formatCs(" protected #dotNetPrimitiveType# _#name#;");
|
$lines[] = $tablePropertie->formatCs(" protected #dotNetPrimitiveType# _#name#;");
|
||||||
$lines[] = " #endregion";
|
$lines[] = " #endregion";
|
||||||
$lines[] = " #region Constructors";
|
$lines[] = " #region Constructors";
|
||||||
$lines[] = " public ".cgMakeIdentifier($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->formatCs("#dotNetPrimitiveType# #name#");
|
$temp[] = $tablePropertie->formatCs("#dotNetPrimitiveType# #name#");
|
||||||
$lines[] = " public ".cgMakeIdentifier($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->formatCs(" 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->formatCs(" 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";
|
||||||
$lines[] = "}";
|
$lines[] = "}";
|
||||||
PMA_DBI_free_result($result);
|
PMA_DBI_free_result($result);
|
||||||
}
|
}
|
||||||
return implode("\n", $lines);
|
return implode("\n", $lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleNHibernateXMLBody($db, $table, $crlf)
|
function handleNHibernateXMLBody($db, $table, $crlf)
|
||||||
{
|
{
|
||||||
$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=\"".cgMakeIdentifier($db)."\" assembly=\"".cgMakeIdentifier($db)."\">";
|
$lines[] = "<hibernate-mapping xmlns=\"urn:nhibernate-mapping-2.2\" namespace=\"".cgMakeIdentifier($db)."\" assembly=\"".cgMakeIdentifier($db)."\">";
|
||||||
$lines[] = " <class name=\"".cgMakeIdentifier($table)."\" table=\"".cgMakeIdentifier($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)
|
||||||
{
|
{
|
||||||
$tableProperties = array();
|
$tableProperties = array();
|
||||||
while ($row = PMA_DBI_fetch_row($result))
|
while ($row = PMA_DBI_fetch_row($result))
|
||||||
$tableProperties[] = new TableProperty($row);
|
$tableProperties[] = new TableProperty($row);
|
||||||
foreach ($tableProperties as $tablePropertie)
|
foreach ($tableProperties as $tablePropertie)
|
||||||
{
|
{
|
||||||
if ($tablePropertie->isPK())
|
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>");
|
$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->formatXml(" <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);
|
||||||
}
|
}
|
||||||
$lines[]=" </class>";
|
$lines[]=" </class>";
|
||||||
$lines[]="</hibernate-mapping>";
|
$lines[]="</hibernate-mapping>";
|
||||||
return implode("\n", $lines);
|
return implode("\n", $lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
function cgGetOption($optionName)
|
function cgGetOption($optionName)
|
||||||
{
|
{
|
||||||
global $what;
|
global $what;
|
||||||
return $GLOBALS[$what . "_" . $optionName];
|
return $GLOBALS[$what . "_" . $optionName];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
Reference in New Issue
Block a user