Completed
Push — master ( 229d9d...1c9390 )
by Alberto
01:52
created

MysqlMetadata   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 3
c 5
b 1
f 0
lcom 0
cbo 2
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A queryFields() 0 20 3
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 - 2016  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 Kumbia\ActiveRecord\Db;
24
use PDO;
25
26
/**
27
 * Adaptador de Metadata para Mysql.
28
 */
29
class MysqlMetadata extends Metadata
30
{
31
    /**
32
     * Consultar los campos de la tabla en la base de datos.
33
     *
34
     * @param string $database base de datos
35
     * @param string $table    tabla
36
     * @param string $schema   squema
37
     *
38
     * @return array
39
     */
40
    protected function queryFields($database, $table, $schema = null)
41
    {
42
        $sql = $schema ? "DESCRIBE `$schema`.`$table`" : "DESCRIBE `$table`";
43
        $describe = Db::get($database)->query($sql);
44
45
        $fields = [];
46
        // TODO mejorar este código
47
        while (($value = $describe->fetch(PDO::FETCH_OBJ))) {
48
            $fields[$value->Field] = [
49
                'Type'    => $value->Type,
50
                'Null'    => $value->Null != 'NO',
51
                'Key'     => $value->Key,
52
                'Default' => $value->Default != '',
53
                'Auto'    => $value->Extra == 'auto_increment',
54
            ];
55
            $this->filterCol($fields[$value->Field], $value->Field);
56
        }
57
58
        return $fields;
59
    }
60
}
61