Completed
Push — master ( 9bd1b4...a21c41 )
by Joao
04:25 queued 02:23
created

SqliteDatabase::dropDatabase()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace ByJG\DbMigration\Database;
4
5
use ByJG\Util\Uri;
6
7
class SqliteDatabase extends AbstractDatabase
8
{
9
10
    public static function prepareEnvironment(Uri $uri)
11
    {
12
    }
13
14
    public function createDatabase()
15
    {
16
    }
17
18
    public function dropDatabase()
19
    {
20
        $iterator = $this->getDbDriver()->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) {
29
            $this->getDbDriver()->execute($row->get('command'));
30
        }
31
    }
32
33
    public function createVersion()
34
    {
35
        $this->getDbDriver()->execute('CREATE TABLE IF NOT EXISTS migration_version (version int, status varchar(20))');
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->getDbDriver()->execute($sql);
51
    }
52
}
53