Completed
Push — master ( f5a493...f6c233 )
by Joao
03:20
created

SqliteCommand::executeSqlInternal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace ByJG\DbMigration\Commands;
4
5
use ByJG\AnyDataset\ConnectionManagement;
6
7
class SqliteCommand extends AbstractCommand
8
{
9
10
    public static function prepareEnvironment(ConnectionManagement $connection)
11
    {
12
    }
13
14
    public function createDatabase()
15
    {
16
    }
17
18
    public function dropDatabase()
19
    {
20
        $iterator = $this->getDbDataset()->getIterator("
21
            select 
22
                'drop table ' || name || ';' as command 
23
            from sqlite_master 
24
            where type = 'table' 
25
              and name <> 'sqlite_sequence';
26
        ");
27
28
        foreach ($iterator as $row) {
0 ignored issues
show
Bug introduced by
The expression $iterator of type object<ByJG\AnyDataset\R...tory\IteratorInterface> is not traversable.
Loading history...
29
            $this->getDbDataset()->execSQL($row->getField('command'));
30
        }
31
    }
32
33
    public function createVersion()
34
    {
35
        $this->getDbDataset()->execSQL('CREATE TABLE IF NOT EXISTS migration_version (version int)');
36
        $this->checkExistsVersion();
37
    }
38
39
    public function executeSql($sql)
40
    {
41
        $statements = explode(";", $sql);
42
43
        foreach ($statements as $sql) {
44
            $this->executeSqlInternal($sql);
45
        }
46
    }
47
48
    protected function executeSqlInternal($sql)
49
    {
50
        $this->getDbDataset()->execSQL($sql);
51
    }
52
}
53