1 | <?php |
||
16 | class SQLiteDriver extends AbstractDriver implements DriverInterface |
||
17 | { |
||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $columns = []; |
||
22 | |||
23 | /** |
||
24 | * @var \PDO |
||
25 | */ |
||
26 | protected $pdo; |
||
27 | |||
28 | /** |
||
29 | * @param PDO $pdo |
||
30 | */ |
||
31 | 21 | public function __construct(\PDO $pdo) |
|
35 | |||
36 | /** |
||
37 | * Returns the result. |
||
38 | * |
||
39 | * @param string $tableName |
||
40 | * @return array |
||
41 | */ |
||
42 | 15 | public function getTable($tableName) |
|
50 | |||
51 | /** |
||
52 | * Shows the list of tables. |
||
53 | * |
||
54 | * @return array |
||
55 | */ |
||
56 | 6 | public function showTables() |
|
57 | { |
||
58 | 6 | $tables = []; |
|
59 | |||
60 | 6 | $query = $this->pdo->prepare('SELECT name FROM sqlite_master WHERE type = "table";'); |
|
61 | |||
62 | 6 | $query->execute(); |
|
63 | 6 | $query->setFetchMode(\PDO::FETCH_OBJ); |
|
64 | |||
65 | 6 | while ($row = $query->fetch()) { |
|
66 | 6 | if ($row->name != 'sqlite_sequence') { |
|
67 | 6 | array_push($tables, $row->name); |
|
68 | 6 | } |
|
69 | 6 | } |
|
70 | |||
71 | 6 | return $tables; |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * Prepares the defined columns. |
||
76 | * |
||
77 | * @param string $tableName |
||
78 | * @param mixed $row |
||
79 | * @return void |
||
80 | */ |
||
81 | 12 | protected function setColumn($tableName, $row) |
|
82 | { |
||
83 | 12 | $column = new Column; |
|
84 | |||
85 | 12 | $this->setProperties($row, $column); |
|
86 | |||
87 | 12 | $column->setDefaultValue($row->dflt_value); |
|
88 | 12 | $column->setField($row->name); |
|
89 | 12 | $column->setDataType(strtolower($row->type)); |
|
90 | |||
91 | 12 | $this->setForeignColumn($tableName, $column); |
|
92 | |||
93 | 12 | array_push($this->columns, $column); |
|
94 | 12 | } |
|
95 | |||
96 | /** |
||
97 | * Sets the properties of the specified column if it does exists. |
||
98 | * |
||
99 | * @param string $tableName |
||
100 | * @param \Rougin\Describe\Column &$column |
||
101 | * @return void |
||
102 | */ |
||
103 | 12 | protected function setForeignColumn($tableName, Column &$column) |
|
119 | |||
120 | /** |
||
121 | * Sets the properties of the specified column. |
||
122 | * |
||
123 | * @param mixed $row |
||
124 | * @param \Rougin\Describe\Column &$column |
||
125 | * @return void |
||
126 | */ |
||
127 | 12 | protected function setProperties($row, Column &$column) |
|
138 | } |
||
139 |