Overview
Comment: | Correction de quelques bugs dans la gestion de DB |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | dev |
Files: | files | file ages | folders |
SHA1: |
171c9591b4b59cda78d8d4a93d441f42 |
User & Date: | bohwaz on 2017-03-17 04:50:06 |
Other Links: | branch diff | manifest | tags |
Context
2017-03-29
| ||
04:48 | Ajout documentation dans DB.php et ajout de tests pour la DB check-in: 8422f038fe user: bohwaz tags: dev | |
2017-03-17
| ||
04:50 | Correction de quelques bugs dans la gestion de DB check-in: 171c9591b4 user: bohwaz tags: dev | |
04:48 | Ré-écriture de la gestion de session, en séparant ça de la classe Membres check-in: 8c2d53a79d user: bohwaz tags: dev | |
Changes
Modified src/include/lib/Garradin/DB.php from [599bdd31e0] to [7f184d61e2].
︙ | ︙ | |||
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | reset($args); if (is_int(key($args))) { foreach ($args as $i=>$arg) { $type = $this->getArgType($arg, $i+1); $statement->bindValue((int)$i+1, $arg, $type); } } else { foreach ($args as $key=>$value) { if (is_int($key)) { | > > > > > | | 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | reset($args); if (is_int(key($args))) { foreach ($args as $i=>$arg) { if (is_string($i)) { throw new \InvalidArgumentException(sprintf('%s requires argument to be a keyed array, but key %s is a string.', __FUNCTION__, $i)); } $type = $this->getArgType($arg, $i+1); $statement->bindValue((int)$i+1, $arg, $type); } } else { foreach ($args as $key=>$value) { if (is_int($key)) { throw new \InvalidArgumentException(sprintf('%s requires argument to be a named-associative array, but key %s is an integer.', __FUNCTION__, $key)); } $type = $this->getArgType($value, $key); $statement->bindValue(':'.$key, $value, $type); } } } |
︙ | ︙ | |||
220 221 222 223 224 225 226 | { throw new \RuntimeException($e->getMessage() . "\n" . $query . "\n" . json_encode($args, true)); } } public function get($query) { | | | | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | { throw new \RuntimeException($e->getMessage() . "\n" . $query . "\n" . json_encode($args, true)); } } public function get($query) { $args = array_slice(func_get_args(), 1); return $this->fetch($this->query($query, $args), self::OBJ); } public function getAssoc($query) { $args = array_slice(func_get_args(), 1); return $this->fetchAssoc($this->query($query, $args)); } public function getAssocKey($query) { $args = array_slice(func_get_args(), 1); return $this->fetchAssocKey($this->query($query, $args), self::OBJ); } public function insert($table, Array $fields) { $fields_names = array_keys($fields); $query = sprintf('INSERT INTO %s (%s) VALUES (:%s);', $table, |
︙ | ︙ | |||
258 259 260 261 262 263 264 | } $args = array_slice(func_get_args(), 3); $column_updates = []; foreach ($fields as $key=>$value) { | < < | | | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | } $args = array_slice(func_get_args(), 3); $column_updates = []; foreach ($fields as $key=>$value) { // Append to arguments $args['field_' . $key] = $value; $column_updates[] = sprintf('%s = :field_%s', $key, $key); } $column_updates = implode(', ', $column_updates); $query = sprintf('UPDATE %s SET %s WHERE %s;', $table, $column_updates, $where); return $this->query($query, $args); } |
︙ | ︙ | |||
285 286 287 288 289 290 291 | public function exec($query) { return $this->query($query, array_slice(func_get_args(), 1)); } public function first($query) { | | | | 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | public function exec($query) { return $this->query($query, array_slice(func_get_args(), 1)); } public function first($query) { $res = $this->query($query, array_slice(func_get_args(), 1)); $row = $res->fetchArray(SQLITE3_ASSOC); $res->finalize(); return is_array($row) ? (object) $row : false; } public function firstColumn($query) { |
︙ | ︙ |