# Source for file Firebird.php

Documentation is available at Firebird.php

1. <?php
2. /*
3. * $Id: Firebird.php 1616 2007-06-10 19:17:26Z zYne $
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');
22. /**
23. * @package Doctrine
24. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
25. * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
26. * @author Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
27. * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
28. * @version $Revision: 1616 $
29. * @category Object Relational Mapping
30. * @link www.phpdoctrine.com
31. * @since 1.0
32. */
33. class Doctrine_Import_Firebird extends Doctrine_Import
34. {
35. /**
36. * list all tables in the current database
37. *
38. * @return array data array
39. */
40. public function listTables($database = null)
41. {
42. $query = 'SELECT RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG=0 AND RDB$VIEW_BLR IS NULL';
44. return $this->conn->fetchColumn($query);
45. }
46. /**
47. * list all fields in a tables in the current database
48. *
49. * @param string $table name of table that should be used in method
50. * @return mixed data array on success, a MDB2 error on failure
51. * @access public
52. */
53. public function listTableFields($table)
54. {
55. $table = $this->conn->quote(strtoupper($table), 'text');
56. $query = 'SELECT RDB$FIELD_NAME FROM RDB$RELATION_FIELDS WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
58. return $this->conn->fetchColumn($query);
59. }
60. /**
61. * list all users
62. *
63. * @return array data array containing all database users
64. */
65. public function listUsers()
66. {
67. return $this->conn->fetchColumn('SELECT DISTINCT RDB$USER FROM RDB$USER_PRIVILEGES');
68. }
69. /**
70. * list the views in the database
71. *
72. * @return array data array containing all database views
73. */
74. public function listViews($database = null)
75. {
76. return $this->conn->fetchColumn('SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS');
77. }
78. /**
79. * list the views in the database that reference a given table
80. *
81. * @param string $table table for which all references views should be found
82. * @return array data array containing all views for given table
83. */
84. public function listTableViews($table)
85. {
86. $query = 'SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS';
87. $table = $this->conn->quote(strtoupper($table), 'text');
88. $query .= ' WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
90. return $this->conn->fetchColumn($query);
91. }
92. /**
93. * list all functions in the current database
94. *
95. * @return array data array containing all availible functions
96. */
97. public function listFunctions()
98. {
99. $query = 'SELECT RDB$FUNCTION_NAME FROM RDB$FUNCTIONS WHERE RDB$SYSTEM_FLAG IS NULL';
101. return $this->conn->fetchColumn($query);
102. }
103. /**
104. * This function will be called to get all triggers of the
105. * current database ($this->conn->getDatabase())
106. *
107. * @param string $table The name of the table from the
108. * previous database to query against.
109. * @return array data array containing all triggers for given table
110. */
111. public function listTableTriggers($table)
112. {
113. $query = 'SELECT RDB$TRIGGER_NAME FROM RDB$TRIGGERS WHERE RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0';
115. if ( ! is_null($table)) {
116. $table = $this->conn->quote(strtoupper($table), 'text');
117. $query .= ' WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
118. }
120. return $this->conn->fetchColumn($query);
121. }
122. }