[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/propel-generator/classes/propel/engine/builder/sql/ -> DDLBuilder.php (source)

   1  <?php
   2  
   3  /*
   4   *  $Id: DDLBuilder.php 1310 2006-05-04 07:36:54Z fabien $
   5   *
   6   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   7   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   8   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   9   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  10   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  12   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  13   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  14   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  16   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17   *
  18   * This software consists of voluntary contributions made by many individuals
  19   * and is licensed under the LGPL. For more information please see
  20   * <http://propel.phpdb.org>.
  21   */
  22  
  23  require_once 'propel/engine/builder/DataModelBuilder.php';
  24  
  25  /**
  26   * Baseclass for SQL DDL-building classes.
  27   *
  28   * DDL-building classes are those that build all the SQL DDL for a single table.
  29   *
  30   * @author Hans Lellelid <hans@xmpl.org>
  31   * @package propel.engine.builder.sql
  32   */
  33  abstract class DDLBuilder extends DataModelBuilder {
  34  
  35      /**
  36       * Builds the SQL for current table and returns it as a string.
  37       *
  38       * This is the main entry point and defines a basic structure that classes should follow.
  39       * In most cases this method will not need to be overridden by subclasses.
  40       *
  41       * @return string The resulting SQL DDL.
  42       */
  43  	public function build()
  44      {
  45          $script = "";
  46          $this->addTable($script);
  47          $this->addIndices($script);
  48          $this->addForeignKeys($script);
  49          return $script;
  50      }
  51  
  52      /**
  53       * Builds the DDL SQL for a Column object.
  54       * @return string
  55       */
  56  	public function getColumnDDL(Column $col)
  57      {
  58          $platform = $this->getPlatform();
  59          $domain = $col->getDomain();
  60  
  61          $sb = "";
  62          $sb .= $this->quoteIdentifier($col->getName()) . " ";
  63          $sb .= $domain->getSqlType();
  64          if ($platform->hasSize($domain->getSqlType())) {
  65              $sb .= $domain->printSize();
  66          }
  67          $sb .= " ";
  68          $sb .= $col->getDefaultSetting() . " ";
  69          $sb .= $col->getNotNullString() . " ";
  70          $sb .= $col->getAutoIncrementString();
  71  
  72          return trim($sb);
  73      }
  74  
  75      /**
  76       * Creates a delimiter-delimited string list of column names, quoted using quoteIdentifier().
  77       * @param array Column[] or string[]
  78       * @param string $delim The delimiter to use in separating the column names.
  79       * @return string
  80       */
  81  	public function getColumnList($columns, $delim=',')
  82      {
  83          $list = array();
  84          foreach($columns as $col) {
  85              if ($col instanceof Column) {
  86                  $col = $col->getName();
  87              }
  88              $list[] = $this->quoteIdentifier($col);
  89          }
  90          return implode($delim, $list);
  91      }
  92  
  93      /**
  94       * This function adds any _database_ start/initialization SQL.
  95       * This is designed to be called for a database, not a specific table, hence it is static.
  96       * @return string The DDL is returned as astring.
  97       */
  98  	public static function getDatabaseStartDDL()
  99      {
 100          return '';
 101      }
 102  
 103      /**
 104       * This function adds any _database_ end/cleanup SQL.
 105       * This is designed to be called for a database, not a specific table, hence it is static.
 106       * @return string The DDL is returned as astring.
 107       */
 108  	public static function getDatabaseEndDDL()
 109      {
 110          return '';
 111      }
 112  
 113      /**
 114       * Adds table definition.
 115       * @param string &$script The script will be modified in this method.
 116       */
 117      abstract protected function addTable(&$script);
 118  
 119      /**
 120       * Adds index definitions.
 121       * @param string &$script The script will be modified in this method.
 122       */
 123      abstract protected function addIndices(&$script);
 124  
 125      /**
 126       * Adds foreign key constraint definitions.
 127       * @param string &$script The script will be modified in this method.
 128       */
 129      abstract protected function addForeignKeys(&$script);
 130  
 131  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7