1 | <?php |
||
5 | class QueryEngine |
||
6 | { |
||
7 | |||
8 | private $db; |
||
9 | |||
10 | 32 | public function setDriver($driver) |
|
14 | |||
15 | /** |
||
16 | * Generates an SQL insert query string for the model based on the fields |
||
17 | * currently stored in the model. |
||
18 | * |
||
19 | * @param RecordWrapper $model |
||
20 | * @return string |
||
21 | */ |
||
22 | public function getInsertQuery($model) |
||
23 | { |
||
24 | $data = $model->getData(); |
||
25 | $table = $model->getDBStoreInformation()['quoted_table']; |
||
26 | $fields = array_keys($data[0]); |
||
27 | $quotedFields = []; |
||
28 | $valueFields = []; |
||
29 | |||
30 | foreach ($fields as $field) { |
||
31 | $quotedFields[] = $this->db->quoteIdentifier($field); |
||
32 | $valueFields[] = ":{$field}"; |
||
33 | } |
||
34 | |||
35 | return "INSERT INTO " . $table . |
||
36 | " (" . implode(", ", $quotedFields) . ") VALUES (" . implode(', ', $valueFields) . ")"; |
||
37 | } |
||
38 | |||
39 | 6 | public function getBulkUpdateQuery($data, $parameters) |
|
53 | |||
54 | /** |
||
55 | * Generates an SQL update query string for the model based on the data |
||
56 | * currently stored in the model. |
||
57 | * |
||
58 | * @param RecordWrapper $model |
||
59 | * @return string |
||
60 | */ |
||
61 | 2 | public function getUpdateQuery($model) |
|
84 | |||
85 | 24 | public function getSelectQuery($parameters) |
|
97 | |||
98 | 4 | public function getCountQuery($parameters) |
|
99 | { |
||
100 | 4 | return sprintf( |
|
101 | 4 | "SELECT count(*) as count FROM %s%s", |
|
102 | 4 | $parameters->getTable(), |
|
103 | 4 | $parameters->getWhereClause() |
|
104 | ); |
||
105 | } |
||
106 | |||
107 | 2 | public function getDeleteQuery($parameters) |
|
115 | |||
116 | } |
||
117 |