Completed
Push — master ( 0a0cac...20d758 )
by joanhey
20s queued 11s
created

SqliteMetadata   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A queryFields() 0 18 4
1
<?php
2
3
/**
4
 * KumbiaPHP web & app Framework.
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file LICENSE.txt.
10
 * It is also available through the world-wide-web at this URL:
11
 * http://wiki.kumbiaphp.com/Licencia
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @category   Kumbia
17
 *
18
 * @copyright  2005 - 2020  Kumbia Team (http://www.kumbiaphp.com)
19
 * @license    http://wiki.kumbiaphp.com/Licencia     New BSD License
20
 */
21
namespace Kumbia\ActiveRecord\Metadata;
22
23
use \PDO;
24
25
/**
26
 * Adaptador de Metadata para SQLite.
27
 */
28
class SqliteMetadata extends Metadata
29
{
30
    /**
31
     * Consultar los campos de la tabla en la base de datos.
32
     *
33
     * @param  \PDO    $pdo      base de datos
34
     * @param  string  $table    tabla
35
     * @param  string  $schema   squema
36
     * 
37
     * @return array
38
     */
39
    protected function queryFields(\PDO $pdo, string $table, string $schema = ''): array
40
    {
41
        $describe = $pdo->query("PRAGMA table_info($table)", \PDO::FETCH_OBJ);
42
        //var_dump($results); die();
43
        $fields = [];
44
        foreach ($describe as $value) {
45
            $fields[$value->name] = [
46
                'Type' => \strtolower(\str_replace(' ', '', $value->type)),
47
                'Null' => $value->notnull == 0,
48
                'Default' => (bool) $value->dflt_value,
49
                'Key' => $value->pk == 1 ? 'PRI' : '',
50
                'Auto' => (\strtolower($value->type) == 'int' && $value->pk == 1) // using rowid
51
            ];
52
            $this->filterColumn($fields[$value->name], $value->name);
53
        }
54
55
        return $fields;
56
    }
57
}
58