[ 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/oracle/ -> OracleDDLBuilder.php (source)

   1  <?php
   2  
   3  /*
   4   *  $Id: OracleDDLBuilder.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/sql/DDLBuilder.php';
  24  
  25  /**
  26   * The SQL DDL-building class for Oracle.
  27   *
  28   *
  29   * @author Hans Lellelid <hans@xmpl.org>
  30   * @package propel.engine.builder.sql.pgsql
  31   */
  32  class OracleDDLBuilder extends DDLBuilder {
  33  
  34      /**
  35       *
  36       * @see parent::addDropStatement()
  37       */
  38  	protected function addDropStatements(&$script)
  39      {
  40          $table = $this->getTable();
  41          $platform = $this->getPlatform();
  42          $script .= "
  43  DROP TABLE ".$this->quoteIdentifier($table->getName())." CASCADE CONSTRAINTS;
  44  ";
  45          if ($table->getIdMethod() == "native") {
  46              $script .= "
  47  DROP SEQUENCE ".$this->quoteIdentifier($table->getSequenceName()).";
  48  ";
  49          }
  50      }
  51  
  52      /**
  53       *
  54       * @see parent::addColumns()
  55       */
  56  	protected function addTable(&$script)
  57      {
  58          $table = $this->getTable();
  59          $script .= "
  60  
  61  /* -----------------------------------------------------------------------
  62     ".$table->getName()."
  63     ----------------------------------------------------------------------- */
  64  ";
  65  
  66          $this->addDropStatements($script);
  67  
  68          $script .= "
  69  
  70  CREATE TABLE ".$table->getName()."
  71  (
  72      ";
  73  
  74          $lines = array();
  75  
  76          foreach ($table->getColumns() as $col) {
  77              $lines[] = $this->getColumnDDL($col);
  78          }
  79  
  80          $sep = ",
  81      ";
  82          $script .= implode($sep, $lines);
  83          $script .= "
  84  );
  85  ";
  86          $this->addPrimaryKey($script);
  87          $this->addIndices($script);
  88          $this->addSequences($script);
  89  
  90      }
  91  
  92      /**
  93       *
  94       *
  95       */
  96  	protected function addPrimaryKey(&$script)
  97      {
  98          $table = $this->getTable();
  99          $platform = $this->getPlatform();
 100          $tableName = $table->getName();
 101          $length = strlen($tableName);
 102          if ($length > 27) {
 103              $length = 27;
 104          }
 105          if ( is_array($table->getPrimaryKey()) && count($table->getPrimaryKey()) ) {
 106              $script .= "
 107      ALTER TABLE ".$this->quoteIdentifier($table->getName())."
 108          ADD CONSTRAINT ".substr($tableName,0,$length)."_PK
 109      PRIMARY KEY (";
 110              $delim = "";
 111              foreach ($table->getPrimaryKey() as $col) {
 112                  echo $delim . $col->getName();
 113                  $delim = ",";
 114              }
 115      $script .= ");
 116  ";
 117          }
 118      }
 119  
 120      /**
 121       * Adds CREATE SEQUENCE statements for this table.
 122       *
 123       */
 124  	protected function addSequences(&$script)
 125      {
 126          $table = $this->getTable();
 127          $platform = $this->getPlatform();
 128          if ($table->getIdMethod() == "native") {
 129              $script .= "CREATE SEQUENCE ".$this->quoteIdentifier($table->getSequenceName())." INCREMENT BY 1 START WITH 1 NOMAXVALUE NOCYCLE NOCACHE ORDER;
 130  ";
 131          }
 132      }
 133  
 134  
 135      /**
 136       * Adds CREATE INDEX statements for this table.
 137       * @see parent::addIndices()
 138       */
 139  	protected function addIndices(&$script)
 140      {
 141          $table = $this->getTable();
 142          $platform = $this->getPlatform();
 143          foreach ($table->getIndices() as $index) {
 144              $script .= "CREATE ";
 145              if($index->getIsUnique()) {
 146                  $script .= "UNIQUE";
 147              }
 148              $script .= "INDEX ".$this->quoteIdentifier($index->getName()) ." ON ".$this->quoteIdentifier($table->getName())." (".$this->getColumnList($index->getColumns()).");
 149  ";
 150          }
 151      }
 152  
 153      /**
 154       *
 155       * @see parent::addForeignKeys()
 156       */
 157  	protected function addForeignKeys(&$script)
 158      {
 159          $table = $this->getTable();
 160          $platform = $this->getPlatform();
 161          foreach ($table->getForeignKeys() as $fk) {
 162              $script .= "
 163  ALTER TABLE ".$this->quoteIdentifier($table->getName())." ADD CONSTRAINT ".$this->quoteIdentifier($fk->getName())." FOREIGN KEY (".$this->getColumnList($fk->getLocalColumns()) .") REFERENCES ".$this->quoteIdentifier($fk->getForeignTableName())." (".$this->getColumnList($fk->getForeignColumns()).")";
 164              if ($fk->hasOnUpdate()) {
 165                  $this->warn("ON UPDATE not yet implemented for Oracle builder.(ignoring for ".$this->getColumnList($fk->getLocalColumns())." fk).");
 166                  //$script .= " ON UPDATE ".$fk->getOnUpdate();
 167              }
 168              if ($fk->hasOnDelete()) {
 169                  $script .= " ON DELETE ".$fk->getOnDelete();
 170              }
 171              $script .= ";
 172  ";
 173          }
 174      }
 175  
 176  
 177  }


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