[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/dbal/src/drivers/ -> lmbDbColumnInfo.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  lmb_require('limb/dbal/src/drivers/lmbDbTypeInfo.class.php');
  11  lmb_require('limb/dbal/src/exception/lmbDbException.class.php');
  12  
  13  /**

  14   * class lmbDbColumnInfo.

  15   *

  16   * @package dbal

  17   * @version $Id: lmbDbColumnInfo.class.php 5945 2007-06-06 08:31:43Z pachanga $

  18   */
  19  class lmbDbColumnInfo
  20  {
  21    protected $table;
  22    protected $name;
  23    protected $type;
  24    protected $size;
  25    protected $scale;
  26    protected $isNullable;
  27    protected $defaultValue;
  28  
  29    function __construct($table,
  30                          $name,
  31                          $type = null,
  32                          $size = null,
  33                          $scale = null,
  34                          $isNullable = null,
  35                          $default = null)
  36    {
  37  
  38      $this->table = $table;
  39      $this->name = $this->canonicalizeName($name);
  40      $this->type = $this->canonicalizeType($type);
  41      $this->size = $this->canonicalizeSize($size);
  42      $this->scale = $this->canonicalizeScale($scale);
  43      $this->isNullable = $this->canonicalizeIsNullable($isNullable);
  44      $this->defaultValue = $this->canonicalizeDefaultValue($default);
  45    }
  46  
  47    function isValidColumnName($name)
  48    {
  49      return preg_match('/[A-Za-z][A-Za-z0-9_]*/', $name);
  50    }
  51  
  52    function getName()
  53    {
  54      return $this->name;
  55    }
  56  
  57    function canonicalizeName($name)
  58    {
  59      if(!$this->isValidColumnName($name))
  60      {
  61        throw new lmbDbException("Invalid column name '$name'");
  62      }
  63      return $name;
  64    }
  65  
  66    function getType()
  67    {
  68      return $this->type;
  69    }
  70  
  71    function canonicalizeType($type)
  72    {
  73      $typeinfo = new lmbDbTypeInfo();
  74      $typelist = $typeinfo->getColumnTypeList();
  75      if(!in_array($type, $typelist))
  76      {
  77        throw new lmbDbException("Invalid column type '$type'");
  78      }
  79      return $type;
  80    }
  81  
  82    function getSize()
  83    {
  84      return $this->size;
  85    }
  86  
  87    function canonicalizeSize($size)
  88    {
  89      return is_null($size) ?  null : (int) $size;
  90    }
  91  
  92    function getScale()
  93    {
  94      return $this->scale;
  95    }
  96  
  97    function canonicalizeScale($scale)
  98    {
  99      return is_null($scale) ?  null : (int) $scale;
 100    }
 101  
 102    function getDefaultValue()
 103    {
 104      return $this->defaultValue;
 105    }
 106  
 107    function canonicalizeDefaultValue($defaultValue)
 108    {
 109      return $defaultValue;
 110    }
 111  
 112    function isNullable()
 113    {
 114      return $this->isNullable;
 115    }
 116  
 117    function canonicalizeIsNullable($isNullable)
 118    {
 119      return is_null($isNullable) ?  null : (bool) $isNullable;
 120    }
 121  
 122    function getTable()
 123    {
 124      return $this->table;
 125    }
 126  
 127    function escapeIdentifier($name)
 128    {
 129      return $name;
 130    }
 131  }
 132  
 133  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7