Passed
Push — master ( 9155e7...72c61b )
by 世昌
02:37
created

SQLiteTableCreator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 5 1
A toSQL() 0 4 1
A seekField() 0 8 2
1
<?php
2
namespace suda\application\database\creator;
3
4
use suda\orm\exception\SQLException;
5
use suda\orm\struct\Field;
6
use suda\orm\struct\Fields;
7
use suda\orm\connection\Connection;
8
use suda\orm\statement\QueryStatement;
9
10
/**
11
 * 数据表链接对象
12
 *
13
 */
14
class SQLiteTableCreator
15
{
16
    /**
17
     * 连接
18
     *
19
     * @var Connection
20
     */
21
    protected $connection;
22
23
    /**
24
     * 字段
25
     *
26
     * @var Fields
27
     */
28
    protected $fields;
29
30
    const ENGINE_MyISAM = 'MyISAM';
31
    const ENGINE_InnoDB = 'InnoDB';
32
33
    protected $name;
34
    protected $engine = self::ENGINE_InnoDB;
35
    protected $comment;
36
37
    protected $collate;
38
    protected $charset = 'utf8mb4';
39
    
40
    protected $auto;
41
    protected $foreignKeys;
42
43
    public function __construct(Connection $connection, Fields $fields)
44
    {
45
        $this->name = $fields->getName();
46
        $this->fields = $fields;
47
        $this->connection = $connection;
48
    }
49
50
    /**
51
     * @return bool
52
     * @throws SQLException
53
     */
54
    public function create()
55
    {
56
        $statement = new QueryStatement($this->toSQL());
57
        $statement->isWrite(true);
58
        return $this->connection->query($statement) > 0;
59
    }
60
61
    protected function seekField(Field $field)
62
    {
63
        $name = $field->getName();
64
        $this->fields[$name] = $field;
65
        if ($foreign = $field->getForeignKey()) {
66
            $this->foreignKeys[$name] = $foreign;
67
        }
68
        return $this;
69
    }
70
71
72
    protected function toSQL()
73
    {
74
        // TODO
75
        return '';
76
    }
77
}
78