• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

misantron / dbunit / 4562384438

pending completion
4562384438

push

github

Aleksandr Ivanov
Fix build status badge display

635 of 1200 relevant lines covered (52.92%)

5.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Database/Metadata/Firebird.php
1
<?php
2

3
/*
4
 * This file is part of DbUnit.
5
 *
6
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
namespace PHPUnit\DbUnit\Database\Metadata;
13

14
/**
15
 * Provides functionality to retrieve meta data from a Firebird database.
16
 */
17
class Firebird extends AbstractMetadata
18
{
19
    /**
20
     * The command used to perform a TRUNCATE operation.
21
     *
22
     * @var string
23
     */
24
    protected $truncateCommand = 'DELETE FROM';
25

26
    /**
27
     * Returns an array containing the names of all the tables in the database.
28
     *
29
     * @return array
30
     */
31
    public function getTableNames()
32
    {
33
        $query = "
×
34
            SELECT DISTINCT
35
                TABLE_NAME
36
            FROM INFORMATION_SCHEMA.TABLES
37
            WHERE
38
                TABLE_TYPE='BASE TABLE' AND
39
                TABLE_SCHEMA = ?
40
            ORDER BY TABLE_NAME
41
        ";
×
42

43
        $query = "
×
44
            select
45
              RDB$RELATION_NAME as TABLE_NAME
×
46
            from RDB$RELATIONS
×
47
            where
48
              ((RDB$RELATION_TYPE = 0) or
×
49
               (RDB$RELATION_TYPE is null)) and
×
50
              (RDB$SYSTEM_FLAG = 0)
×
51
            order by (RDB$RELATION_NAME)
×
52
        ";
×
53

54
        $statement = $this->pdo->prepare($query);
×
55
        $statement->execute([$this->getSchema()]);
×
56

57
        $tableNames = [];
×
58

59
        while ($tableName = $statement->fetchColumn(0)) {
×
60
            $tableNames[] = $tableName;
×
61
        }
62

63
        return $tableNames;
×
64
    }
65

66
    /**
67
     * Returns an array containing the names of all the columns in the
68
     * $tableName table,
69
     *
70
     * @param string $tableName
71
     *
72
     * @return array
73
     */
74
    public function getTableColumns($tableName)
75
    {
76
        if (!isset($this->columns[$tableName])) {
×
77
            $this->loadColumnInfo($tableName);
×
78
        }
79

80
        return $this->columns[$tableName];
×
81
    }
82

83
    /**
84
     * Returns an array containing the names of all the primary key columns in
85
     * the $tableName table.
86
     *
87
     * @param string $tableName
88
     *
89
     * @return array
90
     */
91
    public function getTablePrimaryKeys($tableName)
92
    {
93
        if (!isset($this->keys[$tableName])) {
×
94
            $this->loadColumnInfo($tableName);
×
95
        }
96

97
        return $this->keys[$tableName];
×
98
    }
99

100
    /**
101
     * Returns the schema for the connection.
102
     *
103
     * @return string
104
     */
105
    public function getSchema()
106
    {
107
        if (empty($this->schema)) {
×
108
            return 'public';
×
109
        }
110

111
        return $this->schema;
×
112
    }
113

114
    /**
115
     * Returns true if the rdbms allows cascading
116
     *
117
     * @return bool
118
     */
119
    public function allowsCascading()
120
    {
121
        return false;
×
122
    }
123

124
    /**
125
     * Returns a quoted schema object. (table name, column name, etc)
126
     *
127
     * @param string $object
128
     *
129
     * @return string
130
     */
131
    public function quoteSchemaObject($object)
132
    {
133
        return $object; //firebird does not allow object quoting
×
134
    }
135

136
    /**
137
     * Loads column info from a database table.
138
     *
139
     * @param string $tableName
140
     */
141
    protected function loadColumnInfo($tableName): void
142
    {
143
        $this->columns[$tableName] = [];
×
144
        $this->keys[$tableName]    = [];
×
145

146
        $columnQuery = '
×
147
            SELECT DISTINCT
148
                COLUMN_NAME, ORDINAL_POSITION
149
            FROM INFORMATION_SCHEMA.COLUMNS
150
            WHERE
151
                TABLE_NAME = ? AND
152
                TABLE_SCHEMA = ?
153
            ORDER BY ORDINAL_POSITION
154
        ';
×
155

156
        $columnQuery = '
×
157
            select
158
              rf.RDB$FIELD_NAME as COLUMN_NAME,
159
              rf.RDB$FIELD_POSITION as ORDINAL_POSITION
160
            from RDB$RELATION_FIELDS as rf
161
            where
162
              upper(RDB$RELATION_NAME) = upper(?)
163
            order by
164
              ORDINAL_POSITION
165

166
        ';
×
167

168
        $columnStatement = $this->pdo->prepare($columnQuery);
×
169
        $columnStatement->execute([$tableName]);
×
170

171
        while ($columName = $columnStatement->fetchColumn(0)) {
×
172
            $this->columns[$tableName][] = $columName;
×
173
        }
174

175
        $keyQuery = "
×
176
            SELECT
177
                KCU.COLUMN_NAME,
178
                KCU.ORDINAL_POSITION
179
            FROM
180
                INFORMATION_SCHEMA.KEY_COLUMN_USAGE as KCU
181
            LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS as TC
182
                ON TC.TABLE_NAME = KCU.TABLE_NAME
183
            WHERE
184
                TC.CONSTRAINT_TYPE = 'PRIMARY KEY' AND
185
                TC.TABLE_NAME = ? AND
186
                TC.TABLE_SCHEMA = ?
187
            ORDER BY
188
                KCU.ORDINAL_POSITION ASC
189
        ";
×
190

191
        $keyQuery = "
×
192
            select
193
              idseg.rdb\$field_name as COLUMN_NAME,
194
              idseg.rdb\$field_position as ORDINAL_POSITION,
195
              rc.rdb\$relation_name as tablename,
196
              rc.rdb\$constraint_name as pk_name
197
            from
198
              RDB\$RELATION_CONSTRAINTS AS rc
199
                left join
200
              rdb\$index_segments as idseg on
201
                (rc.rdb\$index_name = idseg.rdb\$index_name)
202
            where
203
              rc.RDB\$CONSTRAINT_TYPE = 'PRIMARY KEY'
204
              and upper(rc.RDB\$RELATION_NAME) = upper(?)
205
            order by
206
              rc.rdb\$constraint_name, idseg.rdb\$field_position
207
        ";
×
208

209
        $keyStatement = $this->pdo->prepare($keyQuery);
×
210
        $keyStatement->execute([$tableName]);
×
211

212
        while ($columName = $keyStatement->fetchColumn(0)) {
×
213
            $this->keys[$tableName][] = $columName;
×
214
        }
215
    }
216
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc