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 Mysql. |
27
|
|
|
*/ |
28
|
|
|
class MysqlMetadata 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
|
|
|
$sql = $schema ? "DESCRIBE `$schema`.`$table`" : "DESCRIBE `$table`"; |
42
|
|
|
$describe = $pdo->query($sql, \PDO::FETCH_OBJ); |
43
|
|
|
|
44
|
|
|
$fields = []; |
45
|
|
|
// TODO mejorar este código |
46
|
|
|
while ($value = $describe->fetch()) { |
47
|
|
|
$fields[$value->Field] = [ |
48
|
|
|
'Type' => $value->Type, |
49
|
|
|
'Null' => $value->Null !== 'NO', |
50
|
|
|
'Key' => $value->Key, |
51
|
|
|
'Default' => $value->Default != '', |
52
|
|
|
'Auto' => $value->Extra === 'auto_increment' |
53
|
|
|
]; |
54
|
|
|
$this->filterColumn($fields[$value->Field], $value->Field); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $fields; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|