[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/class.oproc.php, 1.1.2.3
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/class.oproc.php, 1.1.2.3 |
Date: |
Sun, 23 May 2004 06:19:10 -0000 |
Update of /property
Modified Files:
Branch: proposal-branch
class.oproc.php
date: 2004/05/04 08:42:05; author: sigurdne; state: Exp; lines: +110 -12
Log Message:
no message
=====================================================================
Index: property/class.oproc.php
diff -u property/class.oproc.php:1.1.2.2 property/class.oproc.php:1.1.2.3
--- property/class.oproc.php:1.1.2.2 Mon May 3 21:07:47 2004
+++ property/class.oproc.php Tue May 4 08:42:05 2004
@@ -40,14 +40,22 @@
$sql = "CREATE TABLE $sTableName (";
- $allFields=$TableDef['fd'];
- //foreach($allFields as $field)
- $last=count($allFields)-1;
+ $columns=$TableDef['fd'];
+ //foreach($columns as $field)
+ $last=count($columns)-1;
$i=0;
- while(list($fieldname, $field) = each($allFields))
+ while(list($sColumnName, $aColumnDef) = each($columns))
{
- $sql .= $fieldname . ' ';
+
+ $sql.=
$this->column_def($sColumnName,$aColumnDef);
+ if($i<$last)
+ {
+ $sql .= ", ";
+ }
+ $i++;
+
+/* $sql .= $sColumnName . ' ';
$sType = '';
$iPrecision = 0;
@@ -55,8 +63,8 @@
$sDefault = '';
$bNullable = true;
$sFieldSQL = '';
- reset($field);
- while(list($sAttr, $vAttrVal) = each($field))
+ reset($aColumnDef);
+ while(list($sAttr, $vAttrVal) =
each($aColumnDef))
{
switch ($sAttr)
{
@@ -107,7 +115,7 @@
}
$i++;
$sql .= $sFieldSQL;
- }
+*/ }
$sFields = '';
while(list($key, $sField) = each($TableDef['pk']))
@@ -231,11 +239,101 @@
return "'" . $sDefault . "'";
}
+ function column_def($sColumnName,$aColumnDef)
+ {
+ $sql .= $sColumnName . ' ';
+
+ $sType = '';
+ $iPrecision = 0;
+ $iScale = 0;
+ $sDefault = '';
+ $bNullable = true;
+ $sFieldSQL = '';
+ reset($aColumnDef);
+ while(list($sAttr, $vAttrVal) = each($aColumnDef))
+ {
+ switch ($sAttr)
+ {
+ case 'type':
+ $sType = $vAttrVal;
+ break;
+ case 'precision':
+ $iPrecision = (int)$vAttrVal;
+ break;
+ case 'scale':
+ $iScale = (int)$vAttrVal;
+ break;
+ case 'default':
+ $sDefault = $vAttrVal;
+ if($DEBUG) {
echo'<br>_GetFieldSQL(): Default="' . $sDefault . '"'; }
+ break;
+ case 'nullable':
+ $bNullable = $vAttrVal;
+ break;
+ }
+
+ if($sFieldSQL = $this->TranslateType($sType,
$iPrecision, $iScale))
+ {
+ if($bNullable == False)
+ {
+ $sFieldSQL .= ' NOT NULL';
+ }
+ else
+ {
+ $sFieldSQL .= ' NULL';
+ }
+ if($sDefault != '')
+ {
+ $sTranslatedDefault =
$this->TranslateDefault($sDefault);
+ $sFieldSQL .= " DEFAULT
'$sTranslatedDefault'";
+ }
+ elseif($sDefault == '0')
+ {
+ $sFieldSQL .= " DEFAULT '0'";
+ }
+ }
+ }
+ $sql .= $sFieldSQL;
+ return $sql;
+ }
+
function AddColumn($sTableName, $sColumnName, $aColumnDef)
{
-html_print_r($sTableName);
-html_print_r($sColumnName);
-html_print_r($aColumnDef);
+ $sql = "ALTER TABLE $sTableName ADD ";
+ $sql.= $this->column_def($sColumnName,$aColumnDef);
+ return $GLOBALS['phpgw']->db->Execute($sql);
+ }
+
+ function DropColumn($TableName, $ColumnName)
+ {
+ $sql = "ALTER TABLE $TableName DROP $ColumnName";
+ return $GLOBALS['phpgw']->db->Execute($sql);
+ }
+
+ function DropTable($TableName)
+ {
+ $sql = "DROP TABLE $TableName";
+ return $GLOBALS['phpgw']->db->Execute($sql);
+ }
+
+ function AlterColumn($TableName,$oldColumnName, $newColumnName,
$ColumnDef)
+ {
+ if($oldColumnName == $newColumnName)
+ {
+ $tempname=$oldColumnName."_tmp";
+ $sql = "ALTER TABLE $TableName ADD ";
+ $sql.= $this->column_def($tempname,$ColumnDef);
+ $GLOBALS['phpgw']->db->Execute($sql);
+
+ $this->DropColumn($TableName, $oldColumnName);
+
+ $oldColumnName = $tempname;
+ }
+
+ $sql = "ALTER TABLE $TableName ADD ";
+ $sql.= $this->column_def($newColumnName,$ColumnDef);
+ $GLOBALS['phpgw']->db->Execute($sql);
+ $this->DropColumn($TableName, $oldColumnName);
}
}
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] property/class.oproc.php, 1.1.2.3,
nomail <=