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

codeigniter4 / CodeIgniter4 / 8677009716

13 Apr 2024 11:45PM UTC coverage: 84.44% (-2.2%) from 86.607%
8677009716

push

github

web-flow
Merge pull request #8776 from kenjis/fix-findQualifiedNameFromPath-Cannot-declare-class-v3

fix: Cannot declare class CodeIgniter\Config\Services, because the name is already in use

0 of 3 new or added lines in 1 file covered. (0.0%)

478 existing lines in 72 files now uncovered.

20318 of 24062 relevant lines covered (84.44%)

188.23 hits per line

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

96.83
/system/Database/MySQLi/Builder.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace CodeIgniter\Database\MySQLi;
15

16
use CodeIgniter\Database\BaseBuilder;
17
use CodeIgniter\Database\Exceptions\DatabaseException;
18
use CodeIgniter\Database\RawSql;
19

20
/**
21
 * Builder for MySQLi
22
 */
23
class Builder extends BaseBuilder
24
{
25
    /**
26
     * Identifier escape character
27
     *
28
     * @var string
29
     */
30
    protected $escapeChar = '`';
31

32
    /**
33
     * Specifies which sql statements
34
     * support the ignore option.
35
     *
36
     * @var array
37
     */
38
    protected $supportedIgnoreStatements = [
39
        'update' => 'IGNORE',
40
        'insert' => 'IGNORE',
41
        'delete' => 'IGNORE',
42
    ];
43

44
    /**
45
     * FROM tables
46
     *
47
     * Groups tables in FROM clauses if needed, so there is no confusion
48
     * about operator precedence.
49
     *
50
     * Note: This is only used (and overridden) by MySQL.
51
     */
52
    protected function _fromTables(): string
53
    {
54
        if ($this->QBJoin !== [] && count($this->QBFrom) > 1) {
656✔
55
            return '(' . implode(', ', $this->QBFrom) . ')';
×
56
        }
57

58
        return implode(', ', $this->QBFrom);
656✔
59
    }
60

61
    /**
62
     * Generates a platform-specific batch update string from the supplied data
63
     */
64
    protected function _updateBatch(string $table, array $keys, array $values): string
65
    {
66
        $sql = $this->QBOptions['sql'] ?? '';
17✔
67

68
        // if this is the first iteration of batch then we need to build skeleton sql
69
        if ($sql === '') {
17✔
70
            $constraints = $this->QBOptions['constraints'] ?? [];
17✔
71

72
            if ($constraints === []) {
17✔
73
                if ($this->db->DBDebug) {
1✔
74
                    throw new DatabaseException('You must specify a constraint to match on for batch updates.'); // @codeCoverageIgnore
1✔
75
                }
76

UNCOV
77
                return ''; // @codeCoverageIgnore
×
78
            }
79

80
            $updateFields = $this->QBOptions['updateFields'] ??
16✔
81
                $this->updateFields($keys, false, $constraints)->QBOptions['updateFields'] ??
16✔
82
                [];
13✔
83

84
            $alias = $this->QBOptions['alias'] ?? '`_u`';
16✔
85

86
            $sql = 'UPDATE ' . $this->compileIgnore('update') . $table . "\n";
16✔
87

88
            $sql .= "INNER JOIN (\n{:_table_:}";
16✔
89

90
            $sql .= ') ' . $alias . "\n";
16✔
91

92
            $sql .= 'ON ' . implode(
16✔
93
                ' AND ',
16✔
94
                array_map(
16✔
95
                    static fn ($key, $value) => (
16✔
96
                        ($value instanceof RawSql && is_string($key))
16✔
97
                        ?
16✔
98
                        $table . '.' . $key . ' = ' . $value
1✔
99
                        :
16✔
100
                        (
16✔
101
                            $value instanceof RawSql
15✔
102
                            ?
15✔
103
                            $value
3✔
104
                            :
15✔
105
                            $table . '.' . $value . ' = ' . $alias . '.' . $value
16✔
106
                        )
16✔
107
                    ),
16✔
108
                    array_keys($constraints),
16✔
109
                    $constraints
16✔
110
                )
16✔
111
            ) . "\n";
16✔
112

113
            $sql .= "SET\n";
16✔
114

115
            $sql .= implode(
16✔
116
                ",\n",
16✔
117
                array_map(
16✔
118
                    static fn ($key, $value) => $table . '.' . $key . ($value instanceof RawSql ?
16✔
119
                        ' = ' . $value :
2✔
120
                        ' = ' . $alias . '.' . $value),
16✔
121
                    array_keys($updateFields),
16✔
122
                    $updateFields
16✔
123
                )
16✔
124
            );
16✔
125

126
            $this->QBOptions['sql'] = $sql;
16✔
127
        }
128

129
        if (isset($this->QBOptions['setQueryAsData'])) {
16✔
130
            $data = $this->QBOptions['setQueryAsData'];
1✔
131
        } else {
132
            $data = implode(
15✔
133
                " UNION ALL\n",
15✔
134
                array_map(
15✔
135
                    static fn ($value) => 'SELECT ' . implode(', ', array_map(
15✔
136
                        static fn ($key, $index) => $index . ' ' . $key,
15✔
137
                        $keys,
15✔
138
                        $value
15✔
139
                    )),
15✔
140
                    $values
15✔
141
                )
15✔
142
            ) . "\n";
15✔
143
        }
144

145
        return str_replace('{:_table_:}', $data, $sql);
16✔
146
    }
147
}
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