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

QueryTrait::insert()   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\ForeignKeyEntity;
9
use Lagdo\DbAdmin\Driver\Entity\TriggerEntity;
10
use Lagdo\DbAdmin\Driver\Entity\RoutineEntity;
11
12
use Lagdo\DbAdmin\Driver\Db\ConnectionInterface;
13
use Lagdo\DbAdmin\Driver\Db\StatementInterface;
14
15
trait QueryTrait
16
{
17
    /**
18
     * Get logged user
19
     *
20
     * @return string
21
     */
22
    public function user()
23
    {
24
        return $this->query->user();
25
    }
26
27
    /**
28
     * Get current schema from the database
29
     *
30
     * @return string
31
     */
32
    // public function schema()
33
    // {
34
    //     return $this->query->schema();
35
    // }
36
37
    /**
38
     * Select data from table
39
     *
40
     * @param string $table
41
     * @param array $select Result of processSelectColumns()[0]
42
     * @param array $where Result of processSelectSearch()
43
     * @param array $group Result of processSelectColumns()[1]
44
     * @param array $order Result of processSelectOrder()
45
     * @param int $limit Result of processSelectLimit()
46
     * @param int $page Index of page starting at zero
47
     *
48
     * @return StatementInterface|bool
49
     */
50
    public function select(string $table, array $select, array $where,
51
        array $group, array $order = [], int $limit = 1, int $page = 0)
52
    {
53
        return $this->query->select($table, $select, $where, $group, $order, $limit, $page);
54
    }
55
56
    /**
57
     * Insert data into table
58
     *
59
     * @param string $table
60
     * @param array $set Escaped columns in keys, quoted data in values
61
     *
62
     * @return bool
63
     */
64
    public function insert(string $table, array $set)
65
    {
66
        return $this->query->insert($table, $set);
67
    }
68
69
    /**
70
     * Update data in table
71
     *
72
     * @param string $table
73
     * @param array $set Escaped columns in keys, quoted data in values
74
     * @param string $queryWhere " WHERE ..."
75
     * @param int $limit 0 or 1
76
     * @param string $separator
77
     *
78
     * @return bool
79
     */
80
    public function update(string $table, array $set, string $queryWhere, int $limit = 0, string $separator = "\n")
81
    {
82
        return $this->query->update($table, $set, $queryWhere, $limit, $separator);
83
    }
84
85
    /**
86
     * Delete data from table
87
     *
88
     * @param string $table
89
     * @param string $queryWhere " WHERE ..."
90
     * @param int $limit 0 or 1
91
     *
92
     * @return bool
93
     */
94
    public function delete(string $table, string $queryWhere, int $limit = 0)
95
    {
96
        return $this->query->delete($table, $queryWhere, $limit);
97
    }
98
99
    /**
100
     * Insert or update data in table
101
     *
102
     * @param string $table
103
     * @param array $rows
104
     * @param array $primary of arrays with escaped columns in keys and quoted data in values
105
     *
106
     * @return bool
107
     */
108
    public function insertOrUpdate(string $table, array $rows, array $primary)
109
    {
110
        return $this->query->insertOrUpdate($table, $rows, $primary);
111
    }
112
113
    /**
114
     * Get last auto increment ID
115
     *
116
     * @return string
117
     */
118
    public function lastAutoIncrementId()
119
    {
120
        return $this->query->lastAutoIncrementId();
121
    }
122
123
    /**
124
     * Return query with a timeout
125
     *
126
     * @param string $query
127
     * @param int $timeout In seconds
128
     *
129
     * @return string or null if the driver doesn't support query timeouts
130
     */
131
    public function slowQuery(string $query, int $timeout)
132
    {
133
        return $this->query->slowQuery($query, $timeout);
134
    }
135
136
    /**
137
     * Explain select
138
     *
139
     * @param ConnectionInterface $connection
140
     * @param string $query
141
     *
142
     * @return StatementInterface|bool
143
     */
144
    public function explain(ConnectionInterface $connection, string $query)
145
    {
146
        return $this->query->explain($connection, $query);
147
    }
148
149
    /**
150
     * Get approximate number of rows
151
     *
152
     * @param TableEntity $tableStatus
153
     * @param array $where
154
     *
155
     * @return int|null
156
     */
157
    public function countRows(TableEntity $tableStatus, array $where)
158
    {
159
        return $this->query->countRows($tableStatus, $where);
160
    }
161
162
    /**
163
     * Convert column to be searchable
164
     *
165
     * @param string $idf Escaped column name
166
     * @param array $value ["op" => , "val" => ]
167
     * @param TableFieldEntity $field
168
     *
169
     * @return string
170
     */
171
    public function convertSearch(string $idf, array $value, TableFieldEntity $field)
172
    {
173
        return $this->query->convertSearch($idf, $value, $field);
174
    }
175
176
    /**
177
     * Get view SELECT
178
     *
179
     * @param string $name
180
     *
181
     * @return array array("select" => )
182
     */
183
    public function view(string $name)
184
    {
185
        return $this->query->view($name);
186
    }
187
}
188