# 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. class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
42. {
44. /** Aggregations: */
46. /*** Attributes: ***/
48. /*** Attributes: ***/
50. /**
51. * @access private
52. */
53. private $pdo;
55. /**
56. *
57. * @param object pdo * @return
58. * @access public
59. */
60. public function setPdo( $pdo )
61. {
63. } // end of member function setPdo
65. /**
66. *
67. * @return Doctrine_Schema
68. * @access public
69. */
70. public function read( )
71. {
72. $dataDict = Doctrine_Manager::getInstance()->getCurrentConnection()->getDataDict();
74. $schema = new Doctrine_Schema(); /* @todo FIXME i am incomplete*/
75. $db = new Doctrine_Schema_Database();
76. $schema->addDatabase($db);
78. $dbName = 'XXtest'; // @todo FIXME where should we get
80. $this->conn->set("name",$dbName);
81. $tableNames = $dataDict->listTables();
82. foreach ($tableNames as $tableName){
83. $table = new Doctrine_Schema_Table();
84. $table->set("name",$tableName);
85. $tableColumns = $dataDict->listTableColumns($tableName);
86. foreach ($tableColumns as $tableColumn){
87. $table->addColumn($tableColumn);
88. }
89. $this->conn->addTable($table);
90. if ($fks = $dataDict->listTableConstraints($tableName)){
91. foreach ($fks as $fk){
92. $relation = new Doctrine_Schema_Relation();
93. $relation->setRelationBetween($fk['referencingColumn'],$fk['referencedTable'],$fk['referencedColumn']);
94. $table->setRelation($relation);
95. }
96. }
97. }
99. return $schema;
100. }
102. } // end of Doctrine_Import_Reader_Db