[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/class.oproc.php, 1.1.2.1
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/class.oproc.php, 1.1.2.1 |
Date: |
Sun, 23 May 2004 18:12:01 -0000 |
Update of /property
Added Files:
Branch: proposal-branch
class.oproc.php
date: 2004/05/03 20:56:46; author: sigurdne; state: Exp; lines: +242 -0
Log Message:
no message
=====================================================================
<?php
/**************************************************************************\
* phpGroupWare API - Application configuration in a centralized
location *
* This file written by Joseph Engo <address@hidden> *
* Copyright (C) 2000, 2001 Joseph Engo
*
*
-------------------------------------------------------------------------*
* This library is part of the phpGroupWare API
*
* http://www.phpgroupware.org/api
*
*
------------------------------------------------------------------------ *
* This library is free software; you can redistribute it and/or modify
it *
* under the terms of the GNU Lesser General Public License as published
by *
* the Free Software Foundation; either version 2.1 of the License,
*
* or any later version.
*
* This library is distributed in the hope that it will be useful, but
*
* WITHOUT ANY WARRANTY; without even the implied warranty of
*
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
License *
* along with this library; if not, write to the Free Software
Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\**************************************************************************/
/* $Id: class.oproc.php,v 1.1.2.1 2004/05/03 20:56:46 sigurdne Exp $ */
class property_oproc
{
var $db;
var $appname;
var $config_data;
function property_oproc()
{
$this->currentapp = 'property';
//$GLOBALS['phpgw_data']['flags']['req_app'];
}
function CreateTable($sTableName, $TableDef)
{
//html_print_r($TableDef);
$sql = "CREATE TABLE $sTableName (";
$allFields=$TableDef['fd'];
//foreach($allFields as $field)
$last=count($allFields)-1;
$i=0;
while(list($fieldname, $field) = each($allFields))
{
$sql .= $fieldname . ' ';
//html_print_r($fieldname);
//html_print_r($field);
$sType = '';
$iPrecision = 0;
$iScale = 0;
$sDefault = '';
$bNullable = true;
$sFieldSQL = '';
reset($field);
while(list($sAttr, $vAttrVal) = each($field))
{
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'";
}
}
if($i<$last)
{
$sFieldSQL .= ", ";
}
}
$i++;
$sql .= $sFieldSQL;
}
$sFields = '';
while(list($key, $sField) = each($TableDef['pk']))
{
if($sFields != '')
{
$sFields .= ',';
}
$sFields .= $sField;
}
if($sFields)
{
$sPKSQL = $this->GetPKSQL($sFields);
$sql .= ', ' . $sPKSQL;
}
$sUCSQL = '';
$sFields = '';
while(list($key,$sField) = each($TableDef['uc']))
{
if($sFields != '')
{
$sFields .= ',';
}
$sFields .= $sField;
}
if($sFields)
{
$sUCSQL = $this->GetUCSQL($sFields);
$sql .= ', ' . $sUCSQL;
}
$sql .= ')';
return $GLOBALS['phpgw']->db->Execute($sql);
}
function TranslateType($sType, $iPrecision = 0, $iScale = 0)
{
//html_print_r($sType);
//html_print_r($iPrecision);
//html_print_r($iScale);
switch($sType)
{
case 'auto':
$sTranslated = 'int4';
break;
case 'blob':
$sTranslated = 'text';
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 'longtext':
$sTranslated = 'text';
break;
case 'text':
$sTranslated = 'text';
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 $sTranslated;
}
function GetPKSQL($sFields)
{
return "PRIMARY KEY($sFields)";
}
function GetUCSQL($sFields)
{
return "UNIQUE($sFields)";
}
function TranslateDefault($sDefault)
{
switch ($sDefault)
{
case 'current_date':
case 'current_timestamp':
return "'now'";
}
return "'" . $sDefault . "'";
}
}
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] property/class.oproc.php, 1.1.2.1,
nomail <=