Passed
Push — main ( af1024...b746de )
by Thierry
02:04
created

GrammarTrait::applySqlFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Lagdo\DbAdmin\Driver;
4
5
use Lagdo\DbAdmin\Driver\Entity\ConfigEntity;
6
use Lagdo\DbAdmin\Driver\Entity\TableEntity;
7
use Lagdo\DbAdmin\Driver\Entity\TableFieldEntity;
8
use Lagdo\DbAdmin\Driver\Entity\TableSelectEntity;
9
use Lagdo\DbAdmin\Driver\Entity\ForeignKeyEntity;
10
use Lagdo\DbAdmin\Driver\Entity\TriggerEntity;
11
use Lagdo\DbAdmin\Driver\Entity\RoutineEntity;
12
13
trait GrammarTrait
14
{
15
    /**
16
     * Get escaped table name
17
     *
18
     * @param string $idf
19
     *
20
     * @return string
21
     */
22
    public function table(string $idf)
23
    {
24
        return $this->grammar->table($idf);
25
    }
26
27
    /**
28
     * Escape database identifier
29
     *
30
     * @param string $idf
31
     *
32
     * @return string
33
     */
34
    public function escapeId(string $idf)
35
    {
36
        return $this->grammar->escapeId($idf);
37
    }
38
39
    /**
40
     * Unescape database identifier
41
     *
42
     * @param string $idf
43
     *
44
     * @return string
45
     */
46
    public function unescapeId(string $idf)
47
    {
48
        return $this->grammar->unescapeId($idf);
49
    }
50
51
    /**
52
     * Convert field in select and edit
53
     *
54
     * @param TableFieldEntity $field one element from $this->fields()
55
     *
56
     * @return string
57
     */
58
    public function convertField(TableFieldEntity $field)
59
    {
60
        return $this->grammar->convertField($field);
61
    }
62
63
    /**
64
     * Convert value in edit after applying functions back
65
     *
66
     * @param TableFieldEntity $field One element from $this->fields()
67
     * @param string $value
68
     *
69
     * @return string
70
     */
71
    public function unconvertField(TableFieldEntity $field, string $value)
72
    {
73
        return $this->grammar->unconvertField($field, $value);
74
    }
75
76
    /**
77
     * Get select clause for convertible fields
78
     *
79
     * @param array $columns
80
     * @param array $fields
81
     * @param array $select
82
     *
83
     * @return string
84
     */
85
    public function convertFields(array $columns, array $fields, array $select = [])
86
    {
87
        return $this->grammar->convertFields($columns, $fields, $select);
88
    }
89
90
    /**
91
     * Select data from table
92
     *
93
     * @param TableSelectEntity $select
94
     *
95
     * @return string
96
     */
97
    public function buildSelectQuery(TableSelectEntity $select)
98
    {
99
        return $this->grammar->buildSelectQuery($select);
100
    }
101
102
    /**
103
     * Get query to compute number of found rows
104
     *
105
     * @param string $table
106
     * @param array $where
107
     * @param bool $isGroup
108
     * @param array $groups
109
     *
110
     * @return string
111
     */
112
    public function countRowsSql(string $table, array $where, bool $isGroup, array $groups)
113
    {
114
        return $this->grammar->countRowsSql($table, $where, $isGroup, $groups);
115
    }
116
117
    /**
118
     * Get default value clause
119
     *
120
     * @param TableFieldEntity $field
121
     *
122
     * @return string
123
     */
124
    public function defaultValue(TableFieldEntity $field)
125
    {
126
        return $this->grammar->defaultValue($field);
127
    }
128
129
    /**
130
     * Formulate SQL query with limit
131
     *
132
     * @param string $query Everything after SELECT
133
     * @param string $where Including WHERE
134
     * @param int $limit
135
     * @param int $offset
136
     * @param string $separator
137
     *
138
     * @return string
139
     */
140
    public function limit(string $query, string $where, int $limit, int $offset = 0, string $separator = " ")
141
    {
142
        return $this->grammar->limit($query, $where, $limit, $offset, $separator);
143
    }
144
145
    /**
146
     * Format foreign key to use in SQL query
147
     *
148
     * @param ForeignKeyEntity $foreignKey
149
     *
150
     * @return string
151
     */
152
    public function formatForeignKey(ForeignKeyEntity $foreignKey)
153
    {
154
        return $this->grammar->formatForeignKey($foreignKey);
155
    }
156
157
    /**
158
     * Generate modifier for auto increment column
159
     *
160
     * @return string
161
     */
162
    public function autoIncrement()
163
    {
164
        return $this->grammar->autoIncrement();
165
    }
166
167
    /**
168
     * Get SQL command to create table
169
     *
170
     * @param string $table
171
     * @param bool $autoIncrement
172
     * @param string $style
173
     *
174
     * @return string
175
     */
176
    public function sqlForCreateTable(string $table, bool $autoIncrement, string $style)
177
    {
178
        return $this->grammar->sqlForCreateTable($table, $autoIncrement, $style);
179
    }
180
181
    /**
182
     * Command to create an index
183
     *
184
     * @param string $table
185
     * @param string $type
186
     * @param string $name
187
     * @param string $columns
188
     *
189
     * @return string
190
     */
191
    public function sqlForCreateIndex(string $table, string $type, string $name, string $columns)
192
    {
193
        return $this->grammar->sqlForCreateIndex($table, $type, $name, $columns);
194
    }
195
196
    /**
197
     * Get SQL command to create foreign keys
198
     *
199
     * sqlForCreateTable() produces CREATE TABLE without FK CONSTRAINTs
200
     * sqlForForeignKeys() produces all FK CONSTRAINTs as ALTER TABLE ... ADD CONSTRAINT
201
     * so that all FKs can be added after all tables have been created, avoiding any need
202
     * to reorder CREATE TABLE statements in order of their FK dependencies
203
     *
204
     * @param string $table
205
     *
206
     * @return string
207
     */
208
    public function sqlForForeignKeys(string $table)
209
    {
210
        return $this->grammar->sqlForForeignKeys($table);
211
    }
212
213
    /**
214
     * Get SQL command to truncate table
215
     *
216
     * @param string $table
217
     *
218
     * @return string
219
     */
220
    public function sqlForTruncateTable(string $table)
221
    {
222
        return $this->grammar->sqlForTruncateTable($table);
223
    }
224
225
    /**
226
     * Get SQL command to change database
227
     *
228
     * @param string $database
229
     *
230
     * @return string
231
     */
232
    public function sqlForUseDatabase(string $database)
233
    {
234
        return $this->grammar->sqlForUseDatabase($database);
235
    }
236
237
    /**
238
     * Get SQL commands to create triggers
239
     *
240
     * @param string $table
241
     *
242
     * @return string
243
     */
244
    public function sqlForCreateTrigger(string $table)
245
    {
246
        return $this->grammar->sqlForCreateTrigger($table);
247
    }
248
249
    /**
250
     * Return query to get connection ID
251
     *
252
     * @return string
253
     */
254
    // public function connectionId()
255
    // {
256
    //     return $this->grammar->connectionId();
257
    // }
258
}
259