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: 171c9591b4b59cda78d8d4a93d441f421c812f4c
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
203
204
205
206
207
208
209
210
...
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
...
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301

            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))
                    {
                        throw new \InvalidArgumentException(__FUNCTION__ . ' requires argument to be a named-associative array, but key '.$key.' is an integer.');
                    }

                    $type = $this->getArgType($value, $key);
                    $statement->bindValue(':'.$key, $value, $type);
                }
            }
        }
................................................................................
        {
            throw new \RuntimeException($e->getMessage() . "\n" . $query . "\n" . json_encode($args, true));
        }
    }

    public function get($query)
    {
        $args = array_slice(func_get_args(), 2);
        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(), 2);
        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, 
................................................................................
        }

        $args = array_slice(func_get_args(), 3);
        $column_updates = [];
        
        foreach ($fields as $key=>$value)
        {
            $key = 'field_' . $key;

            // Append to arguments
            $args[$key] = $value;

            $column_updates[] = sprintf('%s = :%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);
    }
................................................................................
    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(), 2));

        $row = $res->fetchArray($all_columns ? SQLITE3_ASSOC : SQLITE3_NUM);
        $res->finalize();

        return is_array($row) ? (object) $row : false;
    }

    public function firstColumn($query)
    {







>
>
>
>
>










|







 







|











|







 







<
<

|

|







 







|

|







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
...
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
...
263
264
265
266
267
268
269


270
271
272
273
274
275
276
277
278
279
280
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304

            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);
                }
            }
        }
................................................................................
        {
            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, 
................................................................................
        }

        $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);
    }
................................................................................
    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)
    {