• 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/Dblib.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 an Dblib (SQL Server) database.
16
 */
17
class Dblib extends AbstractMetadata
18
{
19
    /**
20
     * No character used to quote schema objects.
21
     *
22
     * @var string
23
     */
24
    protected $schemaObjectQuoteChar = '';
25

26
    /**
27
     * The command used to perform a TRUNCATE operation.
28
     *
29
     * @var string
30
     */
31
    protected $truncateCommand = 'TRUNCATE TABLE';
32

33
    /**
34
     * @var array
35
     */
36
    protected $columns = [];
37

38
    /**
39
     * @var array
40
     */
41
    protected $keys = [];
42

43
    /**
44
     * Returns an array containing the names of all the tables in the database.
45
     *
46
     * @return array
47
     */
48
    public function getTableNames()
49
    {
50
        $tableNames = [];
×
51

52
        $query = 'SELECT name
×
53
                    FROM sys.tables
54
                   ORDER BY name';
×
55

56
        $result = $this->pdo->query($query);
×
57

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

62
        return $tableNames;
×
63
    }
64

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

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

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

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

99
    /**
100
     * Loads column info from a sql server database.
101
     *
102
     * @param string $tableName
103
     */
104
    protected function loadColumnInfo($tableName): void
105
    {
106
        $query = "SELECT name
×
107
                        FROM sys.columns
108
                   WHERE object_id = OBJECT_ID('" . $tableName . "')
×
109
                   ORDER BY column_id";
×
110

111
        $result = $this->pdo->query($query);
×
112

113
        while ($columnName = $result->fetchColumn(0)) {
×
114
            $this->columns[$tableName][] = $columnName;
×
115
        }
116

117
        $keyQuery = "SELECT COL_NAME(ic.OBJECT_ID,ic.column_id) AS ColumnName
×
118
                        FROM    sys.indexes AS i INNER JOIN 
119
                                sys.index_columns AS ic ON  i.OBJECT_ID = ic.OBJECT_ID
120
                                                        AND i.index_id = ic.index_id
121
                        WHERE   i.is_primary_key = 1 AND OBJECT_NAME(ic.OBJECT_ID) = '" . $tableName . "'";
×
122

123
        $result = $this->pdo->query($keyQuery);
×
124

125
        while ($columnName = $result->fetchColumn(0)) {
×
126
            $this->keys[$tableName][] = $columnName;
×
127
        }
128
    }
129
}
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

© 2025 Coveralls, Inc