Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
60.00% |
6 / 10 |
|
60.00% |
6 / 10 |
CRAP | |
0.00% |
0 / 1 |
| common_persistence_SqlPersistence | |
60.00% |
6 / 10 |
|
60.00% |
6 / 10 |
16.40 | |
0.00% |
0 / 1 |
| getSchemaManager | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPlatForm | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| exec | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| insert | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| insertMultiple | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| updateMultiple | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| query | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| quote | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| lastInsertId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| transactional | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2013-2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * @author Lionel Lecaque <lionel@taotesting.com> |
| 21 | * @author Jerome Bogaerts, <jerome@taotesting.com> |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | use Doctrine\DBAL\Driver\Statement; |
| 26 | |
| 27 | /** |
| 28 | * Persistence base on SQL |
| 29 | */ |
| 30 | class common_persistence_SqlPersistence extends common_persistence_Persistence implements |
| 31 | common_persistence_Transactional |
| 32 | { |
| 33 | /** |
| 34 | * @return common_persistence_sql_SchemaManager |
| 35 | */ |
| 36 | public function getSchemaManager() |
| 37 | { |
| 38 | return $this->getDriver()->getSchemaManager(); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @return common_persistence_sql_Platform |
| 43 | */ |
| 44 | public function getPlatForm() |
| 45 | { |
| 46 | return $this->getDriver()->getPlatform(); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Execute a statement. |
| 51 | * |
| 52 | * @param string $statement |
| 53 | * @param array $params |
| 54 | * @param array $types |
| 55 | * @return int number of updated rows |
| 56 | */ |
| 57 | public function exec($statement, array $params = [], array $types = []) |
| 58 | { |
| 59 | return $this->getDriver()->exec($statement, $params, $types); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Inserts one row. |
| 64 | * |
| 65 | * @param string $tableName |
| 66 | * @param array $data |
| 67 | * @param array $types |
| 68 | * @return int number of updated rows |
| 69 | */ |
| 70 | public function insert($tableName, array $data, array $types = []) |
| 71 | { |
| 72 | return $this->getDriver()->insert($tableName, $data, $types); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Inserts multiple rows. |
| 77 | * |
| 78 | * @param $tableName |
| 79 | * @param array $data |
| 80 | * @param array $types |
| 81 | * @return int number of updated rows |
| 82 | */ |
| 83 | public function insertMultiple($tableName, array $data, array $types = []) |
| 84 | { |
| 85 | return $this->getDriver()->insertMultiple($tableName, $data, $types); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Update multiple rows. |
| 90 | * |
| 91 | * @param string $table |
| 92 | * @param array $data |
| 93 | * @return bool |
| 94 | * @throws Exception |
| 95 | */ |
| 96 | public function updateMultiple($table, array $data) |
| 97 | { |
| 98 | return $this->getDriver()->updateMultiple($table, $data); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Executes parameterized query. |
| 103 | * |
| 104 | * @param string $statement |
| 105 | * @param array $params |
| 106 | * @param array $types |
| 107 | * @return Statement |
| 108 | */ |
| 109 | public function query($statement, $params = [], array $types = []) |
| 110 | { |
| 111 | return $this->getDriver()->query($statement, $params, $types); |
| 112 | } |
| 113 | |
| 114 | |
| 115 | /** |
| 116 | * Convenience access to quote. |
| 117 | * |
| 118 | * @param string $parameter The parameter to quote. |
| 119 | * @param int $parameter_type A PDO PARAM_XX constant. |
| 120 | * @return string The quoted string. |
| 121 | */ |
| 122 | public function quote($parameter, $parameter_type = PDO::PARAM_STR) |
| 123 | { |
| 124 | return $this->getDriver()->quote($parameter, $parameter_type); |
| 125 | } |
| 126 | |
| 127 | |
| 128 | /** |
| 129 | * Convenience access to lastInsertId. |
| 130 | * |
| 131 | * @param string $name |
| 132 | * @return string The quoted string. |
| 133 | */ |
| 134 | public function lastInsertId($name = null) |
| 135 | { |
| 136 | return $this->getDriver()->lastInsertId($name); |
| 137 | } |
| 138 | |
| 139 | |
| 140 | /** |
| 141 | * Execute a function within a transaction. |
| 142 | * |
| 143 | * @param Closure $func The function to execute in a transactional way. |
| 144 | * |
| 145 | * @return mixed The value returned by $func |
| 146 | * |
| 147 | * @throws Throwable |
| 148 | */ |
| 149 | public function transactional(Closure $func) |
| 150 | { |
| 151 | return $this->getDriver()->transactional($func); |
| 152 | } |
| 153 | } |