working on new setup prog that will allow add-on apps to take advantage of it

This commit is contained in:
seek3r 2000-12-20 00:02:11 +00:00
parent 66ab743445
commit edb1ade9db
5 changed files with 395 additions and 0 deletions

View File

@ -306,5 +306,8 @@
echo "</td></tr></table>";
}
include("./inc/phpgw_schema_proc.inc.php");
// $phpgw_schema_proc = new phpgw_schema_proc($phpgw_domain[$SetupDomain]["db_type"]);
$phpgw_schema_proc = new phpgw_schema_proc("mysql");
?>

View File

@ -0,0 +1,115 @@
<?php
class phpgw_schema_proc
{
var $m_oTranslator;
function phpgw_schema_proc($dbms)
{
include("./inc/phpgw_schema_proc_" . $dbms . ".inc.php");
eval("\$this->m_oTranslator = new phpgw_schema_proc_$dbms;");
}
function GenerateScripts($aTables, $bOutputHTML = false)
{
if (!is_array($aTables))
return false;
reset($aTables);
$sAllTableSQL = "";
while (list($sTableName, $aTableDef) = each($aTables))
{
if ($this->_GetTableSQL($aTableDef, $sTableSQL))
{
$sTableSQL = "CREATE TABLE $sTableName (\n$sTableSQL\n)"
. $this->m_oTranslator->m_sStatementTerminator;
$sAllTableSQL .= $sTableSQL . "\n\n";
}
else
return false;
}
if ($bOutputHTML)
print("<PRE>$sAllTableSQL</PRE><BR><BR>");
return true;
}
function _GetTableSQL($aTableDef, &$sTableSQL)
{
if (!is_array($aTableDef))
return false;
$sTableSQL = "";
reset($aTableDef);
while (list($sFieldName, $aFieldAttr) = each($aTableDef))
{
$sFieldSQL = "";
if ($this->_GetFieldSQL($aFieldAttr, $sFieldSQL))
{
if ($sTableSQL != "")
$sTableSQL .= ",\n";
$sTableSQL .= "$sFieldName $sFieldSQL";
}
else
return false;
}
return true;
}
// Get field DDL
function _GetFieldSQL($aField, &$sFieldSQL)
{
if (!is_array($aField))
return false;
$sType = "";
$iPrecision = 0;
$iScale = 0;
$sDefault = "";
$bNullable = false;
reset($aField);
while (list($sAttr, $vAttrVal) = each($aField))
{
switch ($sAttr)
{
case "type":
$sType = $vAttrVal;
break;
case "precision":
$iPrecision = (int)$vAttrVal;
break;
case "scale":
$iScale = (int)$vAttrVal;
break;
case "default":
$sDefault = $vAttrVal;
break;
case "nullable":
$bNullable = $vAttrVal;
break;
}
}
// Translate the type for the DBMS
if ($this->m_oTranslator->TranslateType($sType, $iPrecision, $iScale, $sFieldSQL))
{
if ($bNullable == false)
$sFieldSQL .= " NOT NULL";
if ($sDefault != "")
{
// Get default DDL - useful for differences in date defaults (eg, now() vs. getdate())
$sTranslatedDefault = $this->m_oTranslator->TranslateDefault($sDefault);
$sFieldSQL .= " DEFAULT '$sTranslatedDefault'";
}
return true;
}
return false;
}
}
?>

View File

@ -0,0 +1,84 @@
<?php
class phpgw_schema_proc_mysql
{
var $m_sStatementTerminator;
function phpgw_schema_proc_mysql()
{
$this->m_sStatementTerminator = ";";
}
// Return a type suitable for DDL
function TranslateType($sType, $iPrecision = 0, $iScale = 0, &$sTranslated)
{
$sTranslated = "";
switch($sType)
{
case "autoincrement":
$sTranslated = "auto_increment";
break;
case "char":
if ($iPrecision > 0 && $iPrecision < 256)
$sTranslated = sprintf("char(%d)", $iPrecision);
if ($iPrecision > 255)
$sTranslated = "text";
break;
case "date":
$sTranslated = "date";
break;
case "decimal":
$sTranslated = sprintf("decimal(%d,%d)", $iPrecision, $iScale);
break;
case "float":
switch ($iPrecision)
{
case 4:
$sTranslated = "float";
break;
case 8:
$sTranslated = "double";
break;
}
break;
case "int":
switch ($iPrecision)
{
case 2:
$sTranslated = "smallint";
break;
case 4:
$sTranslated = "int";
break;
case 8:
$sTranslated = "bigint";
break;
}
break;
case "timestamp":
$sTranslated = "datetime";
case "varchar":
if ($iPrecision > 0 && $iPrecision < 256)
$sTranslated = sprintf("varchar(%d)", $iPrecision);
if ($iPrecision > 255)
$sTranslated = "text";
}
return (strlen($sTranslated) > 0);
}
function TranslateDefault($sDefault)
{
switch ($sDefault)
{
case "current_date":
case "current_timestamp":
return "now";
}
return $sDefault;
}
}
?>

View File

@ -0,0 +1,71 @@
<?php
class phpgw_schema_proc_pgsql
{
var $m_sStatementTerminator;
function phpgw_schema_proc_pgsql()
{
$this->m_sStatementTerminator = ";";
}
// Return a type suitable for DDL
function TranslateType($sType, $iPrecision = 0, $iScale = 0, &$sTranslated)
{
switch($sType)
{
case "autoincrement":
$sTranslated = "serial";
break;
case "char":
if ($iPrecision > 0 && $iPrecision < 256)
$sTranslated = sprintf("char(%d)", $iPrecision);
if ($iPrecision > 255)
$sTranslated = "text";
break;
case "date":
$sTranslated = "date";
break;
case "decimal":
$sTranslated = sprintf("decimal(%d,%d)", $iPrecision, $iScale);
break;
case "float":
if ($iPrecision == 4 || $iPrecision == 8)
$sTranslated = sprintf("float%d", $iPrecision);
break;
case "int":
if ($iPrecision == 2 || $iPrecision == 4 || $iPrecision == 8)
$sTranslated = sprintf("int%d", $iPrecision);
break;
case "timestamp":
$sTranslated = "timestamp";
break;
case "varchar":
if ($iPrecision > 0 && $iPrecision < 256)
$sTranslated = sprintf("varchar(%d)", $iPrecision);
if ($iPrecision > 255)
$sTranslated = "text";
break;
}
return (strlen($sTranslated) > 0);
}
function TranslateDefault($sDefault)
{
switch ($sDefault)
{
case "current_date":
case "current_timestamp":
return "now";
}
return $sDefault;
}
}
?>

View File

@ -0,0 +1,122 @@
<HTML>
<HEAD>
</HEAD>
<BODY STYLE="background-color: #ffffff;">
Welcome to the phpGroupWare Schema Abstraction Definition testing program.<BR>
Here we go:<P>
<?php
$phpgw_info["flags"] = array("noheader" => True, "nonavbar" => True, "currentapp" => "home", "noapi" => True);
include("../header.inc.php");
include("./inc/functions.inc.php");
$SetupDomain = "phpgroupware.org";
$tables = array(
"departments" => array(
"id" => array(
"type" => "autoincrement"
),
"short" => array(
"type" => "varchar",
"precision" => 20,
"nullable" => false
),
"name" => array(
"type" => "varchar",
"precision" => 50,
"nullable" => false
),
"active" => array(
"type" => "char",
"precision" => 1,
"nullable" => false,
"default" => "Y"
)
),
"actions" => array(
"id" => array(
"type" => "autoincrement"
),
"short" => array(
"type" => "varchar",
"precision" => 20,
"nullable" => false
),
"name" => array(
"type" => "varchar",
"precision" => 50,
"nullable" => false
),
"active" => array(
"type" => "char",
"precision" => 1,
"nullable" => false,
"default" => "Y"
)
),
"timecards" => array(
"id" => array(
"type" => "autoincrement"
),
"jcn" => array(
"type" => "int",
"precision" => 4,
"nullable" => false
),
"seq" => array(
"type" => "int",
"precision" => 4,
"nullable" => false
),
"actionon" => array(
"type" => "timestamp",
"nullable" => false,
"default" => "current_timestamp"
),
"inputon" => array(
"type" => "timestamp",
"nullable" => false,
"default" => "current_timestamp"
),
"actionby" => array(
"type" => "int",
"precision" => 4,
"nullable" => false
),
"status" => array(
"type" => "int",
"precision" => 4,
"nullable" => false
),
"action" => array(
"type" => "int",
"precision" => 4,
"nullable" => false
),
"hours" => array(
"type" => "float",
"precision" => 4,
"nullable" => false,
"default" => 0.0
),
"summary" => array(
"type" => "varchar",
"precision" => 80,
"nullable" => false
),
"description" => array(
"type" => "varchar",
"precision" => 1024,
"nullable" => true
),
"revision" => array(
"type" => "varchar",
"precision" => 20,
"nullable" => true
)
)
);
$phpgw_schema_proc->GenerateScripts($tables, true);
?>
</BODY>
</HTML>