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

SqliteDatabase   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 46
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareEnvironment() 0 3 1
A createDatabase() 0 3 1
A dropDatabase() 0 14 2
A createVersion() 0 5 1
A executeSql() 0 8 2
A executeSqlInternal() 0 4 1
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