Source for file Db.php

Documentation is available at Db.php

  1. <?php
  2. /*
  3.  *  $Id: Db.php 1080 2007-02-10 18:17:08Z romanb $
  4.  *
  5.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16.  *
  17.  * This software consists of voluntary contributions made by many individuals
  18.  * and is licensed under the LGPL. For more information, see
  19.  * <http://www.phpdoctrine.com>.
  20.  */
  21. Doctrine::autoload('Doctrine_Import_Reader');
  22. /**
  23.  * @package     Doctrine
  24.  * @url         http://www.phpdoctrine.com
  25.  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
  26.  * @author      Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
  27.  * @version     $Id: Db.php 1080 2007-02-10 18:17:08Z romanb $
  28.  */
  29. /**
  30.  * class Doctrine_Import_Reader_Db
  31.  * Reads a database using the given PDO connection and constructs a database
  32.  * schema
  33.  * @package     Doctrine
  34.  * @category    Object Relational Mapping
  35.  * @link        www.phpdoctrine.com
  36.  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
  37.  * @since       1.0
  38.  * @version     $Revision: 1080 $
  39.  * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
  40.  */
  41. {
  42.  
  43.     /** Aggregations: */
  44.  
  45.     /*** Attributes: ***/
  46.  
  47.      /*** Attributes: ***/
  48.  
  49.     /**
  50.      * @access private
  51.      */
  52.     private $pdo;
  53.  
  54.     /**
  55.      *
  56.      * @param object pdo      * @return
  57.      * @access public
  58.      */
  59.     public function setPdo$pdo )
  60.     {
  61.  
  62.     // end of member function setPdo
  63.  
  64.     /**
  65.      *
  66.      * @return Doctrine_Schema 
  67.      * @access public
  68.      */
  69.     public function read)
  70.     {
  71.         $dataDict Doctrine_Manager::getInstance()->getCurrentConnection()->getDataDict();
  72.  
  73.         $schema new Doctrine_Schema()/* @todo FIXME i am incomplete*/
  74.         $db new Doctrine_Schema_Database();
  75.         $schema->addDatabase($db);
  76.  
  77.         $dbName 'XXtest'// @todo FIXME where should we get
  78.  
  79.         $this->conn->set("name",$dbName);
  80.         $tableNames $dataDict->listTables();
  81.         foreach ($tableNames as $tableName){
  82.             $table new Doctrine_Schema_Table();
  83.             $table->set("name",$tableName);
  84.             $tableColumns $dataDict->listTableColumns($tableName);
  85.             foreach ($tableColumns as $tableColumn){
  86.                 $table->addColumn($tableColumn);
  87.             }
  88.             $this->conn->addTable($table);
  89.             if ($fks $dataDict->listTableConstraints($tableName)){
  90.                 foreach ($fks as $fk){
  91.                     $relation new Doctrine_Schema_Relation();
  92.                     $relation->setRelationBetween($fk['referencingColumn'],$fk['referencedTable'],$fk['referencedColumn']);
  93.                     $table->setRelation($relation);
  94.                 }
  95.             }
  96.         }
  97.  
  98.         return $schema;
  99.     }
  100.  
  101. // end of Doctrine_Import_Reader_Db